]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.13.2-201402111747.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.13.2-201402111747.patch
CommitLineData
b1761047
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 a7fd5d9..dc8e4db 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
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 c1f1a7e..554b0cd 100644
878--- a/arch/arm/Kconfig
879+++ b/arch/arm/Kconfig
880@@ -1828,7 +1828,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@@ -2100,6 +2100,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..7a13651 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,17 +691,28 @@ 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 static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1435@@ -382,6 +740,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1436 return oldval;
1437 }
1438
1439+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1440+ long long new)
1441+{
1442+ long long oldval;
1443+ unsigned long res;
1444+
1445+ smp_mb();
1446+
1447+ do {
1448+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1449+ "ldrexd %1, %H1, [%3]\n"
1450+ "mov %0, #0\n"
1451+ "teq %1, %4\n"
1452+ "teqeq %H1, %H4\n"
1453+ "strexdeq %0, %5, %H5, [%3]"
1454+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1455+ : "r" (&ptr->counter), "r" (old), "r" (new)
1456+ : "cc");
1457+ } while (res);
1458+
1459+ smp_mb();
1460+
1461+ return oldval;
1462+}
1463+
1464 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1465 {
1466 long long result;
1467@@ -406,20 +789,34 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1468 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1469 {
1470 long long result;
1471- unsigned long tmp;
1472+ u64 tmp;
1473
1474 smp_mb();
1475
1476 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1477-"1: ldrexd %0, %H0, [%3]\n"
1478-" subs %Q0, %Q0, #1\n"
1479-" sbc %R0, %R0, #0\n"
1480+"1: ldrexd %1, %H1, [%3]\n"
1481+" subs %Q0, %Q1, #1\n"
1482+" sbcs %R0, %R1, #0\n"
1483+
1484+#ifdef CONFIG_PAX_REFCOUNT
1485+" bvc 3f\n"
1486+" mov %Q0, %Q1\n"
1487+" mov %R0, %R1\n"
1488+"2: bkpt 0xf103\n"
1489+"3:\n"
1490+#endif
1491+
1492 " teq %R0, #0\n"
1493-" bmi 2f\n"
1494+" bmi 4f\n"
1495 " strexd %1, %0, %H0, [%3]\n"
1496 " teq %1, #0\n"
1497 " bne 1b\n"
1498-"2:"
1499+"4:\n"
1500+
1501+#ifdef CONFIG_PAX_REFCOUNT
1502+ _ASM_EXTABLE(2b, 4b)
1503+#endif
1504+
1505 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1506 : "r" (&v->counter)
1507 : "cc");
1508@@ -442,13 +839,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1509 " teq %0, %5\n"
1510 " teqeq %H0, %H5\n"
1511 " moveq %1, #0\n"
1512-" beq 2f\n"
1513+" beq 4f\n"
1514 " adds %Q0, %Q0, %Q6\n"
1515-" adc %R0, %R0, %R6\n"
1516+" adcs %R0, %R0, %R6\n"
1517+
1518+#ifdef CONFIG_PAX_REFCOUNT
1519+" bvc 3f\n"
1520+"2: bkpt 0xf103\n"
1521+"3:\n"
1522+#endif
1523+
1524 " strexd %2, %0, %H0, [%4]\n"
1525 " teq %2, #0\n"
1526 " bne 1b\n"
1527-"2:"
1528+"4:\n"
1529+
1530+#ifdef CONFIG_PAX_REFCOUNT
1531+ _ASM_EXTABLE(2b, 4b)
1532+#endif
1533+
1534 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1535 : "r" (&v->counter), "r" (u), "r" (a)
1536 : "cc");
1537@@ -461,10 +870,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1538
1539 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1540 #define atomic64_inc(v) atomic64_add(1LL, (v))
1541+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1542 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1543+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1544 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1545 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1546 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1547+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1548 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1549 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1550 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1551diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1552index 75fe66b..ba3dee4 100644
1553--- a/arch/arm/include/asm/cache.h
1554+++ b/arch/arm/include/asm/cache.h
1555@@ -4,8 +4,10 @@
1556 #ifndef __ASMARM_CACHE_H
1557 #define __ASMARM_CACHE_H
1558
1559+#include <linux/const.h>
1560+
1561 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1562-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1563+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1564
1565 /*
1566 * Memory returned by kmalloc() may be used for DMA, so we must make
1567@@ -24,5 +26,6 @@
1568 #endif
1569
1570 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1571+#define __read_only __attribute__ ((__section__(".data..read_only")))
1572
1573 #endif
1574diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1575index ee753f1..c9c30a5 100644
1576--- a/arch/arm/include/asm/cacheflush.h
1577+++ b/arch/arm/include/asm/cacheflush.h
1578@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1579 void (*dma_unmap_area)(const void *, size_t, int);
1580
1581 void (*dma_flush_range)(const void *, const void *);
1582-};
1583+} __no_const;
1584
1585 /*
1586 * Select the calling method
1587diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1588index 6dcc164..b14d917 100644
1589--- a/arch/arm/include/asm/checksum.h
1590+++ b/arch/arm/include/asm/checksum.h
1591@@ -37,7 +37,19 @@ __wsum
1592 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1593
1594 __wsum
1595-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1596+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1597+
1598+static inline __wsum
1599+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1600+{
1601+ __wsum ret;
1602+ pax_open_userland();
1603+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1604+ pax_close_userland();
1605+ return ret;
1606+}
1607+
1608+
1609
1610 /*
1611 * Fold a partial checksum without adding pseudo headers
1612diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1613index df2fbba..63fe3e1 100644
1614--- a/arch/arm/include/asm/cmpxchg.h
1615+++ b/arch/arm/include/asm/cmpxchg.h
1616@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1617
1618 #define xchg(ptr,x) \
1619 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1620+#define xchg_unchecked(ptr,x) \
1621+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1622
1623 #include <asm-generic/cmpxchg-local.h>
1624
1625diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1626index 6ddbe44..b5e38b1 100644
1627--- a/arch/arm/include/asm/domain.h
1628+++ b/arch/arm/include/asm/domain.h
1629@@ -48,18 +48,37 @@
1630 * Domain types
1631 */
1632 #define DOMAIN_NOACCESS 0
1633-#define DOMAIN_CLIENT 1
1634 #ifdef CONFIG_CPU_USE_DOMAINS
1635+#define DOMAIN_USERCLIENT 1
1636+#define DOMAIN_KERNELCLIENT 1
1637 #define DOMAIN_MANAGER 3
1638+#define DOMAIN_VECTORS DOMAIN_USER
1639 #else
1640+
1641+#ifdef CONFIG_PAX_KERNEXEC
1642 #define DOMAIN_MANAGER 1
1643+#define DOMAIN_KERNEXEC 3
1644+#else
1645+#define DOMAIN_MANAGER 1
1646+#endif
1647+
1648+#ifdef CONFIG_PAX_MEMORY_UDEREF
1649+#define DOMAIN_USERCLIENT 0
1650+#define DOMAIN_UDEREF 1
1651+#define DOMAIN_VECTORS DOMAIN_KERNEL
1652+#else
1653+#define DOMAIN_USERCLIENT 1
1654+#define DOMAIN_VECTORS DOMAIN_USER
1655+#endif
1656+#define DOMAIN_KERNELCLIENT 1
1657+
1658 #endif
1659
1660 #define domain_val(dom,type) ((type) << (2*(dom)))
1661
1662 #ifndef __ASSEMBLY__
1663
1664-#ifdef CONFIG_CPU_USE_DOMAINS
1665+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1666 static inline void set_domain(unsigned val)
1667 {
1668 asm volatile(
1669@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1670 isb();
1671 }
1672
1673-#define modify_domain(dom,type) \
1674- do { \
1675- struct thread_info *thread = current_thread_info(); \
1676- unsigned int domain = thread->cpu_domain; \
1677- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1678- thread->cpu_domain = domain | domain_val(dom, type); \
1679- set_domain(thread->cpu_domain); \
1680- } while (0)
1681-
1682+extern void modify_domain(unsigned int dom, unsigned int type);
1683 #else
1684 static inline void set_domain(unsigned val) { }
1685 static inline void modify_domain(unsigned dom, unsigned type) { }
1686diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1687index f4b46d3..abc9b2b 100644
1688--- a/arch/arm/include/asm/elf.h
1689+++ b/arch/arm/include/asm/elf.h
1690@@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1691 the loader. We need to make sure that it is out of the way of the program
1692 that it will "exec", and that there is sufficient room for the brk. */
1693
1694-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1695+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1696+
1697+#ifdef CONFIG_PAX_ASLR
1698+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1699+
1700+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1701+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1702+#endif
1703
1704 /* When the program starts, a1 contains a pointer to a function to be
1705 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1706@@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1707 extern void elf_set_personality(const struct elf32_hdr *);
1708 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1709
1710-struct mm_struct;
1711-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1712-#define arch_randomize_brk arch_randomize_brk
1713-
1714 #ifdef CONFIG_MMU
1715 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1716 struct linux_binprm;
1717diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1718index de53547..52b9a28 100644
1719--- a/arch/arm/include/asm/fncpy.h
1720+++ b/arch/arm/include/asm/fncpy.h
1721@@ -81,7 +81,9 @@
1722 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1723 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1724 \
1725+ pax_open_kernel(); \
1726 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1727+ pax_close_kernel(); \
1728 flush_icache_range((unsigned long)(dest_buf), \
1729 (unsigned long)(dest_buf) + (size)); \
1730 \
1731diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1732index e42cf59..7b94b8f 100644
1733--- a/arch/arm/include/asm/futex.h
1734+++ b/arch/arm/include/asm/futex.h
1735@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1736 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1737 return -EFAULT;
1738
1739+ pax_open_userland();
1740+
1741 smp_mb();
1742 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1743 "1: ldrex %1, [%4]\n"
1744@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1745 : "cc", "memory");
1746 smp_mb();
1747
1748+ pax_close_userland();
1749+
1750 *uval = val;
1751 return ret;
1752 }
1753@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1754 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1755 return -EFAULT;
1756
1757+ pax_open_userland();
1758+
1759 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1760 "1: " TUSER(ldr) " %1, [%4]\n"
1761 " teq %1, %2\n"
1762@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1763 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1764 : "cc", "memory");
1765
1766+ pax_close_userland();
1767+
1768 *uval = val;
1769 return ret;
1770 }
1771@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1772 return -EFAULT;
1773
1774 pagefault_disable(); /* implies preempt_disable() */
1775+ pax_open_userland();
1776
1777 switch (op) {
1778 case FUTEX_OP_SET:
1779@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1780 ret = -ENOSYS;
1781 }
1782
1783+ pax_close_userland();
1784 pagefault_enable(); /* subsumes preempt_enable() */
1785
1786 if (!ret) {
1787diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1788index 83eb2f7..ed77159 100644
1789--- a/arch/arm/include/asm/kmap_types.h
1790+++ b/arch/arm/include/asm/kmap_types.h
1791@@ -4,6 +4,6 @@
1792 /*
1793 * This is the "bare minimum". AIO seems to require this.
1794 */
1795-#define KM_TYPE_NR 16
1796+#define KM_TYPE_NR 17
1797
1798 #endif
1799diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1800index 9e614a1..3302cca 100644
1801--- a/arch/arm/include/asm/mach/dma.h
1802+++ b/arch/arm/include/asm/mach/dma.h
1803@@ -22,7 +22,7 @@ struct dma_ops {
1804 int (*residue)(unsigned int, dma_t *); /* optional */
1805 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1806 const char *type;
1807-};
1808+} __do_const;
1809
1810 struct dma_struct {
1811 void *addr; /* single DMA address */
1812diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1813index 2fe141f..192dc01 100644
1814--- a/arch/arm/include/asm/mach/map.h
1815+++ b/arch/arm/include/asm/mach/map.h
1816@@ -27,13 +27,16 @@ struct map_desc {
1817 #define MT_MINICLEAN 6
1818 #define MT_LOW_VECTORS 7
1819 #define MT_HIGH_VECTORS 8
1820-#define MT_MEMORY 9
1821+#define MT_MEMORY_RWX 9
1822 #define MT_ROM 10
1823-#define MT_MEMORY_NONCACHED 11
1824+#define MT_MEMORY_NONCACHED_RX 11
1825 #define MT_MEMORY_DTCM 12
1826 #define MT_MEMORY_ITCM 13
1827 #define MT_MEMORY_SO 14
1828 #define MT_MEMORY_DMA_READY 15
1829+#define MT_MEMORY_RW 16
1830+#define MT_MEMORY_RX 17
1831+#define MT_MEMORY_NONCACHED_RW 18
1832
1833 #ifdef CONFIG_MMU
1834 extern void iotable_init(struct map_desc *, int);
1835diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1836index f94784f..9a09a4a 100644
1837--- a/arch/arm/include/asm/outercache.h
1838+++ b/arch/arm/include/asm/outercache.h
1839@@ -35,7 +35,7 @@ struct outer_cache_fns {
1840 #endif
1841 void (*set_debug)(unsigned long);
1842 void (*resume)(void);
1843-};
1844+} __no_const;
1845
1846 extern struct outer_cache_fns outer_cache;
1847
1848diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1849index 4355f0e..c229913 100644
1850--- a/arch/arm/include/asm/page.h
1851+++ b/arch/arm/include/asm/page.h
1852@@ -114,7 +114,7 @@ struct cpu_user_fns {
1853 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1854 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1855 unsigned long vaddr, struct vm_area_struct *vma);
1856-};
1857+} __no_const;
1858
1859 #ifdef MULTI_USER
1860 extern struct cpu_user_fns cpu_user;
1861diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1862index 78a7793..e3dc06c 100644
1863--- a/arch/arm/include/asm/pgalloc.h
1864+++ b/arch/arm/include/asm/pgalloc.h
1865@@ -17,6 +17,7 @@
1866 #include <asm/processor.h>
1867 #include <asm/cacheflush.h>
1868 #include <asm/tlbflush.h>
1869+#include <asm/system_info.h>
1870
1871 #define check_pgt_cache() do { } while (0)
1872
1873@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1874 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1875 }
1876
1877+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1878+{
1879+ pud_populate(mm, pud, pmd);
1880+}
1881+
1882 #else /* !CONFIG_ARM_LPAE */
1883
1884 /*
1885@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1886 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1887 #define pmd_free(mm, pmd) do { } while (0)
1888 #define pud_populate(mm,pmd,pte) BUG()
1889+#define pud_populate_kernel(mm,pmd,pte) BUG()
1890
1891 #endif /* CONFIG_ARM_LPAE */
1892
1893@@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1894 __free_page(pte);
1895 }
1896
1897+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1898+{
1899+#ifdef CONFIG_ARM_LPAE
1900+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1901+#else
1902+ if (addr & SECTION_SIZE)
1903+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1904+ else
1905+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1906+#endif
1907+ flush_pmd_entry(pmdp);
1908+}
1909+
1910 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1911 pmdval_t prot)
1912 {
1913@@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1914 static inline void
1915 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1916 {
1917- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1918+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1919 }
1920 #define pmd_pgtable(pmd) pmd_page(pmd)
1921
1922diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1923index 5cfba15..f415e1a 100644
1924--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1925+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1926@@ -20,12 +20,15 @@
1927 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1928 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1929 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1930+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1931 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1932 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1933 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1934+
1935 /*
1936 * - section
1937 */
1938+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1939 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1940 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1941 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1942@@ -37,6 +40,7 @@
1943 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1944 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1945 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1946+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1947
1948 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1949 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1950@@ -66,6 +70,7 @@
1951 * - extended small page/tiny page
1952 */
1953 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1954+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1955 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1956 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1957 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1958diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1959index 86a659a..70e0120 100644
1960--- a/arch/arm/include/asm/pgtable-2level.h
1961+++ b/arch/arm/include/asm/pgtable-2level.h
1962@@ -126,6 +126,9 @@
1963 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1964 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1965
1966+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1967+#define L_PTE_PXN (_AT(pteval_t, 0))
1968+
1969 /*
1970 * These are the memory types, defined to be compatible with
1971 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1972diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1973index 626989f..9d67a33 100644
1974--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1975+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1976@@ -75,6 +75,7 @@
1977 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1978 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1979 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1980+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1981 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1982
1983 /*
1984diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1985index 4f95039..b2dd513 100644
1986--- a/arch/arm/include/asm/pgtable-3level.h
1987+++ b/arch/arm/include/asm/pgtable-3level.h
1988@@ -82,6 +82,7 @@
1989 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1990 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1991 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1992+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1993 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1994 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1995 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1996@@ -95,6 +96,7 @@
1997 /*
1998 * To be used in assembly code with the upper page attributes.
1999 */
2000+#define L_PTE_PXN_HIGH (1 << (53 - 32))
2001 #define L_PTE_XN_HIGH (1 << (54 - 32))
2002 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2003
2004diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2005index 1571d12..b8a9b43 100644
2006--- a/arch/arm/include/asm/pgtable.h
2007+++ b/arch/arm/include/asm/pgtable.h
2008@@ -33,6 +33,9 @@
2009 #include <asm/pgtable-2level.h>
2010 #endif
2011
2012+#define ktla_ktva(addr) (addr)
2013+#define ktva_ktla(addr) (addr)
2014+
2015 /*
2016 * Just any arbitrary offset to the start of the vmalloc VM area: the
2017 * current 8MB value just means that there will be a 8MB "hole" after the
2018@@ -48,6 +51,9 @@
2019 #define LIBRARY_TEXT_START 0x0c000000
2020
2021 #ifndef __ASSEMBLY__
2022+extern pteval_t __supported_pte_mask;
2023+extern pmdval_t __supported_pmd_mask;
2024+
2025 extern void __pte_error(const char *file, int line, pte_t);
2026 extern void __pmd_error(const char *file, int line, pmd_t);
2027 extern void __pgd_error(const char *file, int line, pgd_t);
2028@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2029 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2030 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2031
2032+#define __HAVE_ARCH_PAX_OPEN_KERNEL
2033+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2034+
2035+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2036+#include <asm/domain.h>
2037+#include <linux/thread_info.h>
2038+#include <linux/preempt.h>
2039+
2040+static inline int test_domain(int domain, int domaintype)
2041+{
2042+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2043+}
2044+#endif
2045+
2046+#ifdef CONFIG_PAX_KERNEXEC
2047+static inline unsigned long pax_open_kernel(void) {
2048+#ifdef CONFIG_ARM_LPAE
2049+ /* TODO */
2050+#else
2051+ preempt_disable();
2052+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2053+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2054+#endif
2055+ return 0;
2056+}
2057+
2058+static inline unsigned long pax_close_kernel(void) {
2059+#ifdef CONFIG_ARM_LPAE
2060+ /* TODO */
2061+#else
2062+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2063+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2064+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2065+ preempt_enable_no_resched();
2066+#endif
2067+ return 0;
2068+}
2069+#else
2070+static inline unsigned long pax_open_kernel(void) { return 0; }
2071+static inline unsigned long pax_close_kernel(void) { return 0; }
2072+#endif
2073+
2074 /*
2075 * This is the lowest virtual address we can permit any user space
2076 * mapping to be mapped at. This is particularly important for
2077@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2078 /*
2079 * The pgprot_* and protection_map entries will be fixed up in runtime
2080 * to include the cachable and bufferable bits based on memory policy,
2081- * as well as any architecture dependent bits like global/ASID and SMP
2082- * shared mapping bits.
2083+ * as well as any architecture dependent bits like global/ASID, PXN,
2084+ * and SMP shared mapping bits.
2085 */
2086 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2087
2088@@ -260,7 +308,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2089 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2090 {
2091 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2092- L_PTE_NONE | L_PTE_VALID;
2093+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2094 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2095 return pte;
2096 }
2097diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2098index 5324c11..bcae5f0 100644
2099--- a/arch/arm/include/asm/proc-fns.h
2100+++ b/arch/arm/include/asm/proc-fns.h
2101@@ -75,7 +75,7 @@ extern struct processor {
2102 unsigned int suspend_size;
2103 void (*do_suspend)(void *);
2104 void (*do_resume)(void *);
2105-} processor;
2106+} __do_const processor;
2107
2108 #ifndef MULTI_CPU
2109 extern void cpu_proc_init(void);
2110diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2111index c4ae171..ea0c0c2 100644
2112--- a/arch/arm/include/asm/psci.h
2113+++ b/arch/arm/include/asm/psci.h
2114@@ -29,7 +29,7 @@ struct psci_operations {
2115 int (*cpu_off)(struct psci_power_state state);
2116 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2117 int (*migrate)(unsigned long cpuid);
2118-};
2119+} __no_const;
2120
2121 extern struct psci_operations psci_ops;
2122 extern struct smp_operations psci_smp_ops;
2123diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2124index 22a3b9b..7f214ee 100644
2125--- a/arch/arm/include/asm/smp.h
2126+++ b/arch/arm/include/asm/smp.h
2127@@ -112,7 +112,7 @@ struct smp_operations {
2128 int (*cpu_disable)(unsigned int cpu);
2129 #endif
2130 #endif
2131-};
2132+} __no_const;
2133
2134 /*
2135 * set platform specific SMP operations
2136diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2137index 71a06b2..8bb9ae1 100644
2138--- a/arch/arm/include/asm/thread_info.h
2139+++ b/arch/arm/include/asm/thread_info.h
2140@@ -88,9 +88,9 @@ struct thread_info {
2141 .flags = 0, \
2142 .preempt_count = INIT_PREEMPT_COUNT, \
2143 .addr_limit = KERNEL_DS, \
2144- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2145- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2146- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2147+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2148+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2149+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2150 .restart_block = { \
2151 .fn = do_no_restart_syscall, \
2152 }, \
2153@@ -157,7 +157,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2154 #define TIF_SYSCALL_AUDIT 9
2155 #define TIF_SYSCALL_TRACEPOINT 10
2156 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2157-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2158+/* within 8 bits of TIF_SYSCALL_TRACE
2159+ * to meet flexible second operand requirements
2160+ */
2161+#define TIF_GRSEC_SETXID 12
2162+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2163 #define TIF_USING_IWMMXT 17
2164 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2165 #define TIF_RESTORE_SIGMASK 20
2166@@ -170,10 +174,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2167 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2168 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2169 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2170+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2171
2172 /* Checks for any syscall work in entry-common.S */
2173 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2174- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2175+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2176
2177 /*
2178 * Change these and you break ASM code in entry-common.S
2179diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2180index 72abdc5..9eba222 100644
2181--- a/arch/arm/include/asm/uaccess.h
2182+++ b/arch/arm/include/asm/uaccess.h
2183@@ -18,6 +18,7 @@
2184 #include <asm/domain.h>
2185 #include <asm/unified.h>
2186 #include <asm/compiler.h>
2187+#include <asm/pgtable.h>
2188
2189 #if __LINUX_ARM_ARCH__ < 6
2190 #include <asm-generic/uaccess-unaligned.h>
2191@@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2192 static inline void set_fs(mm_segment_t fs)
2193 {
2194 current_thread_info()->addr_limit = fs;
2195- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2196+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2197 }
2198
2199 #define segment_eq(a,b) ((a) == (b))
2200
2201+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2202+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2203+
2204+static inline void pax_open_userland(void)
2205+{
2206+
2207+#ifdef CONFIG_PAX_MEMORY_UDEREF
2208+ if (segment_eq(get_fs(), USER_DS)) {
2209+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2210+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2211+ }
2212+#endif
2213+
2214+}
2215+
2216+static inline void pax_close_userland(void)
2217+{
2218+
2219+#ifdef CONFIG_PAX_MEMORY_UDEREF
2220+ if (segment_eq(get_fs(), USER_DS)) {
2221+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2222+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2223+ }
2224+#endif
2225+
2226+}
2227+
2228 #define __addr_ok(addr) ({ \
2229 unsigned long flag; \
2230 __asm__("cmp %2, %0; movlo %0, #0" \
2231@@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2232
2233 #define get_user(x,p) \
2234 ({ \
2235+ int __e; \
2236 might_fault(); \
2237- __get_user_check(x,p); \
2238+ pax_open_userland(); \
2239+ __e = __get_user_check(x,p); \
2240+ pax_close_userland(); \
2241+ __e; \
2242 })
2243
2244 extern int __put_user_1(void *, unsigned int);
2245@@ -195,8 +227,12 @@ extern int __put_user_8(void *, unsigned long long);
2246
2247 #define put_user(x,p) \
2248 ({ \
2249+ int __e; \
2250 might_fault(); \
2251- __put_user_check(x,p); \
2252+ pax_open_userland(); \
2253+ __e = __put_user_check(x,p); \
2254+ pax_close_userland(); \
2255+ __e; \
2256 })
2257
2258 #else /* CONFIG_MMU */
2259@@ -237,13 +273,17 @@ static inline void set_fs(mm_segment_t fs)
2260 #define __get_user(x,ptr) \
2261 ({ \
2262 long __gu_err = 0; \
2263+ pax_open_userland(); \
2264 __get_user_err((x),(ptr),__gu_err); \
2265+ pax_close_userland(); \
2266 __gu_err; \
2267 })
2268
2269 #define __get_user_error(x,ptr,err) \
2270 ({ \
2271+ pax_open_userland(); \
2272 __get_user_err((x),(ptr),err); \
2273+ pax_close_userland(); \
2274 (void) 0; \
2275 })
2276
2277@@ -319,13 +359,17 @@ do { \
2278 #define __put_user(x,ptr) \
2279 ({ \
2280 long __pu_err = 0; \
2281+ pax_open_userland(); \
2282 __put_user_err((x),(ptr),__pu_err); \
2283+ pax_close_userland(); \
2284 __pu_err; \
2285 })
2286
2287 #define __put_user_error(x,ptr,err) \
2288 ({ \
2289+ pax_open_userland(); \
2290 __put_user_err((x),(ptr),err); \
2291+ pax_close_userland(); \
2292 (void) 0; \
2293 })
2294
2295@@ -425,11 +469,44 @@ do { \
2296
2297
2298 #ifdef CONFIG_MMU
2299-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2300-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
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+
2304+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2305+{
2306+ unsigned long ret;
2307+
2308+ check_object_size(to, n, false);
2309+ pax_open_userland();
2310+ ret = ___copy_from_user(to, from, n);
2311+ pax_close_userland();
2312+ return ret;
2313+}
2314+
2315+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2316+{
2317+ unsigned long ret;
2318+
2319+ check_object_size(from, n, true);
2320+ pax_open_userland();
2321+ ret = ___copy_to_user(to, from, n);
2322+ pax_close_userland();
2323+ return ret;
2324+}
2325+
2326 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2327-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2328+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2329 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2330+
2331+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2332+{
2333+ unsigned long ret;
2334+ pax_open_userland();
2335+ ret = ___clear_user(addr, n);
2336+ pax_close_userland();
2337+ return ret;
2338+}
2339+
2340 #else
2341 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2342 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2343@@ -438,6 +515,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2344
2345 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2346 {
2347+ if ((long)n < 0)
2348+ return n;
2349+
2350 if (access_ok(VERIFY_READ, from, n))
2351 n = __copy_from_user(to, from, n);
2352 else /* security hole - plug it */
2353@@ -447,6 +527,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2354
2355 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2356 {
2357+ if ((long)n < 0)
2358+ return n;
2359+
2360 if (access_ok(VERIFY_WRITE, to, n))
2361 n = __copy_to_user(to, from, n);
2362 return n;
2363diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2364index 5af0ed1..cea83883 100644
2365--- a/arch/arm/include/uapi/asm/ptrace.h
2366+++ b/arch/arm/include/uapi/asm/ptrace.h
2367@@ -92,7 +92,7 @@
2368 * ARMv7 groups of PSR bits
2369 */
2370 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2371-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2372+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2373 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2374 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2375
2376diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2377index 1f031dd..d9b5e4a 100644
2378--- a/arch/arm/kernel/armksyms.c
2379+++ b/arch/arm/kernel/armksyms.c
2380@@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2381
2382 /* networking */
2383 EXPORT_SYMBOL(csum_partial);
2384-EXPORT_SYMBOL(csum_partial_copy_from_user);
2385+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2386 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2387 EXPORT_SYMBOL(__csum_ipv6_magic);
2388
2389@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2390 #ifdef CONFIG_MMU
2391 EXPORT_SYMBOL(copy_page);
2392
2393-EXPORT_SYMBOL(__copy_from_user);
2394-EXPORT_SYMBOL(__copy_to_user);
2395-EXPORT_SYMBOL(__clear_user);
2396+EXPORT_SYMBOL(___copy_from_user);
2397+EXPORT_SYMBOL(___copy_to_user);
2398+EXPORT_SYMBOL(___clear_user);
2399
2400 EXPORT_SYMBOL(__get_user_1);
2401 EXPORT_SYMBOL(__get_user_2);
2402diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2403index b3fb8c9..59cfab2 100644
2404--- a/arch/arm/kernel/entry-armv.S
2405+++ b/arch/arm/kernel/entry-armv.S
2406@@ -47,6 +47,87 @@
2407 9997:
2408 .endm
2409
2410+ .macro pax_enter_kernel
2411+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2412+ @ make aligned space for saved DACR
2413+ sub sp, sp, #8
2414+ @ save regs
2415+ stmdb sp!, {r1, r2}
2416+ @ read DACR from cpu_domain into r1
2417+ mov r2, sp
2418+ @ assume 8K pages, since we have to split the immediate in two
2419+ bic r2, r2, #(0x1fc0)
2420+ bic r2, r2, #(0x3f)
2421+ ldr r1, [r2, #TI_CPU_DOMAIN]
2422+ @ store old DACR on stack
2423+ str r1, [sp, #8]
2424+#ifdef CONFIG_PAX_KERNEXEC
2425+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2426+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2427+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2428+#endif
2429+#ifdef CONFIG_PAX_MEMORY_UDEREF
2430+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2431+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2432+#endif
2433+ @ write r1 to current_thread_info()->cpu_domain
2434+ str r1, [r2, #TI_CPU_DOMAIN]
2435+ @ write r1 to DACR
2436+ mcr p15, 0, r1, c3, c0, 0
2437+ @ instruction sync
2438+ instr_sync
2439+ @ restore regs
2440+ ldmia sp!, {r1, r2}
2441+#endif
2442+ .endm
2443+
2444+ .macro pax_open_userland
2445+#ifdef CONFIG_PAX_MEMORY_UDEREF
2446+ @ save regs
2447+ stmdb sp!, {r0, r1}
2448+ @ read DACR from cpu_domain into r1
2449+ mov r0, sp
2450+ @ assume 8K pages, since we have to split the immediate in two
2451+ bic r0, r0, #(0x1fc0)
2452+ bic r0, r0, #(0x3f)
2453+ ldr r1, [r0, #TI_CPU_DOMAIN]
2454+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2455+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2456+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2457+ @ write r1 to current_thread_info()->cpu_domain
2458+ str r1, [r0, #TI_CPU_DOMAIN]
2459+ @ write r1 to DACR
2460+ mcr p15, 0, r1, c3, c0, 0
2461+ @ instruction sync
2462+ instr_sync
2463+ @ restore regs
2464+ ldmia sp!, {r0, r1}
2465+#endif
2466+ .endm
2467+
2468+ .macro pax_close_userland
2469+#ifdef CONFIG_PAX_MEMORY_UDEREF
2470+ @ save regs
2471+ stmdb sp!, {r0, r1}
2472+ @ read DACR from cpu_domain into r1
2473+ mov r0, sp
2474+ @ assume 8K pages, since we have to split the immediate in two
2475+ bic r0, r0, #(0x1fc0)
2476+ bic r0, r0, #(0x3f)
2477+ ldr r1, [r0, #TI_CPU_DOMAIN]
2478+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2479+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2480+ @ write r1 to current_thread_info()->cpu_domain
2481+ str r1, [r0, #TI_CPU_DOMAIN]
2482+ @ write r1 to DACR
2483+ mcr p15, 0, r1, c3, c0, 0
2484+ @ instruction sync
2485+ instr_sync
2486+ @ restore regs
2487+ ldmia sp!, {r0, r1}
2488+#endif
2489+ .endm
2490+
2491 .macro pabt_helper
2492 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2493 #ifdef MULTI_PABORT
2494@@ -89,11 +170,15 @@
2495 * Invalid mode handlers
2496 */
2497 .macro inv_entry, reason
2498+
2499+ pax_enter_kernel
2500+
2501 sub sp, sp, #S_FRAME_SIZE
2502 ARM( stmib sp, {r1 - lr} )
2503 THUMB( stmia sp, {r0 - r12} )
2504 THUMB( str sp, [sp, #S_SP] )
2505 THUMB( str lr, [sp, #S_LR] )
2506+
2507 mov r1, #\reason
2508 .endm
2509
2510@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2511 .macro svc_entry, stack_hole=0
2512 UNWIND(.fnstart )
2513 UNWIND(.save {r0 - pc} )
2514+
2515+ pax_enter_kernel
2516+
2517 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2518+
2519 #ifdef CONFIG_THUMB2_KERNEL
2520 SPFIX( str r0, [sp] ) @ temporarily saved
2521 SPFIX( mov r0, sp )
2522@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2523 ldmia r0, {r3 - r5}
2524 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2525 mov r6, #-1 @ "" "" "" ""
2526+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2527+ @ offset sp by 8 as done in pax_enter_kernel
2528+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2529+#else
2530 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2531+#endif
2532 SPFIX( addeq r2, r2, #4 )
2533 str r3, [sp, #-4]! @ save the "real" r0 copied
2534 @ from the exception stack
2535@@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2536 .macro usr_entry
2537 UNWIND(.fnstart )
2538 UNWIND(.cantunwind ) @ don't unwind the user space
2539+
2540+ pax_enter_kernel_user
2541+
2542 sub sp, sp, #S_FRAME_SIZE
2543 ARM( stmib sp, {r1 - r12} )
2544 THUMB( stmia sp, {r0 - r12} )
2545@@ -416,7 +513,9 @@ __und_usr:
2546 tst r3, #PSR_T_BIT @ Thumb mode?
2547 bne __und_usr_thumb
2548 sub r4, r2, #4 @ ARM instr at LR - 4
2549+ pax_open_userland
2550 1: ldrt r0, [r4]
2551+ pax_close_userland
2552 ARM_BE8(rev r0, r0) @ little endian instruction
2553
2554 @ r0 = 32-bit ARM instruction which caused the exception
2555@@ -450,10 +549,14 @@ __und_usr_thumb:
2556 */
2557 .arch armv6t2
2558 #endif
2559+ pax_open_userland
2560 2: ldrht r5, [r4]
2561+ pax_close_userland
2562 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2563 blo __und_usr_fault_16 @ 16bit undefined instruction
2564+ pax_open_userland
2565 3: ldrht r0, [r2]
2566+ pax_close_userland
2567 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2568 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2569 orr r0, r0, r5, lsl #16
2570@@ -482,7 +585,8 @@ ENDPROC(__und_usr)
2571 */
2572 .pushsection .fixup, "ax"
2573 .align 2
2574-4: mov pc, r9
2575+4: pax_close_userland
2576+ mov pc, r9
2577 .popsection
2578 .pushsection __ex_table,"a"
2579 .long 1b, 4b
2580@@ -692,7 +796,7 @@ ENTRY(__switch_to)
2581 THUMB( str lr, [ip], #4 )
2582 ldr r4, [r2, #TI_TP_VALUE]
2583 ldr r5, [r2, #TI_TP_VALUE + 4]
2584-#ifdef CONFIG_CPU_USE_DOMAINS
2585+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2586 ldr r6, [r2, #TI_CPU_DOMAIN]
2587 #endif
2588 switch_tls r1, r4, r5, r3, r7
2589@@ -701,7 +805,7 @@ ENTRY(__switch_to)
2590 ldr r8, =__stack_chk_guard
2591 ldr r7, [r7, #TSK_STACK_CANARY]
2592 #endif
2593-#ifdef CONFIG_CPU_USE_DOMAINS
2594+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2595 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2596 #endif
2597 mov r5, r0
2598diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2599index a2dcafd..1048b5a 100644
2600--- a/arch/arm/kernel/entry-common.S
2601+++ b/arch/arm/kernel/entry-common.S
2602@@ -10,18 +10,46 @@
2603
2604 #include <asm/unistd.h>
2605 #include <asm/ftrace.h>
2606+#include <asm/domain.h>
2607 #include <asm/unwind.h>
2608
2609+#include "entry-header.S"
2610+
2611 #ifdef CONFIG_NEED_RET_TO_USER
2612 #include <mach/entry-macro.S>
2613 #else
2614 .macro arch_ret_to_user, tmp1, tmp2
2615+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2616+ @ save regs
2617+ stmdb sp!, {r1, r2}
2618+ @ read DACR from cpu_domain into r1
2619+ mov r2, sp
2620+ @ assume 8K pages, since we have to split the immediate in two
2621+ bic r2, r2, #(0x1fc0)
2622+ bic r2, r2, #(0x3f)
2623+ ldr r1, [r2, #TI_CPU_DOMAIN]
2624+#ifdef CONFIG_PAX_KERNEXEC
2625+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2626+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2627+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2628+#endif
2629+#ifdef CONFIG_PAX_MEMORY_UDEREF
2630+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2631+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2632+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2633+#endif
2634+ @ write r1 to current_thread_info()->cpu_domain
2635+ str r1, [r2, #TI_CPU_DOMAIN]
2636+ @ write r1 to DACR
2637+ mcr p15, 0, r1, c3, c0, 0
2638+ @ instruction sync
2639+ instr_sync
2640+ @ restore regs
2641+ ldmia sp!, {r1, r2}
2642+#endif
2643 .endm
2644 #endif
2645
2646-#include "entry-header.S"
2647-
2648-
2649 .align 5
2650 /*
2651 * This is the fast syscall return path. We do as little as
2652@@ -411,6 +439,12 @@ ENTRY(vector_swi)
2653 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2654 #endif
2655
2656+ /*
2657+ * do this here to avoid a performance hit of wrapping the code above
2658+ * that directly dereferences userland to parse the SWI instruction
2659+ */
2660+ pax_enter_kernel_user
2661+
2662 adr tbl, sys_call_table @ load syscall table pointer
2663
2664 #if defined(CONFIG_OABI_COMPAT)
2665diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2666index 39f89fb..d612bd9 100644
2667--- a/arch/arm/kernel/entry-header.S
2668+++ b/arch/arm/kernel/entry-header.S
2669@@ -184,6 +184,60 @@
2670 msr cpsr_c, \rtemp @ switch back to the SVC mode
2671 .endm
2672
2673+ .macro pax_enter_kernel_user
2674+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2675+ @ save regs
2676+ stmdb sp!, {r0, r1}
2677+ @ read DACR from cpu_domain into r1
2678+ mov r0, sp
2679+ @ assume 8K pages, since we have to split the immediate in two
2680+ bic r0, r0, #(0x1fc0)
2681+ bic r0, r0, #(0x3f)
2682+ ldr r1, [r0, #TI_CPU_DOMAIN]
2683+#ifdef CONFIG_PAX_MEMORY_UDEREF
2684+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2685+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2686+#endif
2687+#ifdef CONFIG_PAX_KERNEXEC
2688+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2689+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2690+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2691+#endif
2692+ @ write r1 to current_thread_info()->cpu_domain
2693+ str r1, [r0, #TI_CPU_DOMAIN]
2694+ @ write r1 to DACR
2695+ mcr p15, 0, r1, c3, c0, 0
2696+ @ instruction sync
2697+ instr_sync
2698+ @ restore regs
2699+ ldmia sp!, {r0, r1}
2700+#endif
2701+ .endm
2702+
2703+ .macro pax_exit_kernel
2704+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2705+ @ save regs
2706+ stmdb sp!, {r0, r1}
2707+ @ read old DACR from stack into r1
2708+ ldr r1, [sp, #(8 + S_SP)]
2709+ sub r1, r1, #8
2710+ ldr r1, [r1]
2711+
2712+ @ write r1 to current_thread_info()->cpu_domain
2713+ mov r0, sp
2714+ @ assume 8K pages, since we have to split the immediate in two
2715+ bic r0, r0, #(0x1fc0)
2716+ bic r0, r0, #(0x3f)
2717+ str r1, [r0, #TI_CPU_DOMAIN]
2718+ @ write r1 to DACR
2719+ mcr p15, 0, r1, c3, c0, 0
2720+ @ instruction sync
2721+ instr_sync
2722+ @ restore regs
2723+ ldmia sp!, {r0, r1}
2724+#endif
2725+ .endm
2726+
2727 #ifndef CONFIG_THUMB2_KERNEL
2728 .macro svc_exit, rpsr, irq = 0
2729 .if \irq != 0
2730@@ -203,6 +257,9 @@
2731 blne trace_hardirqs_off
2732 #endif
2733 .endif
2734+
2735+ pax_exit_kernel
2736+
2737 msr spsr_cxsf, \rpsr
2738 #if defined(CONFIG_CPU_V6)
2739 ldr r0, [sp]
2740@@ -266,6 +323,9 @@
2741 blne trace_hardirqs_off
2742 #endif
2743 .endif
2744+
2745+ pax_exit_kernel
2746+
2747 ldr lr, [sp, #S_SP] @ top of the stack
2748 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2749 clrex @ clear the exclusive monitor
2750diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2751index 918875d..cd5fa27 100644
2752--- a/arch/arm/kernel/fiq.c
2753+++ b/arch/arm/kernel/fiq.c
2754@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2755 void *base = vectors_page;
2756 unsigned offset = FIQ_OFFSET;
2757
2758+ pax_open_kernel();
2759 memcpy(base + offset, start, length);
2760+ pax_close_kernel();
2761+
2762 if (!cache_is_vipt_nonaliasing())
2763 flush_icache_range((unsigned long)base + offset, offset +
2764 length);
2765diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2766index 32f317e..710ae07 100644
2767--- a/arch/arm/kernel/head.S
2768+++ b/arch/arm/kernel/head.S
2769@@ -52,7 +52,9 @@
2770 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2771
2772 .macro pgtbl, rd, phys
2773- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2774+ mov \rd, #TEXT_OFFSET
2775+ sub \rd, #PG_DIR_SIZE
2776+ add \rd, \rd, \phys
2777 .endm
2778
2779 /*
2780@@ -436,7 +438,7 @@ __enable_mmu:
2781 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2782 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2783 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2784- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2785+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2786 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2787 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2788 #endif
2789diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2790index 45e4781..8eac93d 100644
2791--- a/arch/arm/kernel/module.c
2792+++ b/arch/arm/kernel/module.c
2793@@ -38,12 +38,39 @@
2794 #endif
2795
2796 #ifdef CONFIG_MMU
2797-void *module_alloc(unsigned long size)
2798+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2799 {
2800+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2801+ return NULL;
2802 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2803- GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2804+ GFP_KERNEL, prot, NUMA_NO_NODE,
2805 __builtin_return_address(0));
2806 }
2807+
2808+void *module_alloc(unsigned long size)
2809+{
2810+
2811+#ifdef CONFIG_PAX_KERNEXEC
2812+ return __module_alloc(size, PAGE_KERNEL);
2813+#else
2814+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2815+#endif
2816+
2817+}
2818+
2819+#ifdef CONFIG_PAX_KERNEXEC
2820+void module_free_exec(struct module *mod, void *module_region)
2821+{
2822+ module_free(mod, module_region);
2823+}
2824+EXPORT_SYMBOL(module_free_exec);
2825+
2826+void *module_alloc_exec(unsigned long size)
2827+{
2828+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2829+}
2830+EXPORT_SYMBOL(module_alloc_exec);
2831+#endif
2832 #endif
2833
2834 int
2835diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2836index 07314af..c46655c 100644
2837--- a/arch/arm/kernel/patch.c
2838+++ b/arch/arm/kernel/patch.c
2839@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2840 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2841 int size;
2842
2843+ pax_open_kernel();
2844 if (thumb2 && __opcode_is_thumb16(insn)) {
2845 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2846 size = sizeof(u16);
2847@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2848 *(u32 *)addr = insn;
2849 size = sizeof(u32);
2850 }
2851+ pax_close_kernel();
2852
2853 flush_icache_range((uintptr_t)(addr),
2854 (uintptr_t)(addr) + size);
2855diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2856index 92f7b15..7048500 100644
2857--- a/arch/arm/kernel/process.c
2858+++ b/arch/arm/kernel/process.c
2859@@ -217,6 +217,7 @@ void machine_power_off(void)
2860
2861 if (pm_power_off)
2862 pm_power_off();
2863+ BUG();
2864 }
2865
2866 /*
2867@@ -230,7 +231,7 @@ void machine_power_off(void)
2868 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2869 * to use. Implementing such co-ordination would be essentially impossible.
2870 */
2871-void machine_restart(char *cmd)
2872+__noreturn void machine_restart(char *cmd)
2873 {
2874 local_irq_disable();
2875 smp_send_stop();
2876@@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2877
2878 show_regs_print_info(KERN_DEFAULT);
2879
2880- print_symbol("PC is at %s\n", instruction_pointer(regs));
2881- print_symbol("LR is at %s\n", regs->ARM_lr);
2882+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2883+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2884 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2885 "sp : %08lx ip : %08lx fp : %08lx\n",
2886 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2887@@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2888 return 0;
2889 }
2890
2891-unsigned long arch_randomize_brk(struct mm_struct *mm)
2892-{
2893- unsigned long range_end = mm->brk + 0x02000000;
2894- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2895-}
2896-
2897 #ifdef CONFIG_MMU
2898 #ifdef CONFIG_KUSER_HELPERS
2899 /*
2900@@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2901
2902 static int __init gate_vma_init(void)
2903 {
2904- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2905+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2906 return 0;
2907 }
2908 arch_initcall(gate_vma_init);
2909@@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2910
2911 const char *arch_vma_name(struct vm_area_struct *vma)
2912 {
2913- return is_gate_vma(vma) ? "[vectors]" :
2914- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2915- "[sigpage]" : NULL;
2916+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2917 }
2918
2919-static struct page *signal_page;
2920-extern struct page *get_signal_page(void);
2921-
2922 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2923 {
2924 struct mm_struct *mm = current->mm;
2925- unsigned long addr;
2926- int ret;
2927-
2928- if (!signal_page)
2929- signal_page = get_signal_page();
2930- if (!signal_page)
2931- return -ENOMEM;
2932
2933 down_write(&mm->mmap_sem);
2934- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2935- if (IS_ERR_VALUE(addr)) {
2936- ret = addr;
2937- goto up_fail;
2938- }
2939-
2940- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2941- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2942- &signal_page);
2943-
2944- if (ret == 0)
2945- mm->context.sigpage = addr;
2946-
2947- up_fail:
2948+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2949 up_write(&mm->mmap_sem);
2950- return ret;
2951+ return 0;
2952 }
2953 #endif
2954diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2955index 4693188..4596c5e 100644
2956--- a/arch/arm/kernel/psci.c
2957+++ b/arch/arm/kernel/psci.c
2958@@ -24,7 +24,7 @@
2959 #include <asm/opcodes-virt.h>
2960 #include <asm/psci.h>
2961
2962-struct psci_operations psci_ops;
2963+struct psci_operations psci_ops __read_only;
2964
2965 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2966
2967diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2968index 0dd3b79..e018f64 100644
2969--- a/arch/arm/kernel/ptrace.c
2970+++ b/arch/arm/kernel/ptrace.c
2971@@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2972 return current_thread_info()->syscall;
2973 }
2974
2975+#ifdef CONFIG_GRKERNSEC_SETXID
2976+extern void gr_delayed_cred_worker(void);
2977+#endif
2978+
2979 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2980 {
2981 current_thread_info()->syscall = scno;
2982
2983+#ifdef CONFIG_GRKERNSEC_SETXID
2984+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2985+ gr_delayed_cred_worker();
2986+#endif
2987+
2988 /* Do the secure computing check first; failures should be fast. */
2989 if (secure_computing(scno) == -1)
2990 return -1;
2991diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2992index 987a7f5..d9d6071 100644
2993--- a/arch/arm/kernel/setup.c
2994+++ b/arch/arm/kernel/setup.c
2995@@ -100,21 +100,23 @@ EXPORT_SYMBOL(system_serial_high);
2996 unsigned int elf_hwcap __read_mostly;
2997 EXPORT_SYMBOL(elf_hwcap);
2998
2999+pteval_t __supported_pte_mask __read_only;
3000+pmdval_t __supported_pmd_mask __read_only;
3001
3002 #ifdef MULTI_CPU
3003-struct processor processor __read_mostly;
3004+struct processor processor;
3005 #endif
3006 #ifdef MULTI_TLB
3007-struct cpu_tlb_fns cpu_tlb __read_mostly;
3008+struct cpu_tlb_fns cpu_tlb __read_only;
3009 #endif
3010 #ifdef MULTI_USER
3011-struct cpu_user_fns cpu_user __read_mostly;
3012+struct cpu_user_fns cpu_user __read_only;
3013 #endif
3014 #ifdef MULTI_CACHE
3015-struct cpu_cache_fns cpu_cache __read_mostly;
3016+struct cpu_cache_fns cpu_cache __read_only;
3017 #endif
3018 #ifdef CONFIG_OUTER_CACHE
3019-struct outer_cache_fns outer_cache __read_mostly;
3020+struct outer_cache_fns outer_cache __read_only;
3021 EXPORT_SYMBOL(outer_cache);
3022 #endif
3023
3024@@ -247,9 +249,13 @@ static int __get_cpu_architecture(void)
3025 asm("mrc p15, 0, %0, c0, c1, 4"
3026 : "=r" (mmfr0));
3027 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3028- (mmfr0 & 0x000000f0) >= 0x00000030)
3029+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3030 cpu_arch = CPU_ARCH_ARMv7;
3031- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3032+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3033+ __supported_pte_mask |= L_PTE_PXN;
3034+ __supported_pmd_mask |= PMD_PXNTABLE;
3035+ }
3036+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3037 (mmfr0 & 0x000000f0) == 0x00000020)
3038 cpu_arch = CPU_ARCH_ARMv6;
3039 else
3040@@ -573,7 +579,7 @@ static void __init setup_processor(void)
3041 __cpu_architecture = __get_cpu_architecture();
3042
3043 #ifdef MULTI_CPU
3044- processor = *list->proc;
3045+ memcpy((void *)&processor, list->proc, sizeof processor);
3046 #endif
3047 #ifdef MULTI_TLB
3048 cpu_tlb = *list->tlb;
3049diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3050index 04d6388..5115238 100644
3051--- a/arch/arm/kernel/signal.c
3052+++ b/arch/arm/kernel/signal.c
3053@@ -23,8 +23,6 @@
3054
3055 extern const unsigned long sigreturn_codes[7];
3056
3057-static unsigned long signal_return_offset;
3058-
3059 #ifdef CONFIG_CRUNCH
3060 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3061 {
3062@@ -395,8 +393,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3063 * except when the MPU has protected the vectors
3064 * page from PL0
3065 */
3066- retcode = mm->context.sigpage + signal_return_offset +
3067- (idx << 2) + thumb;
3068+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3069 } else
3070 #endif
3071 {
3072@@ -600,33 +597,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3073 } while (thread_flags & _TIF_WORK_MASK);
3074 return 0;
3075 }
3076-
3077-struct page *get_signal_page(void)
3078-{
3079- unsigned long ptr;
3080- unsigned offset;
3081- struct page *page;
3082- void *addr;
3083-
3084- page = alloc_pages(GFP_KERNEL, 0);
3085-
3086- if (!page)
3087- return NULL;
3088-
3089- addr = page_address(page);
3090-
3091- /* Give the signal return code some randomness */
3092- offset = 0x200 + (get_random_int() & 0x7fc);
3093- signal_return_offset = offset;
3094-
3095- /*
3096- * Copy signal return handlers into the vector page, and
3097- * set sigreturn to be a pointer to these.
3098- */
3099- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3100-
3101- ptr = (unsigned long)addr + offset;
3102- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3103-
3104- return page;
3105-}
3106diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3107index dc894ab..f929a0d 100644
3108--- a/arch/arm/kernel/smp.c
3109+++ b/arch/arm/kernel/smp.c
3110@@ -73,7 +73,7 @@ enum ipi_msg_type {
3111
3112 static DECLARE_COMPLETION(cpu_running);
3113
3114-static struct smp_operations smp_ops;
3115+static struct smp_operations smp_ops __read_only;
3116
3117 void __init smp_set_ops(struct smp_operations *ops)
3118 {
3119diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3120index 4636d56..ce4ec3d 100644
3121--- a/arch/arm/kernel/traps.c
3122+++ b/arch/arm/kernel/traps.c
3123@@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3124 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3125 {
3126 #ifdef CONFIG_KALLSYMS
3127- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3128+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3129 #else
3130 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3131 #endif
3132@@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3133 static int die_owner = -1;
3134 static unsigned int die_nest_count;
3135
3136+extern void gr_handle_kernel_exploit(void);
3137+
3138 static unsigned long oops_begin(void)
3139 {
3140 int cpu;
3141@@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3142 panic("Fatal exception in interrupt");
3143 if (panic_on_oops)
3144 panic("Fatal exception");
3145+
3146+ gr_handle_kernel_exploit();
3147+
3148 if (signr)
3149 do_exit(signr);
3150 }
3151@@ -642,7 +647,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3152 * The user helper at 0xffff0fe0 must be used instead.
3153 * (see entry-armv.S for details)
3154 */
3155+ pax_open_kernel();
3156 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3157+ pax_close_kernel();
3158 }
3159 return 0;
3160
3161@@ -899,7 +906,11 @@ void __init early_trap_init(void *vectors_base)
3162 kuser_init(vectors_base);
3163
3164 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3165- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3166+
3167+#ifndef CONFIG_PAX_MEMORY_UDEREF
3168+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3169+#endif
3170+
3171 #else /* ifndef CONFIG_CPU_V7M */
3172 /*
3173 * on V7-M there is no need to copy the vector table to a dedicated
3174diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3175index 7bcee5c..e2f3249 100644
3176--- a/arch/arm/kernel/vmlinux.lds.S
3177+++ b/arch/arm/kernel/vmlinux.lds.S
3178@@ -8,7 +8,11 @@
3179 #include <asm/thread_info.h>
3180 #include <asm/memory.h>
3181 #include <asm/page.h>
3182-
3183+
3184+#ifdef CONFIG_PAX_KERNEXEC
3185+#include <asm/pgtable.h>
3186+#endif
3187+
3188 #define PROC_INFO \
3189 . = ALIGN(4); \
3190 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3191@@ -34,7 +38,7 @@
3192 #endif
3193
3194 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3195- defined(CONFIG_GENERIC_BUG)
3196+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3197 #define ARM_EXIT_KEEP(x) x
3198 #define ARM_EXIT_DISCARD(x)
3199 #else
3200@@ -90,6 +94,11 @@ SECTIONS
3201 _text = .;
3202 HEAD_TEXT
3203 }
3204+
3205+#ifdef CONFIG_PAX_KERNEXEC
3206+ . = ALIGN(1<<SECTION_SHIFT);
3207+#endif
3208+
3209 .text : { /* Real text segment */
3210 _stext = .; /* Text and read-only data */
3211 __exception_text_start = .;
3212@@ -112,6 +121,8 @@ SECTIONS
3213 ARM_CPU_KEEP(PROC_INFO)
3214 }
3215
3216+ _etext = .; /* End of text section */
3217+
3218 RO_DATA(PAGE_SIZE)
3219
3220 . = ALIGN(4);
3221@@ -142,7 +153,9 @@ SECTIONS
3222
3223 NOTES
3224
3225- _etext = .; /* End of text and rodata section */
3226+#ifdef CONFIG_PAX_KERNEXEC
3227+ . = ALIGN(1<<SECTION_SHIFT);
3228+#endif
3229
3230 #ifndef CONFIG_XIP_KERNEL
3231 . = ALIGN(PAGE_SIZE);
3232@@ -220,6 +233,11 @@ SECTIONS
3233 . = PAGE_OFFSET + TEXT_OFFSET;
3234 #else
3235 __init_end = .;
3236+
3237+#ifdef CONFIG_PAX_KERNEXEC
3238+ . = ALIGN(1<<SECTION_SHIFT);
3239+#endif
3240+
3241 . = ALIGN(THREAD_SIZE);
3242 __data_loc = .;
3243 #endif
3244diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3245index 2a700e0..745b980 100644
3246--- a/arch/arm/kvm/arm.c
3247+++ b/arch/arm/kvm/arm.c
3248@@ -56,7 +56,7 @@ static unsigned long hyp_default_vectors;
3249 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3250
3251 /* The VMID used in the VTTBR */
3252-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3253+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3254 static u8 kvm_next_vmid;
3255 static DEFINE_SPINLOCK(kvm_vmid_lock);
3256
3257@@ -397,7 +397,7 @@ void force_vm_exit(const cpumask_t *mask)
3258 */
3259 static bool need_new_vmid_gen(struct kvm *kvm)
3260 {
3261- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3262+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3263 }
3264
3265 /**
3266@@ -430,7 +430,7 @@ static void update_vttbr(struct kvm *kvm)
3267
3268 /* First user of a new VMID generation? */
3269 if (unlikely(kvm_next_vmid == 0)) {
3270- atomic64_inc(&kvm_vmid_gen);
3271+ atomic64_inc_unchecked(&kvm_vmid_gen);
3272 kvm_next_vmid = 1;
3273
3274 /*
3275@@ -447,7 +447,7 @@ static void update_vttbr(struct kvm *kvm)
3276 kvm_call_hyp(__kvm_flush_vm_context);
3277 }
3278
3279- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3280+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3281 kvm->arch.vmid = kvm_next_vmid;
3282 kvm_next_vmid++;
3283
3284diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3285index 14a0d98..7771a7d 100644
3286--- a/arch/arm/lib/clear_user.S
3287+++ b/arch/arm/lib/clear_user.S
3288@@ -12,14 +12,14 @@
3289
3290 .text
3291
3292-/* Prototype: int __clear_user(void *addr, size_t sz)
3293+/* Prototype: int ___clear_user(void *addr, size_t sz)
3294 * Purpose : clear some user memory
3295 * Params : addr - user memory address to clear
3296 * : sz - number of bytes to clear
3297 * Returns : number of bytes NOT cleared
3298 */
3299 ENTRY(__clear_user_std)
3300-WEAK(__clear_user)
3301+WEAK(___clear_user)
3302 stmfd sp!, {r1, lr}
3303 mov r2, #0
3304 cmp r1, #4
3305@@ -44,7 +44,7 @@ WEAK(__clear_user)
3306 USER( strnebt r2, [r0])
3307 mov r0, #0
3308 ldmfd sp!, {r1, pc}
3309-ENDPROC(__clear_user)
3310+ENDPROC(___clear_user)
3311 ENDPROC(__clear_user_std)
3312
3313 .pushsection .fixup,"ax"
3314diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3315index 66a477a..bee61d3 100644
3316--- a/arch/arm/lib/copy_from_user.S
3317+++ b/arch/arm/lib/copy_from_user.S
3318@@ -16,7 +16,7 @@
3319 /*
3320 * Prototype:
3321 *
3322- * size_t __copy_from_user(void *to, const void *from, size_t n)
3323+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3324 *
3325 * Purpose:
3326 *
3327@@ -84,11 +84,11 @@
3328
3329 .text
3330
3331-ENTRY(__copy_from_user)
3332+ENTRY(___copy_from_user)
3333
3334 #include "copy_template.S"
3335
3336-ENDPROC(__copy_from_user)
3337+ENDPROC(___copy_from_user)
3338
3339 .pushsection .fixup,"ax"
3340 .align 0
3341diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3342index 6ee2f67..d1cce76 100644
3343--- a/arch/arm/lib/copy_page.S
3344+++ b/arch/arm/lib/copy_page.S
3345@@ -10,6 +10,7 @@
3346 * ASM optimised string functions
3347 */
3348 #include <linux/linkage.h>
3349+#include <linux/const.h>
3350 #include <asm/assembler.h>
3351 #include <asm/asm-offsets.h>
3352 #include <asm/cache.h>
3353diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3354index d066df6..df28194 100644
3355--- a/arch/arm/lib/copy_to_user.S
3356+++ b/arch/arm/lib/copy_to_user.S
3357@@ -16,7 +16,7 @@
3358 /*
3359 * Prototype:
3360 *
3361- * size_t __copy_to_user(void *to, const void *from, size_t n)
3362+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3363 *
3364 * Purpose:
3365 *
3366@@ -88,11 +88,11 @@
3367 .text
3368
3369 ENTRY(__copy_to_user_std)
3370-WEAK(__copy_to_user)
3371+WEAK(___copy_to_user)
3372
3373 #include "copy_template.S"
3374
3375-ENDPROC(__copy_to_user)
3376+ENDPROC(___copy_to_user)
3377 ENDPROC(__copy_to_user_std)
3378
3379 .pushsection .fixup,"ax"
3380diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3381index 7d08b43..f7ca7ea 100644
3382--- a/arch/arm/lib/csumpartialcopyuser.S
3383+++ b/arch/arm/lib/csumpartialcopyuser.S
3384@@ -57,8 +57,8 @@
3385 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3386 */
3387
3388-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3389-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3390+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3391+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3392
3393 #include "csumpartialcopygeneric.S"
3394
3395diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3396index 5306de3..aed6d03 100644
3397--- a/arch/arm/lib/delay.c
3398+++ b/arch/arm/lib/delay.c
3399@@ -28,7 +28,7 @@
3400 /*
3401 * Default to the loop-based delay implementation.
3402 */
3403-struct arm_delay_ops arm_delay_ops = {
3404+struct arm_delay_ops arm_delay_ops __read_only = {
3405 .delay = __loop_delay,
3406 .const_udelay = __loop_const_udelay,
3407 .udelay = __loop_udelay,
3408diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3409index 3e58d71..029817c 100644
3410--- a/arch/arm/lib/uaccess_with_memcpy.c
3411+++ b/arch/arm/lib/uaccess_with_memcpy.c
3412@@ -136,7 +136,7 @@ out:
3413 }
3414
3415 unsigned long
3416-__copy_to_user(void __user *to, const void *from, unsigned long n)
3417+___copy_to_user(void __user *to, const void *from, unsigned long n)
3418 {
3419 /*
3420 * This test is stubbed out of the main function above to keep
3421@@ -190,7 +190,7 @@ out:
3422 return n;
3423 }
3424
3425-unsigned long __clear_user(void __user *addr, unsigned long n)
3426+unsigned long ___clear_user(void __user *addr, unsigned long n)
3427 {
3428 /* See rational for this in __copy_to_user() above. */
3429 if (n < 64)
3430diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3431index f3407a5..bd4256f 100644
3432--- a/arch/arm/mach-kirkwood/common.c
3433+++ b/arch/arm/mach-kirkwood/common.c
3434@@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3435 clk_gate_ops.disable(hw);
3436 }
3437
3438-static struct clk_ops clk_gate_fn_ops;
3439+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3440+{
3441+ return clk_gate_ops.is_enabled(hw);
3442+}
3443+
3444+static struct clk_ops clk_gate_fn_ops = {
3445+ .enable = clk_gate_fn_enable,
3446+ .disable = clk_gate_fn_disable,
3447+ .is_enabled = clk_gate_fn_is_enabled,
3448+};
3449
3450 static struct clk __init *clk_register_gate_fn(struct device *dev,
3451 const char *name,
3452@@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3453 gate_fn->fn_en = fn_en;
3454 gate_fn->fn_dis = fn_dis;
3455
3456- /* ops is the gate ops, but with our enable/disable functions */
3457- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3458- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3459- clk_gate_fn_ops = clk_gate_ops;
3460- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3461- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3462- }
3463-
3464 clk = clk_register(dev, &gate_fn->gate.hw);
3465
3466 if (IS_ERR(clk))
3467diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3468index 827d1500..2885dc6 100644
3469--- a/arch/arm/mach-omap2/board-n8x0.c
3470+++ b/arch/arm/mach-omap2/board-n8x0.c
3471@@ -627,7 +627,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3472 }
3473 #endif
3474
3475-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3476+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3477 .late_init = n8x0_menelaus_late_init,
3478 };
3479
3480diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3481index d24926e..a7645a6 100644
3482--- a/arch/arm/mach-omap2/gpmc.c
3483+++ b/arch/arm/mach-omap2/gpmc.c
3484@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3485 };
3486
3487 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3488-static struct irq_chip gpmc_irq_chip;
3489 static int gpmc_irq_start;
3490
3491 static struct resource gpmc_mem_root;
3492@@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3493
3494 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3495
3496+static struct irq_chip gpmc_irq_chip = {
3497+ .name = "gpmc",
3498+ .irq_startup = gpmc_irq_noop_ret,
3499+ .irq_enable = gpmc_irq_enable,
3500+ .irq_disable = gpmc_irq_disable,
3501+ .irq_shutdown = gpmc_irq_noop,
3502+ .irq_ack = gpmc_irq_noop,
3503+ .irq_mask = gpmc_irq_noop,
3504+ .irq_unmask = gpmc_irq_noop,
3505+
3506+};
3507+
3508 static int gpmc_setup_irq(void)
3509 {
3510 int i;
3511@@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3512 return gpmc_irq_start;
3513 }
3514
3515- gpmc_irq_chip.name = "gpmc";
3516- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3517- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3518- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3519- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3520- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3521- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3522- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3523-
3524 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3525 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3526
3527diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3528index f991016..145ebeb 100644
3529--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3530+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3531@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3532 int (*finish_suspend)(unsigned long cpu_state);
3533 void (*resume)(void);
3534 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3535-};
3536+} __no_const;
3537
3538 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3539 static struct powerdomain *mpuss_pd;
3540@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3541 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3542 {}
3543
3544-struct cpu_pm_ops omap_pm_ops = {
3545+static struct cpu_pm_ops omap_pm_ops __read_only = {
3546 .finish_suspend = default_finish_suspend,
3547 .resume = dummy_cpu_resume,
3548 .scu_prepare = dummy_scu_prepare,
3549diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3550index 3664562..72f85c6 100644
3551--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3552+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3553@@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3554 return NOTIFY_OK;
3555 }
3556
3557-static struct notifier_block __refdata irq_hotplug_notifier = {
3558+static struct notifier_block irq_hotplug_notifier = {
3559 .notifier_call = irq_cpu_hotplug_notify,
3560 };
3561
3562diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3563index e0a398c..a470fa5 100644
3564--- a/arch/arm/mach-omap2/omap_device.c
3565+++ b/arch/arm/mach-omap2/omap_device.c
3566@@ -508,7 +508,7 @@ void omap_device_delete(struct omap_device *od)
3567 struct platform_device __init *omap_device_build(const char *pdev_name,
3568 int pdev_id,
3569 struct omap_hwmod *oh,
3570- void *pdata, int pdata_len)
3571+ const void *pdata, int pdata_len)
3572 {
3573 struct omap_hwmod *ohs[] = { oh };
3574
3575@@ -536,7 +536,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3576 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3577 int pdev_id,
3578 struct omap_hwmod **ohs,
3579- int oh_cnt, void *pdata,
3580+ int oh_cnt, const void *pdata,
3581 int pdata_len)
3582 {
3583 int ret = -ENOMEM;
3584diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3585index 78c02b3..c94109a 100644
3586--- a/arch/arm/mach-omap2/omap_device.h
3587+++ b/arch/arm/mach-omap2/omap_device.h
3588@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3589 /* Core code interface */
3590
3591 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3592- struct omap_hwmod *oh, void *pdata,
3593+ struct omap_hwmod *oh, const void *pdata,
3594 int pdata_len);
3595
3596 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3597 struct omap_hwmod **oh, int oh_cnt,
3598- void *pdata, int pdata_len);
3599+ const void *pdata, int pdata_len);
3600
3601 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3602 struct omap_hwmod **ohs, int oh_cnt);
3603diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3604index 8a1b5e0..5f30074 100644
3605--- a/arch/arm/mach-omap2/omap_hwmod.c
3606+++ b/arch/arm/mach-omap2/omap_hwmod.c
3607@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3608 int (*init_clkdm)(struct omap_hwmod *oh);
3609 void (*update_context_lost)(struct omap_hwmod *oh);
3610 int (*get_context_lost)(struct omap_hwmod *oh);
3611-};
3612+} __no_const;
3613
3614 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3615-static struct omap_hwmod_soc_ops soc_ops;
3616+static struct omap_hwmod_soc_ops soc_ops __read_only;
3617
3618 /* omap_hwmod_list contains all registered struct omap_hwmods */
3619 static LIST_HEAD(omap_hwmod_list);
3620diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3621index 95fee54..cfa9cf1 100644
3622--- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3623+++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3624@@ -10,6 +10,7 @@
3625
3626 #include <linux/kernel.h>
3627 #include <linux/init.h>
3628+#include <asm/pgtable.h>
3629
3630 #include "powerdomain.h"
3631
3632@@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3633
3634 void __init am43xx_powerdomains_init(void)
3635 {
3636- omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3637+ pax_open_kernel();
3638+ *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3639+ pax_close_kernel();
3640 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3641 pwrdm_register_pwrdms(powerdomains_am43xx);
3642 pwrdm_complete_init();
3643diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3644index d15c7bb..b2d1f0c 100644
3645--- a/arch/arm/mach-omap2/wd_timer.c
3646+++ b/arch/arm/mach-omap2/wd_timer.c
3647@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3648 struct omap_hwmod *oh;
3649 char *oh_name = "wd_timer2";
3650 char *dev_name = "omap_wdt";
3651- struct omap_wd_timer_platform_data pdata;
3652+ static struct omap_wd_timer_platform_data pdata = {
3653+ .read_reset_sources = prm_read_reset_sources
3654+ };
3655
3656 if (!cpu_class_is_omap2() || of_have_populated_dt())
3657 return 0;
3658@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3659 return -EINVAL;
3660 }
3661
3662- pdata.read_reset_sources = prm_read_reset_sources;
3663-
3664 pdev = omap_device_build(dev_name, id, oh, &pdata,
3665 sizeof(struct omap_wd_timer_platform_data));
3666 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3667diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3668index b82dcae..44ee5b6 100644
3669--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3670+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3671@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3672 bool entered_lp2 = false;
3673
3674 if (tegra_pending_sgi())
3675- ACCESS_ONCE(abort_flag) = true;
3676+ ACCESS_ONCE_RW(abort_flag) = true;
3677
3678 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3679
3680diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3681index bdb3564..cebb96f 100644
3682--- a/arch/arm/mach-ux500/setup.h
3683+++ b/arch/arm/mach-ux500/setup.h
3684@@ -39,13 +39,6 @@ extern void ux500_timer_init(void);
3685 .type = MT_DEVICE, \
3686 }
3687
3688-#define __MEM_DEV_DESC(x, sz) { \
3689- .virtual = IO_ADDRESS(x), \
3690- .pfn = __phys_to_pfn(x), \
3691- .length = sz, \
3692- .type = MT_MEMORY, \
3693-}
3694-
3695 extern struct smp_operations ux500_smp_ops;
3696 extern void ux500_cpu_die(unsigned int cpu);
3697
3698diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3699index 1f8fed9..14d7823 100644
3700--- a/arch/arm/mm/Kconfig
3701+++ b/arch/arm/mm/Kconfig
3702@@ -446,7 +446,7 @@ config CPU_32v5
3703
3704 config CPU_32v6
3705 bool
3706- select CPU_USE_DOMAINS if CPU_V6 && MMU
3707+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3708 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3709
3710 config CPU_32v6K
3711@@ -601,6 +601,7 @@ config CPU_CP15_MPU
3712
3713 config CPU_USE_DOMAINS
3714 bool
3715+ depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3716 help
3717 This option enables or disables the use of domain switching
3718 via the set_fs() function.
3719@@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3720 config KUSER_HELPERS
3721 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3722 default y
3723+ depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3724 help
3725 Warning: disabling this option may break user programs.
3726
3727@@ -812,7 +814,7 @@ config KUSER_HELPERS
3728 See Documentation/arm/kernel_user_helpers.txt for details.
3729
3730 However, the fixed address nature of these helpers can be used
3731- by ROP (return orientated programming) authors when creating
3732+ by ROP (Return Oriented Programming) authors when creating
3733 exploits.
3734
3735 If all of the binaries and libraries which run on your platform
3736diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3737index 9240364..a2b8cf3 100644
3738--- a/arch/arm/mm/alignment.c
3739+++ b/arch/arm/mm/alignment.c
3740@@ -212,10 +212,12 @@ union offset_union {
3741 #define __get16_unaligned_check(ins,val,addr) \
3742 do { \
3743 unsigned int err = 0, v, a = addr; \
3744+ pax_open_userland(); \
3745 __get8_unaligned_check(ins,v,a,err); \
3746 val = v << ((BE) ? 8 : 0); \
3747 __get8_unaligned_check(ins,v,a,err); \
3748 val |= v << ((BE) ? 0 : 8); \
3749+ pax_close_userland(); \
3750 if (err) \
3751 goto fault; \
3752 } while (0)
3753@@ -229,6 +231,7 @@ union offset_union {
3754 #define __get32_unaligned_check(ins,val,addr) \
3755 do { \
3756 unsigned int err = 0, v, a = addr; \
3757+ pax_open_userland(); \
3758 __get8_unaligned_check(ins,v,a,err); \
3759 val = v << ((BE) ? 24 : 0); \
3760 __get8_unaligned_check(ins,v,a,err); \
3761@@ -237,6 +240,7 @@ union offset_union {
3762 val |= v << ((BE) ? 8 : 16); \
3763 __get8_unaligned_check(ins,v,a,err); \
3764 val |= v << ((BE) ? 0 : 24); \
3765+ pax_close_userland(); \
3766 if (err) \
3767 goto fault; \
3768 } while (0)
3769@@ -250,6 +254,7 @@ union offset_union {
3770 #define __put16_unaligned_check(ins,val,addr) \
3771 do { \
3772 unsigned int err = 0, v = val, a = addr; \
3773+ pax_open_userland(); \
3774 __asm__( FIRST_BYTE_16 \
3775 ARM( "1: "ins" %1, [%2], #1\n" ) \
3776 THUMB( "1: "ins" %1, [%2]\n" ) \
3777@@ -269,6 +274,7 @@ union offset_union {
3778 " .popsection\n" \
3779 : "=r" (err), "=&r" (v), "=&r" (a) \
3780 : "0" (err), "1" (v), "2" (a)); \
3781+ pax_close_userland(); \
3782 if (err) \
3783 goto fault; \
3784 } while (0)
3785@@ -282,6 +288,7 @@ union offset_union {
3786 #define __put32_unaligned_check(ins,val,addr) \
3787 do { \
3788 unsigned int err = 0, v = val, a = addr; \
3789+ pax_open_userland(); \
3790 __asm__( FIRST_BYTE_32 \
3791 ARM( "1: "ins" %1, [%2], #1\n" ) \
3792 THUMB( "1: "ins" %1, [%2]\n" ) \
3793@@ -311,6 +318,7 @@ union offset_union {
3794 " .popsection\n" \
3795 : "=r" (err), "=&r" (v), "=&r" (a) \
3796 : "0" (err), "1" (v), "2" (a)); \
3797+ pax_close_userland(); \
3798 if (err) \
3799 goto fault; \
3800 } while (0)
3801diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3802index 447da6f..77a5057 100644
3803--- a/arch/arm/mm/cache-l2x0.c
3804+++ b/arch/arm/mm/cache-l2x0.c
3805@@ -45,7 +45,7 @@ struct l2x0_of_data {
3806 void (*setup)(const struct device_node *, u32 *, u32 *);
3807 void (*save)(void);
3808 struct outer_cache_fns outer_cache;
3809-};
3810+} __do_const;
3811
3812 static bool of_init = false;
3813
3814diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3815index 84e6f77..0b52f31 100644
3816--- a/arch/arm/mm/context.c
3817+++ b/arch/arm/mm/context.c
3818@@ -43,7 +43,7 @@
3819 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3820
3821 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3822-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3823+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3824 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3825
3826 static DEFINE_PER_CPU(atomic64_t, active_asids);
3827@@ -180,7 +180,7 @@ static int is_reserved_asid(u64 asid)
3828 static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3829 {
3830 u64 asid = atomic64_read(&mm->context.id);
3831- u64 generation = atomic64_read(&asid_generation);
3832+ u64 generation = atomic64_read_unchecked(&asid_generation);
3833
3834 if (asid != 0 && is_reserved_asid(asid)) {
3835 /*
3836@@ -198,7 +198,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3837 */
3838 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3839 if (asid == NUM_USER_ASIDS) {
3840- generation = atomic64_add_return(ASID_FIRST_VERSION,
3841+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3842 &asid_generation);
3843 flush_context(cpu);
3844 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3845@@ -227,14 +227,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3846 cpu_set_reserved_ttbr0();
3847
3848 asid = atomic64_read(&mm->context.id);
3849- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3850+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3851 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3852 goto switch_mm_fastpath;
3853
3854 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3855 /* Check that our ASID belongs to the current generation. */
3856 asid = atomic64_read(&mm->context.id);
3857- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3858+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3859 asid = new_context(mm, cpu);
3860 atomic64_set(&mm->context.id, asid);
3861 }
3862diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3863index eb8830a..5360ce7 100644
3864--- a/arch/arm/mm/fault.c
3865+++ b/arch/arm/mm/fault.c
3866@@ -25,6 +25,7 @@
3867 #include <asm/system_misc.h>
3868 #include <asm/system_info.h>
3869 #include <asm/tlbflush.h>
3870+#include <asm/sections.h>
3871
3872 #include "fault.h"
3873
3874@@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3875 if (fixup_exception(regs))
3876 return;
3877
3878+#ifdef CONFIG_PAX_MEMORY_UDEREF
3879+ if (addr < TASK_SIZE) {
3880+ if (current->signal->curr_ip)
3881+ 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),
3882+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3883+ else
3884+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3885+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3886+ }
3887+#endif
3888+
3889+#ifdef CONFIG_PAX_KERNEXEC
3890+ if ((fsr & FSR_WRITE) &&
3891+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3892+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3893+ {
3894+ if (current->signal->curr_ip)
3895+ 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),
3896+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3897+ else
3898+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3899+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3900+ }
3901+#endif
3902+
3903 /*
3904 * No handler, we'll have to terminate things with extreme prejudice.
3905 */
3906@@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3907 }
3908 #endif
3909
3910+#ifdef CONFIG_PAX_PAGEEXEC
3911+ if (fsr & FSR_LNX_PF) {
3912+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3913+ do_group_exit(SIGKILL);
3914+ }
3915+#endif
3916+
3917 tsk->thread.address = addr;
3918 tsk->thread.error_code = fsr;
3919 tsk->thread.trap_no = 14;
3920@@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3921 }
3922 #endif /* CONFIG_MMU */
3923
3924+#ifdef CONFIG_PAX_PAGEEXEC
3925+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3926+{
3927+ long i;
3928+
3929+ printk(KERN_ERR "PAX: bytes at PC: ");
3930+ for (i = 0; i < 20; i++) {
3931+ unsigned char c;
3932+ if (get_user(c, (__force unsigned char __user *)pc+i))
3933+ printk(KERN_CONT "?? ");
3934+ else
3935+ printk(KERN_CONT "%02x ", c);
3936+ }
3937+ printk("\n");
3938+
3939+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3940+ for (i = -1; i < 20; i++) {
3941+ unsigned long c;
3942+ if (get_user(c, (__force unsigned long __user *)sp+i))
3943+ printk(KERN_CONT "???????? ");
3944+ else
3945+ printk(KERN_CONT "%08lx ", c);
3946+ }
3947+ printk("\n");
3948+}
3949+#endif
3950+
3951 /*
3952 * First Level Translation Fault Handler
3953 *
3954@@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3955 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3956 struct siginfo info;
3957
3958+#ifdef CONFIG_PAX_MEMORY_UDEREF
3959+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3960+ if (current->signal->curr_ip)
3961+ 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),
3962+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3963+ else
3964+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3965+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3966+ goto die;
3967+ }
3968+#endif
3969+
3970 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3971 return;
3972
3973+die:
3974 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3975 inf->name, fsr, addr);
3976
3977@@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3978 ifsr_info[nr].name = name;
3979 }
3980
3981+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3982+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3983+
3984 asmlinkage void __exception
3985 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3986 {
3987 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3988 struct siginfo info;
3989+ unsigned long pc = instruction_pointer(regs);
3990+
3991+ if (user_mode(regs)) {
3992+ unsigned long sigpage = current->mm->context.sigpage;
3993+
3994+ if (sigpage <= pc && pc < sigpage + 7*4) {
3995+ if (pc < sigpage + 3*4)
3996+ sys_sigreturn(regs);
3997+ else
3998+ sys_rt_sigreturn(regs);
3999+ return;
4000+ }
4001+ if (pc == 0xffff0f60UL) {
4002+ /*
4003+ * PaX: __kuser_cmpxchg64 emulation
4004+ */
4005+ // TODO
4006+ //regs->ARM_pc = regs->ARM_lr;
4007+ //return;
4008+ }
4009+ if (pc == 0xffff0fa0UL) {
4010+ /*
4011+ * PaX: __kuser_memory_barrier emulation
4012+ */
4013+ // dmb(); implied by the exception
4014+ regs->ARM_pc = regs->ARM_lr;
4015+ return;
4016+ }
4017+ if (pc == 0xffff0fc0UL) {
4018+ /*
4019+ * PaX: __kuser_cmpxchg emulation
4020+ */
4021+ // TODO
4022+ //long new;
4023+ //int op;
4024+
4025+ //op = FUTEX_OP_SET << 28;
4026+ //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4027+ //regs->ARM_r0 = old != new;
4028+ //regs->ARM_pc = regs->ARM_lr;
4029+ //return;
4030+ }
4031+ if (pc == 0xffff0fe0UL) {
4032+ /*
4033+ * PaX: __kuser_get_tls emulation
4034+ */
4035+ regs->ARM_r0 = current_thread_info()->tp_value[0];
4036+ regs->ARM_pc = regs->ARM_lr;
4037+ return;
4038+ }
4039+ }
4040+
4041+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4042+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4043+ if (current->signal->curr_ip)
4044+ 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),
4045+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4046+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4047+ else
4048+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4049+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4050+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4051+ goto die;
4052+ }
4053+#endif
4054+
4055+#ifdef CONFIG_PAX_REFCOUNT
4056+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4057+ unsigned int bkpt;
4058+
4059+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4060+ current->thread.error_code = ifsr;
4061+ current->thread.trap_no = 0;
4062+ pax_report_refcount_overflow(regs);
4063+ fixup_exception(regs);
4064+ return;
4065+ }
4066+ }
4067+#endif
4068
4069 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4070 return;
4071
4072+die:
4073 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4074 inf->name, ifsr, addr);
4075
4076diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4077index cf08bdf..772656c 100644
4078--- a/arch/arm/mm/fault.h
4079+++ b/arch/arm/mm/fault.h
4080@@ -3,6 +3,7 @@
4081
4082 /*
4083 * Fault status register encodings. We steal bit 31 for our own purposes.
4084+ * Set when the FSR value is from an instruction fault.
4085 */
4086 #define FSR_LNX_PF (1 << 31)
4087 #define FSR_WRITE (1 << 11)
4088@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4089 }
4090 #endif
4091
4092+/* valid for LPAE and !LPAE */
4093+static inline int is_xn_fault(unsigned int fsr)
4094+{
4095+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4096+}
4097+
4098+static inline int is_domain_fault(unsigned int fsr)
4099+{
4100+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4101+}
4102+
4103 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4104 unsigned long search_exception_table(unsigned long addr);
4105
4106diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4107index 3e8f106..a0a1fe4 100644
4108--- a/arch/arm/mm/init.c
4109+++ b/arch/arm/mm/init.c
4110@@ -30,6 +30,8 @@
4111 #include <asm/setup.h>
4112 #include <asm/tlb.h>
4113 #include <asm/fixmap.h>
4114+#include <asm/system_info.h>
4115+#include <asm/cp15.h>
4116
4117 #include <asm/mach/arch.h>
4118 #include <asm/mach/map.h>
4119@@ -681,7 +683,46 @@ void free_initmem(void)
4120 {
4121 #ifdef CONFIG_HAVE_TCM
4122 extern char __tcm_start, __tcm_end;
4123+#endif
4124
4125+#ifdef CONFIG_PAX_KERNEXEC
4126+ unsigned long addr;
4127+ pgd_t *pgd;
4128+ pud_t *pud;
4129+ pmd_t *pmd;
4130+ int cpu_arch = cpu_architecture();
4131+ unsigned int cr = get_cr();
4132+
4133+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4134+ /* make pages tables, etc before .text NX */
4135+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; 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 init NX */
4142+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4143+ pgd = pgd_offset_k(addr);
4144+ pud = pud_offset(pgd, addr);
4145+ pmd = pmd_offset(pud, addr);
4146+ __section_update(pmd, addr, PMD_SECT_XN);
4147+ }
4148+ /* make kernel code/rodata RX */
4149+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4150+ pgd = pgd_offset_k(addr);
4151+ pud = pud_offset(pgd, addr);
4152+ pmd = pmd_offset(pud, addr);
4153+#ifdef CONFIG_ARM_LPAE
4154+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4155+#else
4156+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4157+#endif
4158+ }
4159+ }
4160+#endif
4161+
4162+#ifdef CONFIG_HAVE_TCM
4163 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4164 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4165 #endif
4166diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4167index f123d6e..04bf569 100644
4168--- a/arch/arm/mm/ioremap.c
4169+++ b/arch/arm/mm/ioremap.c
4170@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4171 unsigned int mtype;
4172
4173 if (cached)
4174- mtype = MT_MEMORY;
4175+ mtype = MT_MEMORY_RX;
4176 else
4177- mtype = MT_MEMORY_NONCACHED;
4178+ mtype = MT_MEMORY_NONCACHED_RX;
4179
4180 return __arm_ioremap_caller(phys_addr, size, mtype,
4181 __builtin_return_address(0));
4182diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4183index 5e85ed3..b10a7ed 100644
4184--- a/arch/arm/mm/mmap.c
4185+++ b/arch/arm/mm/mmap.c
4186@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4187 struct vm_area_struct *vma;
4188 int do_align = 0;
4189 int aliasing = cache_is_vipt_aliasing();
4190+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4191 struct vm_unmapped_area_info info;
4192
4193 /*
4194@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4195 if (len > TASK_SIZE)
4196 return -ENOMEM;
4197
4198+#ifdef CONFIG_PAX_RANDMMAP
4199+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4200+#endif
4201+
4202 if (addr) {
4203 if (do_align)
4204 addr = COLOUR_ALIGN(addr, pgoff);
4205@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4206 addr = PAGE_ALIGN(addr);
4207
4208 vma = find_vma(mm, addr);
4209- if (TASK_SIZE - len >= addr &&
4210- (!vma || addr + len <= vma->vm_start))
4211+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4212 return addr;
4213 }
4214
4215@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4216 info.high_limit = TASK_SIZE;
4217 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4218 info.align_offset = pgoff << PAGE_SHIFT;
4219+ info.threadstack_offset = offset;
4220 return vm_unmapped_area(&info);
4221 }
4222
4223@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4224 unsigned long addr = addr0;
4225 int do_align = 0;
4226 int aliasing = cache_is_vipt_aliasing();
4227+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4228 struct vm_unmapped_area_info info;
4229
4230 /*
4231@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4232 return addr;
4233 }
4234
4235+#ifdef CONFIG_PAX_RANDMMAP
4236+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4237+#endif
4238+
4239 /* requesting a specific address */
4240 if (addr) {
4241 if (do_align)
4242@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4243 else
4244 addr = PAGE_ALIGN(addr);
4245 vma = find_vma(mm, addr);
4246- if (TASK_SIZE - len >= addr &&
4247- (!vma || addr + len <= vma->vm_start))
4248+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4249 return addr;
4250 }
4251
4252@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4253 info.high_limit = mm->mmap_base;
4254 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4255 info.align_offset = pgoff << PAGE_SHIFT;
4256+ info.threadstack_offset = offset;
4257 addr = vm_unmapped_area(&info);
4258
4259 /*
4260@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4261 {
4262 unsigned long random_factor = 0UL;
4263
4264+#ifdef CONFIG_PAX_RANDMMAP
4265+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4266+#endif
4267+
4268 /* 8 bits of randomness in 20 address space bits */
4269 if ((current->flags & PF_RANDOMIZE) &&
4270 !(current->personality & ADDR_NO_RANDOMIZE))
4271@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4272
4273 if (mmap_is_legacy()) {
4274 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4275+
4276+#ifdef CONFIG_PAX_RANDMMAP
4277+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4278+ mm->mmap_base += mm->delta_mmap;
4279+#endif
4280+
4281 mm->get_unmapped_area = arch_get_unmapped_area;
4282 } else {
4283 mm->mmap_base = mmap_base(random_factor);
4284+
4285+#ifdef CONFIG_PAX_RANDMMAP
4286+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4287+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4288+#endif
4289+
4290 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4291 }
4292 }
4293diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4294index 580ef2d..2da06ca 100644
4295--- a/arch/arm/mm/mmu.c
4296+++ b/arch/arm/mm/mmu.c
4297@@ -38,6 +38,22 @@
4298 #include "mm.h"
4299 #include "tcm.h"
4300
4301+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4302+void modify_domain(unsigned int dom, unsigned int type)
4303+{
4304+ struct thread_info *thread = current_thread_info();
4305+ unsigned int domain = thread->cpu_domain;
4306+ /*
4307+ * DOMAIN_MANAGER might be defined to some other value,
4308+ * use the arch-defined constant
4309+ */
4310+ domain &= ~domain_val(dom, 3);
4311+ thread->cpu_domain = domain | domain_val(dom, type);
4312+ set_domain(thread->cpu_domain);
4313+}
4314+EXPORT_SYMBOL(modify_domain);
4315+#endif
4316+
4317 /*
4318 * empty_zero_page is a special page that is used for
4319 * zero-initialized data and COW.
4320@@ -230,10 +246,18 @@ __setup("noalign", noalign_setup);
4321
4322 #endif /* ifdef CONFIG_CPU_CP15 / else */
4323
4324-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4325+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4326 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4327
4328-static struct mem_type mem_types[] = {
4329+#ifdef CONFIG_PAX_KERNEXEC
4330+#define L_PTE_KERNEXEC L_PTE_RDONLY
4331+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4332+#else
4333+#define L_PTE_KERNEXEC L_PTE_DIRTY
4334+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4335+#endif
4336+
4337+static struct mem_type mem_types[] __read_only = {
4338 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4339 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4340 L_PTE_SHARED,
4341@@ -262,16 +286,16 @@ static struct mem_type mem_types[] = {
4342 [MT_UNCACHED] = {
4343 .prot_pte = PROT_PTE_DEVICE,
4344 .prot_l1 = PMD_TYPE_TABLE,
4345- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4346+ .prot_sect = PROT_SECT_DEVICE,
4347 .domain = DOMAIN_IO,
4348 },
4349 [MT_CACHECLEAN] = {
4350- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4351+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4352 .domain = DOMAIN_KERNEL,
4353 },
4354 #ifndef CONFIG_ARM_LPAE
4355 [MT_MINICLEAN] = {
4356- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4357+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4358 .domain = DOMAIN_KERNEL,
4359 },
4360 #endif
4361@@ -279,36 +303,54 @@ static struct mem_type mem_types[] = {
4362 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4363 L_PTE_RDONLY,
4364 .prot_l1 = PMD_TYPE_TABLE,
4365- .domain = DOMAIN_USER,
4366+ .domain = DOMAIN_VECTORS,
4367 },
4368 [MT_HIGH_VECTORS] = {
4369 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4370 L_PTE_USER | L_PTE_RDONLY,
4371 .prot_l1 = PMD_TYPE_TABLE,
4372- .domain = DOMAIN_USER,
4373+ .domain = DOMAIN_VECTORS,
4374 },
4375- [MT_MEMORY] = {
4376+ [MT_MEMORY_RWX] = {
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_RW] = {
4383+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4384+ .prot_l1 = PMD_TYPE_TABLE,
4385+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4386+ .domain = DOMAIN_KERNEL,
4387+ },
4388+ [MT_MEMORY_RX] = {
4389+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4390+ .prot_l1 = PMD_TYPE_TABLE,
4391+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4392+ .domain = DOMAIN_KERNEL,
4393+ },
4394 [MT_ROM] = {
4395- .prot_sect = PMD_TYPE_SECT,
4396+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4397 .domain = DOMAIN_KERNEL,
4398 },
4399- [MT_MEMORY_NONCACHED] = {
4400+ [MT_MEMORY_NONCACHED_RW] = {
4401 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4402 L_PTE_MT_BUFFERABLE,
4403 .prot_l1 = PMD_TYPE_TABLE,
4404 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4405 .domain = DOMAIN_KERNEL,
4406 },
4407+ [MT_MEMORY_NONCACHED_RX] = {
4408+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4409+ L_PTE_MT_BUFFERABLE,
4410+ .prot_l1 = PMD_TYPE_TABLE,
4411+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4412+ .domain = DOMAIN_KERNEL,
4413+ },
4414 [MT_MEMORY_DTCM] = {
4415- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4416- L_PTE_XN,
4417+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4418 .prot_l1 = PMD_TYPE_TABLE,
4419- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4420+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4421 .domain = DOMAIN_KERNEL,
4422 },
4423 [MT_MEMORY_ITCM] = {
4424@@ -318,10 +360,10 @@ static struct mem_type mem_types[] = {
4425 },
4426 [MT_MEMORY_SO] = {
4427 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4428- L_PTE_MT_UNCACHED | L_PTE_XN,
4429+ L_PTE_MT_UNCACHED,
4430 .prot_l1 = PMD_TYPE_TABLE,
4431 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4432- PMD_SECT_UNCACHED | PMD_SECT_XN,
4433+ PMD_SECT_UNCACHED,
4434 .domain = DOMAIN_KERNEL,
4435 },
4436 [MT_MEMORY_DMA_READY] = {
4437@@ -407,9 +449,35 @@ static void __init build_mem_type_table(void)
4438 * to prevent speculative instruction fetches.
4439 */
4440 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4441+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4442 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4443+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4444 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4445+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4446 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4447+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4448+
4449+ /* Mark other regions on ARMv6+ as execute-never */
4450+
4451+#ifdef CONFIG_PAX_KERNEXEC
4452+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4453+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4454+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4455+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4456+#ifndef CONFIG_ARM_LPAE
4457+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4458+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4459+#endif
4460+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4461+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4462+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4463+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4464+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4465+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4466+#endif
4467+
4468+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4469+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4470 }
4471 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4472 /*
4473@@ -470,6 +538,9 @@ static void __init build_mem_type_table(void)
4474 * from SVC mode and no access from userspace.
4475 */
4476 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4477+#ifdef CONFIG_PAX_KERNEXEC
4478+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4479+#endif
4480 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4481 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4482 #endif
4483@@ -487,11 +558,17 @@ static void __init build_mem_type_table(void)
4484 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4485 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4486 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4487- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4488- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4489+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4490+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4491+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4492+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4493+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4494+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4495 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4496- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4497- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4498+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4499+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4500+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4501+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4502 }
4503 }
4504
4505@@ -502,15 +579,20 @@ static void __init build_mem_type_table(void)
4506 if (cpu_arch >= CPU_ARCH_ARMv6) {
4507 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4508 /* Non-cacheable Normal is XCB = 001 */
4509- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4510+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4511+ PMD_SECT_BUFFERED;
4512+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4513 PMD_SECT_BUFFERED;
4514 } else {
4515 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4516- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4517+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4518+ PMD_SECT_TEX(1);
4519+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4520 PMD_SECT_TEX(1);
4521 }
4522 } else {
4523- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4524+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4525+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4526 }
4527
4528 #ifdef CONFIG_ARM_LPAE
4529@@ -526,6 +608,8 @@ static void __init build_mem_type_table(void)
4530 vecs_pgprot |= PTE_EXT_AF;
4531 #endif
4532
4533+ user_pgprot |= __supported_pte_mask;
4534+
4535 for (i = 0; i < 16; i++) {
4536 pteval_t v = pgprot_val(protection_map[i]);
4537 protection_map[i] = __pgprot(v | user_pgprot);
4538@@ -543,10 +627,15 @@ static void __init build_mem_type_table(void)
4539
4540 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4541 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4542- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4543- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4544+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4545+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4546+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4547+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4548+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4549+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4550 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4551- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4552+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4553+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4554 mem_types[MT_ROM].prot_sect |= cp->pmd;
4555
4556 switch (cp->pmd) {
4557@@ -1188,18 +1277,15 @@ void __init arm_mm_memblock_reserve(void)
4558 * called function. This means you can't use any function or debugging
4559 * method which may touch any device, otherwise the kernel _will_ crash.
4560 */
4561+
4562+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4563+
4564 static void __init devicemaps_init(const struct machine_desc *mdesc)
4565 {
4566 struct map_desc map;
4567 unsigned long addr;
4568- void *vectors;
4569
4570- /*
4571- * Allocate the vector page early.
4572- */
4573- vectors = early_alloc(PAGE_SIZE * 2);
4574-
4575- early_trap_init(vectors);
4576+ early_trap_init(&vectors);
4577
4578 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4579 pmd_clear(pmd_off_k(addr));
4580@@ -1239,7 +1325,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4581 * location (0xffff0000). If we aren't using high-vectors, also
4582 * create a mapping at the low-vectors virtual address.
4583 */
4584- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4585+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4586 map.virtual = 0xffff0000;
4587 map.length = PAGE_SIZE;
4588 #ifdef CONFIG_KUSER_HELPERS
4589@@ -1311,8 +1397,39 @@ static void __init map_lowmem(void)
4590 map.pfn = __phys_to_pfn(start);
4591 map.virtual = __phys_to_virt(start);
4592 map.length = end - start;
4593- map.type = MT_MEMORY;
4594
4595+#ifdef CONFIG_PAX_KERNEXEC
4596+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4597+ struct map_desc kernel;
4598+ struct map_desc initmap;
4599+
4600+ /* when freeing initmem we will make this RW */
4601+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4602+ initmap.virtual = (unsigned long)__init_begin;
4603+ initmap.length = _sdata - __init_begin;
4604+ initmap.type = MT_MEMORY_RWX;
4605+ create_mapping(&initmap);
4606+
4607+ /* when freeing initmem we will make this RX */
4608+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4609+ kernel.virtual = (unsigned long)_stext;
4610+ kernel.length = __init_begin - _stext;
4611+ kernel.type = MT_MEMORY_RWX;
4612+ create_mapping(&kernel);
4613+
4614+ if (map.virtual < (unsigned long)_stext) {
4615+ map.length = (unsigned long)_stext - map.virtual;
4616+ map.type = MT_MEMORY_RWX;
4617+ create_mapping(&map);
4618+ }
4619+
4620+ map.pfn = __phys_to_pfn(__pa(_sdata));
4621+ map.virtual = (unsigned long)_sdata;
4622+ map.length = end - __pa(_sdata);
4623+ }
4624+#endif
4625+
4626+ map.type = MT_MEMORY_RW;
4627 create_mapping(&map);
4628 }
4629 }
4630diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4631index a5bc92d..0bb4730 100644
4632--- a/arch/arm/plat-omap/sram.c
4633+++ b/arch/arm/plat-omap/sram.c
4634@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4635 * Looks like we need to preserve some bootloader code at the
4636 * beginning of SRAM for jumping to flash for reboot to work...
4637 */
4638+ pax_open_kernel();
4639 memset_io(omap_sram_base + omap_sram_skip, 0,
4640 omap_sram_size - omap_sram_skip);
4641+ pax_close_kernel();
4642 }
4643diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4644index ce6d763..cfea917 100644
4645--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4646+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4647@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4648 int (*started)(unsigned ch);
4649 int (*flush)(unsigned ch);
4650 int (*stop)(unsigned ch);
4651-};
4652+} __no_const;
4653
4654 extern void *samsung_dmadev_get_ops(void);
4655 extern void *s3c_dma_get_ops(void);
4656diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4657index c3a58a1..78fbf54 100644
4658--- a/arch/avr32/include/asm/cache.h
4659+++ b/arch/avr32/include/asm/cache.h
4660@@ -1,8 +1,10 @@
4661 #ifndef __ASM_AVR32_CACHE_H
4662 #define __ASM_AVR32_CACHE_H
4663
4664+#include <linux/const.h>
4665+
4666 #define L1_CACHE_SHIFT 5
4667-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4668+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4669
4670 /*
4671 * Memory returned by kmalloc() may be used for DMA, so we must make
4672diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4673index d232888..87c8df1 100644
4674--- a/arch/avr32/include/asm/elf.h
4675+++ b/arch/avr32/include/asm/elf.h
4676@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4677 the loader. We need to make sure that it is out of the way of the program
4678 that it will "exec", and that there is sufficient room for the brk. */
4679
4680-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4681+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4682
4683+#ifdef CONFIG_PAX_ASLR
4684+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4685+
4686+#define PAX_DELTA_MMAP_LEN 15
4687+#define PAX_DELTA_STACK_LEN 15
4688+#endif
4689
4690 /* This yields a mask that user programs can use to figure out what
4691 instruction set this CPU supports. This could be done in user space,
4692diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4693index 479330b..53717a8 100644
4694--- a/arch/avr32/include/asm/kmap_types.h
4695+++ b/arch/avr32/include/asm/kmap_types.h
4696@@ -2,9 +2,9 @@
4697 #define __ASM_AVR32_KMAP_TYPES_H
4698
4699 #ifdef CONFIG_DEBUG_HIGHMEM
4700-# define KM_TYPE_NR 29
4701+# define KM_TYPE_NR 30
4702 #else
4703-# define KM_TYPE_NR 14
4704+# define KM_TYPE_NR 15
4705 #endif
4706
4707 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4708diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4709index 0eca933..eb78c7b 100644
4710--- a/arch/avr32/mm/fault.c
4711+++ b/arch/avr32/mm/fault.c
4712@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4713
4714 int exception_trace = 1;
4715
4716+#ifdef CONFIG_PAX_PAGEEXEC
4717+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4718+{
4719+ unsigned long i;
4720+
4721+ printk(KERN_ERR "PAX: bytes at PC: ");
4722+ for (i = 0; i < 20; i++) {
4723+ unsigned char c;
4724+ if (get_user(c, (unsigned char *)pc+i))
4725+ printk(KERN_CONT "???????? ");
4726+ else
4727+ printk(KERN_CONT "%02x ", c);
4728+ }
4729+ printk("\n");
4730+}
4731+#endif
4732+
4733 /*
4734 * This routine handles page faults. It determines the address and the
4735 * problem, and then passes it off to one of the appropriate routines.
4736@@ -176,6 +193,16 @@ bad_area:
4737 up_read(&mm->mmap_sem);
4738
4739 if (user_mode(regs)) {
4740+
4741+#ifdef CONFIG_PAX_PAGEEXEC
4742+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4743+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4744+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4745+ do_group_exit(SIGKILL);
4746+ }
4747+ }
4748+#endif
4749+
4750 if (exception_trace && printk_ratelimit())
4751 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4752 "sp %08lx ecr %lu\n",
4753diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4754index 568885a..f8008df 100644
4755--- a/arch/blackfin/include/asm/cache.h
4756+++ b/arch/blackfin/include/asm/cache.h
4757@@ -7,6 +7,7 @@
4758 #ifndef __ARCH_BLACKFIN_CACHE_H
4759 #define __ARCH_BLACKFIN_CACHE_H
4760
4761+#include <linux/const.h>
4762 #include <linux/linkage.h> /* for asmlinkage */
4763
4764 /*
4765@@ -14,7 +15,7 @@
4766 * Blackfin loads 32 bytes for cache
4767 */
4768 #define L1_CACHE_SHIFT 5
4769-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4770+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4771 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4772
4773 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4774diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4775index aea2718..3639a60 100644
4776--- a/arch/cris/include/arch-v10/arch/cache.h
4777+++ b/arch/cris/include/arch-v10/arch/cache.h
4778@@ -1,8 +1,9 @@
4779 #ifndef _ASM_ARCH_CACHE_H
4780 #define _ASM_ARCH_CACHE_H
4781
4782+#include <linux/const.h>
4783 /* Etrax 100LX have 32-byte cache-lines. */
4784-#define L1_CACHE_BYTES 32
4785 #define L1_CACHE_SHIFT 5
4786+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4787
4788 #endif /* _ASM_ARCH_CACHE_H */
4789diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4790index 7caf25d..ee65ac5 100644
4791--- a/arch/cris/include/arch-v32/arch/cache.h
4792+++ b/arch/cris/include/arch-v32/arch/cache.h
4793@@ -1,11 +1,12 @@
4794 #ifndef _ASM_CRIS_ARCH_CACHE_H
4795 #define _ASM_CRIS_ARCH_CACHE_H
4796
4797+#include <linux/const.h>
4798 #include <arch/hwregs/dma.h>
4799
4800 /* A cache-line is 32 bytes. */
4801-#define L1_CACHE_BYTES 32
4802 #define L1_CACHE_SHIFT 5
4803+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4804
4805 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4806
4807diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4808index b86329d..6709906 100644
4809--- a/arch/frv/include/asm/atomic.h
4810+++ b/arch/frv/include/asm/atomic.h
4811@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4812 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4813 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4814
4815+#define atomic64_read_unchecked(v) atomic64_read(v)
4816+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4817+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4818+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4819+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4820+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4821+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4822+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4823+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4824+
4825 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4826 {
4827 int c, old;
4828diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4829index 2797163..c2a401d 100644
4830--- a/arch/frv/include/asm/cache.h
4831+++ b/arch/frv/include/asm/cache.h
4832@@ -12,10 +12,11 @@
4833 #ifndef __ASM_CACHE_H
4834 #define __ASM_CACHE_H
4835
4836+#include <linux/const.h>
4837
4838 /* bytes per L1 cache line */
4839 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4840-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4841+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4842
4843 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4844 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4845diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4846index 43901f2..0d8b865 100644
4847--- a/arch/frv/include/asm/kmap_types.h
4848+++ b/arch/frv/include/asm/kmap_types.h
4849@@ -2,6 +2,6 @@
4850 #ifndef _ASM_KMAP_TYPES_H
4851 #define _ASM_KMAP_TYPES_H
4852
4853-#define KM_TYPE_NR 17
4854+#define KM_TYPE_NR 18
4855
4856 #endif
4857diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4858index 836f147..4cf23f5 100644
4859--- a/arch/frv/mm/elf-fdpic.c
4860+++ b/arch/frv/mm/elf-fdpic.c
4861@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4862 {
4863 struct vm_area_struct *vma;
4864 struct vm_unmapped_area_info info;
4865+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4866
4867 if (len > TASK_SIZE)
4868 return -ENOMEM;
4869@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4870 if (addr) {
4871 addr = PAGE_ALIGN(addr);
4872 vma = find_vma(current->mm, addr);
4873- if (TASK_SIZE - len >= addr &&
4874- (!vma || addr + len <= vma->vm_start))
4875+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4876 goto success;
4877 }
4878
4879@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4880 info.high_limit = (current->mm->start_stack - 0x00200000);
4881 info.align_mask = 0;
4882 info.align_offset = 0;
4883+ info.threadstack_offset = offset;
4884 addr = vm_unmapped_area(&info);
4885 if (!(addr & ~PAGE_MASK))
4886 goto success;
4887diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4888index f4ca594..adc72fd6 100644
4889--- a/arch/hexagon/include/asm/cache.h
4890+++ b/arch/hexagon/include/asm/cache.h
4891@@ -21,9 +21,11 @@
4892 #ifndef __ASM_CACHE_H
4893 #define __ASM_CACHE_H
4894
4895+#include <linux/const.h>
4896+
4897 /* Bytes per L1 cache line */
4898-#define L1_CACHE_SHIFT (5)
4899-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4900+#define L1_CACHE_SHIFT 5
4901+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4902
4903 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4904 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4905diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
4906index 4e4119b..dd7de0a 100644
4907--- a/arch/ia64/Kconfig
4908+++ b/arch/ia64/Kconfig
4909@@ -554,6 +554,7 @@ source "drivers/sn/Kconfig"
4910 config KEXEC
4911 bool "kexec system call"
4912 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
4913+ depends on !GRKERNSEC_KMEM
4914 help
4915 kexec is a system call that implements the ability to shutdown your
4916 current kernel, and to start another kernel. It is like a reboot
4917diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4918index 6e6fe18..a6ae668 100644
4919--- a/arch/ia64/include/asm/atomic.h
4920+++ b/arch/ia64/include/asm/atomic.h
4921@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4922 #define atomic64_inc(v) atomic64_add(1, (v))
4923 #define atomic64_dec(v) atomic64_sub(1, (v))
4924
4925+#define atomic64_read_unchecked(v) atomic64_read(v)
4926+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4927+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4928+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4929+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4930+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4931+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4932+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4933+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4934+
4935 /* Atomic operations are already serializing */
4936 #define smp_mb__before_atomic_dec() barrier()
4937 #define smp_mb__after_atomic_dec() barrier()
4938diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4939index 988254a..e1ee885 100644
4940--- a/arch/ia64/include/asm/cache.h
4941+++ b/arch/ia64/include/asm/cache.h
4942@@ -1,6 +1,7 @@
4943 #ifndef _ASM_IA64_CACHE_H
4944 #define _ASM_IA64_CACHE_H
4945
4946+#include <linux/const.h>
4947
4948 /*
4949 * Copyright (C) 1998-2000 Hewlett-Packard Co
4950@@ -9,7 +10,7 @@
4951
4952 /* Bytes per L1 (data) cache line. */
4953 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4954-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4955+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4956
4957 #ifdef CONFIG_SMP
4958 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4959diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4960index 5a83c5c..4d7f553 100644
4961--- a/arch/ia64/include/asm/elf.h
4962+++ b/arch/ia64/include/asm/elf.h
4963@@ -42,6 +42,13 @@
4964 */
4965 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4966
4967+#ifdef CONFIG_PAX_ASLR
4968+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4969+
4970+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4971+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4972+#endif
4973+
4974 #define PT_IA_64_UNWIND 0x70000001
4975
4976 /* IA-64 relocations: */
4977diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4978index 5767cdf..7462574 100644
4979--- a/arch/ia64/include/asm/pgalloc.h
4980+++ b/arch/ia64/include/asm/pgalloc.h
4981@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4982 pgd_val(*pgd_entry) = __pa(pud);
4983 }
4984
4985+static inline void
4986+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4987+{
4988+ pgd_populate(mm, pgd_entry, pud);
4989+}
4990+
4991 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4992 {
4993 return quicklist_alloc(0, GFP_KERNEL, NULL);
4994@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4995 pud_val(*pud_entry) = __pa(pmd);
4996 }
4997
4998+static inline void
4999+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5000+{
5001+ pud_populate(mm, pud_entry, pmd);
5002+}
5003+
5004 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5005 {
5006 return quicklist_alloc(0, GFP_KERNEL, NULL);
5007diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5008index 7935115..c0eca6a 100644
5009--- a/arch/ia64/include/asm/pgtable.h
5010+++ b/arch/ia64/include/asm/pgtable.h
5011@@ -12,7 +12,7 @@
5012 * David Mosberger-Tang <davidm@hpl.hp.com>
5013 */
5014
5015-
5016+#include <linux/const.h>
5017 #include <asm/mman.h>
5018 #include <asm/page.h>
5019 #include <asm/processor.h>
5020@@ -142,6 +142,17 @@
5021 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5022 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5023 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5024+
5025+#ifdef CONFIG_PAX_PAGEEXEC
5026+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5027+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5028+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5029+#else
5030+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5031+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5032+# define PAGE_COPY_NOEXEC PAGE_COPY
5033+#endif
5034+
5035 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5036 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5037 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5038diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5039index 45698cd..e8e2dbc 100644
5040--- a/arch/ia64/include/asm/spinlock.h
5041+++ b/arch/ia64/include/asm/spinlock.h
5042@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5043 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5044
5045 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5046- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5047+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5048 }
5049
5050 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5051diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5052index 449c8c0..18965fb 100644
5053--- a/arch/ia64/include/asm/uaccess.h
5054+++ b/arch/ia64/include/asm/uaccess.h
5055@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5056 static inline unsigned long
5057 __copy_to_user (void __user *to, const void *from, unsigned long count)
5058 {
5059+ if (count > INT_MAX)
5060+ return count;
5061+
5062+ if (!__builtin_constant_p(count))
5063+ check_object_size(from, count, true);
5064+
5065 return __copy_user(to, (__force void __user *) from, count);
5066 }
5067
5068 static inline unsigned long
5069 __copy_from_user (void *to, const void __user *from, unsigned long count)
5070 {
5071+ if (count > INT_MAX)
5072+ return count;
5073+
5074+ if (!__builtin_constant_p(count))
5075+ check_object_size(to, count, false);
5076+
5077 return __copy_user((__force void __user *) to, from, count);
5078 }
5079
5080@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5081 ({ \
5082 void __user *__cu_to = (to); \
5083 const void *__cu_from = (from); \
5084- long __cu_len = (n); \
5085+ unsigned long __cu_len = (n); \
5086 \
5087- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5088+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5089+ if (!__builtin_constant_p(n)) \
5090+ check_object_size(__cu_from, __cu_len, true); \
5091 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5092+ } \
5093 __cu_len; \
5094 })
5095
5096@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5097 ({ \
5098 void *__cu_to = (to); \
5099 const void __user *__cu_from = (from); \
5100- long __cu_len = (n); \
5101+ unsigned long __cu_len = (n); \
5102 \
5103 __chk_user_ptr(__cu_from); \
5104- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5105+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5106+ if (!__builtin_constant_p(n)) \
5107+ check_object_size(__cu_to, __cu_len, false); \
5108 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5109+ } \
5110 __cu_len; \
5111 })
5112
5113diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5114index 24603be..948052d 100644
5115--- a/arch/ia64/kernel/module.c
5116+++ b/arch/ia64/kernel/module.c
5117@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5118 void
5119 module_free (struct module *mod, void *module_region)
5120 {
5121- if (mod && mod->arch.init_unw_table &&
5122- module_region == mod->module_init) {
5123+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5124 unw_remove_unwind_table(mod->arch.init_unw_table);
5125 mod->arch.init_unw_table = NULL;
5126 }
5127@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5128 }
5129
5130 static inline int
5131+in_init_rx (const struct module *mod, uint64_t addr)
5132+{
5133+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5134+}
5135+
5136+static inline int
5137+in_init_rw (const struct module *mod, uint64_t addr)
5138+{
5139+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5140+}
5141+
5142+static inline int
5143 in_init (const struct module *mod, uint64_t addr)
5144 {
5145- return addr - (uint64_t) mod->module_init < mod->init_size;
5146+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5147+}
5148+
5149+static inline int
5150+in_core_rx (const struct module *mod, uint64_t addr)
5151+{
5152+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5153+}
5154+
5155+static inline int
5156+in_core_rw (const struct module *mod, uint64_t addr)
5157+{
5158+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5159 }
5160
5161 static inline int
5162 in_core (const struct module *mod, uint64_t addr)
5163 {
5164- return addr - (uint64_t) mod->module_core < mod->core_size;
5165+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5166 }
5167
5168 static inline int
5169@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5170 break;
5171
5172 case RV_BDREL:
5173- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5174+ if (in_init_rx(mod, val))
5175+ val -= (uint64_t) mod->module_init_rx;
5176+ else if (in_init_rw(mod, val))
5177+ val -= (uint64_t) mod->module_init_rw;
5178+ else if (in_core_rx(mod, val))
5179+ val -= (uint64_t) mod->module_core_rx;
5180+ else if (in_core_rw(mod, val))
5181+ val -= (uint64_t) mod->module_core_rw;
5182 break;
5183
5184 case RV_LTV:
5185@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5186 * addresses have been selected...
5187 */
5188 uint64_t gp;
5189- if (mod->core_size > MAX_LTOFF)
5190+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5191 /*
5192 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5193 * at the end of the module.
5194 */
5195- gp = mod->core_size - MAX_LTOFF / 2;
5196+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5197 else
5198- gp = mod->core_size / 2;
5199- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5200+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5201+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5202 mod->arch.gp = gp;
5203 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5204 }
5205diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5206index ab33328..f39506c 100644
5207--- a/arch/ia64/kernel/palinfo.c
5208+++ b/arch/ia64/kernel/palinfo.c
5209@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5210 return NOTIFY_OK;
5211 }
5212
5213-static struct notifier_block __refdata palinfo_cpu_notifier =
5214+static struct notifier_block palinfo_cpu_notifier =
5215 {
5216 .notifier_call = palinfo_cpu_callback,
5217 .priority = 0,
5218diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5219index 41e33f8..65180b2a 100644
5220--- a/arch/ia64/kernel/sys_ia64.c
5221+++ b/arch/ia64/kernel/sys_ia64.c
5222@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5223 unsigned long align_mask = 0;
5224 struct mm_struct *mm = current->mm;
5225 struct vm_unmapped_area_info info;
5226+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5227
5228 if (len > RGN_MAP_LIMIT)
5229 return -ENOMEM;
5230@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5231 if (REGION_NUMBER(addr) == RGN_HPAGE)
5232 addr = 0;
5233 #endif
5234+
5235+#ifdef CONFIG_PAX_RANDMMAP
5236+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5237+ addr = mm->free_area_cache;
5238+ else
5239+#endif
5240+
5241 if (!addr)
5242 addr = TASK_UNMAPPED_BASE;
5243
5244@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5245 info.high_limit = TASK_SIZE;
5246 info.align_mask = align_mask;
5247 info.align_offset = 0;
5248+ info.threadstack_offset = offset;
5249 return vm_unmapped_area(&info);
5250 }
5251
5252diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5253index 0ccb28f..8992469 100644
5254--- a/arch/ia64/kernel/vmlinux.lds.S
5255+++ b/arch/ia64/kernel/vmlinux.lds.S
5256@@ -198,7 +198,7 @@ SECTIONS {
5257 /* Per-cpu data: */
5258 . = ALIGN(PERCPU_PAGE_SIZE);
5259 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5260- __phys_per_cpu_start = __per_cpu_load;
5261+ __phys_per_cpu_start = per_cpu_load;
5262 /*
5263 * ensure percpu data fits
5264 * into percpu page size
5265diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5266index 7225dad..2a7c8256 100644
5267--- a/arch/ia64/mm/fault.c
5268+++ b/arch/ia64/mm/fault.c
5269@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5270 return pte_present(pte);
5271 }
5272
5273+#ifdef CONFIG_PAX_PAGEEXEC
5274+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5275+{
5276+ unsigned long i;
5277+
5278+ printk(KERN_ERR "PAX: bytes at PC: ");
5279+ for (i = 0; i < 8; i++) {
5280+ unsigned int c;
5281+ if (get_user(c, (unsigned int *)pc+i))
5282+ printk(KERN_CONT "???????? ");
5283+ else
5284+ printk(KERN_CONT "%08x ", c);
5285+ }
5286+ printk("\n");
5287+}
5288+#endif
5289+
5290 # define VM_READ_BIT 0
5291 # define VM_WRITE_BIT 1
5292 # define VM_EXEC_BIT 2
5293@@ -151,8 +168,21 @@ retry:
5294 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5295 goto bad_area;
5296
5297- if ((vma->vm_flags & mask) != mask)
5298+ if ((vma->vm_flags & mask) != mask) {
5299+
5300+#ifdef CONFIG_PAX_PAGEEXEC
5301+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5302+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5303+ goto bad_area;
5304+
5305+ up_read(&mm->mmap_sem);
5306+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5307+ do_group_exit(SIGKILL);
5308+ }
5309+#endif
5310+
5311 goto bad_area;
5312+ }
5313
5314 /*
5315 * If for any reason at all we couldn't handle the fault, make
5316diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5317index 68232db..6ca80af 100644
5318--- a/arch/ia64/mm/hugetlbpage.c
5319+++ b/arch/ia64/mm/hugetlbpage.c
5320@@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5321 unsigned long pgoff, unsigned long flags)
5322 {
5323 struct vm_unmapped_area_info info;
5324+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5325
5326 if (len > RGN_MAP_LIMIT)
5327 return -ENOMEM;
5328@@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5329 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5330 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5331 info.align_offset = 0;
5332+ info.threadstack_offset = offset;
5333 return vm_unmapped_area(&info);
5334 }
5335
5336diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5337index 88504ab..cbb6c9f 100644
5338--- a/arch/ia64/mm/init.c
5339+++ b/arch/ia64/mm/init.c
5340@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5341 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5342 vma->vm_end = vma->vm_start + PAGE_SIZE;
5343 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5344+
5345+#ifdef CONFIG_PAX_PAGEEXEC
5346+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5347+ vma->vm_flags &= ~VM_EXEC;
5348+
5349+#ifdef CONFIG_PAX_MPROTECT
5350+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5351+ vma->vm_flags &= ~VM_MAYEXEC;
5352+#endif
5353+
5354+ }
5355+#endif
5356+
5357 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5358 down_write(&current->mm->mmap_sem);
5359 if (insert_vm_struct(current->mm, vma)) {
5360diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5361index 40b3ee9..8c2c112 100644
5362--- a/arch/m32r/include/asm/cache.h
5363+++ b/arch/m32r/include/asm/cache.h
5364@@ -1,8 +1,10 @@
5365 #ifndef _ASM_M32R_CACHE_H
5366 #define _ASM_M32R_CACHE_H
5367
5368+#include <linux/const.h>
5369+
5370 /* L1 cache line size */
5371 #define L1_CACHE_SHIFT 4
5372-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5373+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5374
5375 #endif /* _ASM_M32R_CACHE_H */
5376diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5377index 82abd15..d95ae5d 100644
5378--- a/arch/m32r/lib/usercopy.c
5379+++ b/arch/m32r/lib/usercopy.c
5380@@ -14,6 +14,9 @@
5381 unsigned long
5382 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5383 {
5384+ if ((long)n < 0)
5385+ return n;
5386+
5387 prefetch(from);
5388 if (access_ok(VERIFY_WRITE, to, n))
5389 __copy_user(to,from,n);
5390@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5391 unsigned long
5392 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5393 {
5394+ if ((long)n < 0)
5395+ return n;
5396+
5397 prefetchw(to);
5398 if (access_ok(VERIFY_READ, from, n))
5399 __copy_user_zeroing(to,from,n);
5400diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5401index 0395c51..5f26031 100644
5402--- a/arch/m68k/include/asm/cache.h
5403+++ b/arch/m68k/include/asm/cache.h
5404@@ -4,9 +4,11 @@
5405 #ifndef __ARCH_M68K_CACHE_H
5406 #define __ARCH_M68K_CACHE_H
5407
5408+#include <linux/const.h>
5409+
5410 /* bytes per L1 cache line */
5411 #define L1_CACHE_SHIFT 4
5412-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5413+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5414
5415 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5416
5417diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5418index 0424315..defcca9 100644
5419--- a/arch/metag/mm/hugetlbpage.c
5420+++ b/arch/metag/mm/hugetlbpage.c
5421@@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5422 info.high_limit = TASK_SIZE;
5423 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5424 info.align_offset = 0;
5425+ info.threadstack_offset = 0;
5426 return vm_unmapped_area(&info);
5427 }
5428
5429diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5430index 4efe96a..60e8699 100644
5431--- a/arch/microblaze/include/asm/cache.h
5432+++ b/arch/microblaze/include/asm/cache.h
5433@@ -13,11 +13,12 @@
5434 #ifndef _ASM_MICROBLAZE_CACHE_H
5435 #define _ASM_MICROBLAZE_CACHE_H
5436
5437+#include <linux/const.h>
5438 #include <asm/registers.h>
5439
5440 #define L1_CACHE_SHIFT 5
5441 /* word-granular cache in microblaze */
5442-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5443+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5444
5445 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5446
5447diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5448index 650de39..6982b02 100644
5449--- a/arch/mips/Kconfig
5450+++ b/arch/mips/Kconfig
5451@@ -2268,6 +2268,7 @@ source "kernel/Kconfig.preempt"
5452
5453 config KEXEC
5454 bool "Kexec system call"
5455+ depends on !GRKERNSEC_KMEM
5456 help
5457 kexec is a system call that implements the ability to shutdown your
5458 current kernel, and to start another kernel. It is like a reboot
5459diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5460index 7eed2f2..c4e385d 100644
5461--- a/arch/mips/include/asm/atomic.h
5462+++ b/arch/mips/include/asm/atomic.h
5463@@ -21,15 +21,39 @@
5464 #include <asm/cmpxchg.h>
5465 #include <asm/war.h>
5466
5467+#ifdef CONFIG_GENERIC_ATOMIC64
5468+#include <asm-generic/atomic64.h>
5469+#endif
5470+
5471 #define ATOMIC_INIT(i) { (i) }
5472
5473+#ifdef CONFIG_64BIT
5474+#define _ASM_EXTABLE(from, to) \
5475+" .section __ex_table,\"a\"\n" \
5476+" .dword " #from ", " #to"\n" \
5477+" .previous\n"
5478+#else
5479+#define _ASM_EXTABLE(from, to) \
5480+" .section __ex_table,\"a\"\n" \
5481+" .word " #from ", " #to"\n" \
5482+" .previous\n"
5483+#endif
5484+
5485 /*
5486 * atomic_read - read atomic variable
5487 * @v: pointer of type atomic_t
5488 *
5489 * Atomically reads the value of @v.
5490 */
5491-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5492+static inline int atomic_read(const atomic_t *v)
5493+{
5494+ return (*(volatile const int *) &v->counter);
5495+}
5496+
5497+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5498+{
5499+ return (*(volatile const int *) &v->counter);
5500+}
5501
5502 /*
5503 * atomic_set - set atomic variable
5504@@ -38,7 +62,15 @@
5505 *
5506 * Atomically sets the value of @v to @i.
5507 */
5508-#define atomic_set(v, i) ((v)->counter = (i))
5509+static inline void atomic_set(atomic_t *v, int i)
5510+{
5511+ v->counter = i;
5512+}
5513+
5514+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5515+{
5516+ v->counter = i;
5517+}
5518
5519 /*
5520 * atomic_add - add integer to atomic variable
5521@@ -47,7 +79,67 @@
5522 *
5523 * Atomically adds @i to @v.
5524 */
5525-static __inline__ void atomic_add(int i, atomic_t * v)
5526+static __inline__ void atomic_add(int i, atomic_t *v)
5527+{
5528+ int temp;
5529+
5530+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5531+ __asm__ __volatile__(
5532+ " .set mips3 \n"
5533+ "1: ll %0, %1 # atomic_add \n"
5534+#ifdef CONFIG_PAX_REFCOUNT
5535+ /* Exception on overflow. */
5536+ "2: add %0, %2 \n"
5537+#else
5538+ " addu %0, %2 \n"
5539+#endif
5540+ " sc %0, %1 \n"
5541+ " beqzl %0, 1b \n"
5542+#ifdef CONFIG_PAX_REFCOUNT
5543+ "3: \n"
5544+ _ASM_EXTABLE(2b, 3b)
5545+#endif
5546+ " .set mips0 \n"
5547+ : "=&r" (temp), "+m" (v->counter)
5548+ : "Ir" (i));
5549+ } else if (kernel_uses_llsc) {
5550+ __asm__ __volatile__(
5551+ " .set mips3 \n"
5552+ "1: ll %0, %1 # atomic_add \n"
5553+#ifdef CONFIG_PAX_REFCOUNT
5554+ /* Exception on overflow. */
5555+ "2: add %0, %2 \n"
5556+#else
5557+ " addu %0, %2 \n"
5558+#endif
5559+ " sc %0, %1 \n"
5560+ " beqz %0, 1b \n"
5561+#ifdef CONFIG_PAX_REFCOUNT
5562+ "3: \n"
5563+ _ASM_EXTABLE(2b, 3b)
5564+#endif
5565+ " .set mips0 \n"
5566+ : "=&r" (temp), "+m" (v->counter)
5567+ : "Ir" (i));
5568+ } else {
5569+ unsigned long flags;
5570+
5571+ raw_local_irq_save(flags);
5572+ __asm__ __volatile__(
5573+#ifdef CONFIG_PAX_REFCOUNT
5574+ /* Exception on overflow. */
5575+ "1: add %0, %1 \n"
5576+ "2: \n"
5577+ _ASM_EXTABLE(1b, 2b)
5578+#else
5579+ " addu %0, %1 \n"
5580+#endif
5581+ : "+r" (v->counter) : "Ir" (i));
5582+ raw_local_irq_restore(flags);
5583+ }
5584+}
5585+
5586+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5587 {
5588 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5589 int temp;
5590@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5591 *
5592 * Atomically subtracts @i from @v.
5593 */
5594-static __inline__ void atomic_sub(int i, atomic_t * v)
5595+static __inline__ void atomic_sub(int i, atomic_t *v)
5596+{
5597+ int temp;
5598+
5599+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5600+ __asm__ __volatile__(
5601+ " .set mips3 \n"
5602+ "1: ll %0, %1 # atomic64_sub \n"
5603+#ifdef CONFIG_PAX_REFCOUNT
5604+ /* Exception on overflow. */
5605+ "2: sub %0, %2 \n"
5606+#else
5607+ " subu %0, %2 \n"
5608+#endif
5609+ " sc %0, %1 \n"
5610+ " beqzl %0, 1b \n"
5611+#ifdef CONFIG_PAX_REFCOUNT
5612+ "3: \n"
5613+ _ASM_EXTABLE(2b, 3b)
5614+#endif
5615+ " .set mips0 \n"
5616+ : "=&r" (temp), "+m" (v->counter)
5617+ : "Ir" (i));
5618+ } else if (kernel_uses_llsc) {
5619+ __asm__ __volatile__(
5620+ " .set mips3 \n"
5621+ "1: ll %0, %1 # atomic64_sub \n"
5622+#ifdef CONFIG_PAX_REFCOUNT
5623+ /* Exception on overflow. */
5624+ "2: sub %0, %2 \n"
5625+#else
5626+ " subu %0, %2 \n"
5627+#endif
5628+ " sc %0, %1 \n"
5629+ " beqz %0, 1b \n"
5630+#ifdef CONFIG_PAX_REFCOUNT
5631+ "3: \n"
5632+ _ASM_EXTABLE(2b, 3b)
5633+#endif
5634+ " .set mips0 \n"
5635+ : "=&r" (temp), "+m" (v->counter)
5636+ : "Ir" (i));
5637+ } else {
5638+ unsigned long flags;
5639+
5640+ raw_local_irq_save(flags);
5641+ __asm__ __volatile__(
5642+#ifdef CONFIG_PAX_REFCOUNT
5643+ /* Exception on overflow. */
5644+ "1: sub %0, %1 \n"
5645+ "2: \n"
5646+ _ASM_EXTABLE(1b, 2b)
5647+#else
5648+ " subu %0, %1 \n"
5649+#endif
5650+ : "+r" (v->counter) : "Ir" (i));
5651+ raw_local_irq_restore(flags);
5652+ }
5653+}
5654+
5655+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5656 {
5657 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5658 int temp;
5659@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5660 /*
5661 * Same as above, but return the result value
5662 */
5663-static __inline__ int atomic_add_return(int i, atomic_t * v)
5664+static __inline__ int atomic_add_return(int i, atomic_t *v)
5665+{
5666+ int result;
5667+ int temp;
5668+
5669+ smp_mb__before_llsc();
5670+
5671+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5672+ __asm__ __volatile__(
5673+ " .set mips3 \n"
5674+ "1: ll %1, %2 # atomic_add_return \n"
5675+#ifdef CONFIG_PAX_REFCOUNT
5676+ "2: add %0, %1, %3 \n"
5677+#else
5678+ " addu %0, %1, %3 \n"
5679+#endif
5680+ " sc %0, %2 \n"
5681+ " beqzl %0, 1b \n"
5682+#ifdef CONFIG_PAX_REFCOUNT
5683+ " b 4f \n"
5684+ " .set noreorder \n"
5685+ "3: b 5f \n"
5686+ " move %0, %1 \n"
5687+ " .set reorder \n"
5688+ _ASM_EXTABLE(2b, 3b)
5689+#endif
5690+ "4: addu %0, %1, %3 \n"
5691+#ifdef CONFIG_PAX_REFCOUNT
5692+ "5: \n"
5693+#endif
5694+ " .set mips0 \n"
5695+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5696+ : "Ir" (i));
5697+ } else if (kernel_uses_llsc) {
5698+ __asm__ __volatile__(
5699+ " .set mips3 \n"
5700+ "1: ll %1, %2 # atomic_add_return \n"
5701+#ifdef CONFIG_PAX_REFCOUNT
5702+ "2: add %0, %1, %3 \n"
5703+#else
5704+ " addu %0, %1, %3 \n"
5705+#endif
5706+ " sc %0, %2 \n"
5707+ " bnez %0, 4f \n"
5708+ " b 1b \n"
5709+#ifdef CONFIG_PAX_REFCOUNT
5710+ " .set noreorder \n"
5711+ "3: b 5f \n"
5712+ " move %0, %1 \n"
5713+ " .set reorder \n"
5714+ _ASM_EXTABLE(2b, 3b)
5715+#endif
5716+ "4: addu %0, %1, %3 \n"
5717+#ifdef CONFIG_PAX_REFCOUNT
5718+ "5: \n"
5719+#endif
5720+ " .set mips0 \n"
5721+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5722+ : "Ir" (i));
5723+ } else {
5724+ unsigned long flags;
5725+
5726+ raw_local_irq_save(flags);
5727+ __asm__ __volatile__(
5728+ " lw %0, %1 \n"
5729+#ifdef CONFIG_PAX_REFCOUNT
5730+ /* Exception on overflow. */
5731+ "1: add %0, %2 \n"
5732+#else
5733+ " addu %0, %2 \n"
5734+#endif
5735+ " sw %0, %1 \n"
5736+#ifdef CONFIG_PAX_REFCOUNT
5737+ /* Note: Dest reg is not modified on overflow */
5738+ "2: \n"
5739+ _ASM_EXTABLE(1b, 2b)
5740+#endif
5741+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5742+ raw_local_irq_restore(flags);
5743+ }
5744+
5745+ smp_llsc_mb();
5746+
5747+ return result;
5748+}
5749+
5750+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5751 {
5752 int result;
5753
5754@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5755 return result;
5756 }
5757
5758-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5759+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5760+{
5761+ int result;
5762+ int temp;
5763+
5764+ smp_mb__before_llsc();
5765+
5766+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5767+ __asm__ __volatile__(
5768+ " .set mips3 \n"
5769+ "1: ll %1, %2 # atomic_sub_return \n"
5770+#ifdef CONFIG_PAX_REFCOUNT
5771+ "2: sub %0, %1, %3 \n"
5772+#else
5773+ " subu %0, %1, %3 \n"
5774+#endif
5775+ " sc %0, %2 \n"
5776+ " beqzl %0, 1b \n"
5777+#ifdef CONFIG_PAX_REFCOUNT
5778+ " b 4f \n"
5779+ " .set noreorder \n"
5780+ "3: b 5f \n"
5781+ " move %0, %1 \n"
5782+ " .set reorder \n"
5783+ _ASM_EXTABLE(2b, 3b)
5784+#endif
5785+ "4: subu %0, %1, %3 \n"
5786+#ifdef CONFIG_PAX_REFCOUNT
5787+ "5: \n"
5788+#endif
5789+ " .set mips0 \n"
5790+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5791+ : "Ir" (i), "m" (v->counter)
5792+ : "memory");
5793+ } else if (kernel_uses_llsc) {
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+ " bnez %0, 4f \n"
5804+ " b 1b \n"
5805+#ifdef CONFIG_PAX_REFCOUNT
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));
5819+ } else {
5820+ unsigned long flags;
5821+
5822+ raw_local_irq_save(flags);
5823+ __asm__ __volatile__(
5824+ " lw %0, %1 \n"
5825+#ifdef CONFIG_PAX_REFCOUNT
5826+ /* Exception on overflow. */
5827+ "1: sub %0, %2 \n"
5828+#else
5829+ " subu %0, %2 \n"
5830+#endif
5831+ " sw %0, %1 \n"
5832+#ifdef CONFIG_PAX_REFCOUNT
5833+ /* Note: Dest reg is not modified on overflow */
5834+ "2: \n"
5835+ _ASM_EXTABLE(1b, 2b)
5836+#endif
5837+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5838+ raw_local_irq_restore(flags);
5839+ }
5840+
5841+ smp_llsc_mb();
5842+
5843+ return result;
5844+}
5845+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5846 {
5847 int result;
5848
5849@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5850 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5851 * The function returns the old value of @v minus @i.
5852 */
5853-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5854+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5855 {
5856 int result;
5857
5858@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5859 return result;
5860 }
5861
5862-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5863-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5864+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5865+{
5866+ return cmpxchg(&v->counter, old, new);
5867+}
5868+
5869+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5870+ int new)
5871+{
5872+ return cmpxchg(&(v->counter), old, new);
5873+}
5874+
5875+static inline int atomic_xchg(atomic_t *v, int new)
5876+{
5877+ return xchg(&v->counter, new);
5878+}
5879+
5880+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5881+{
5882+ return xchg(&(v->counter), new);
5883+}
5884
5885 /**
5886 * __atomic_add_unless - add unless the number is a given value
5887@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5888
5889 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5890 #define atomic_inc_return(v) atomic_add_return(1, (v))
5891+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5892+{
5893+ return atomic_add_return_unchecked(1, v);
5894+}
5895
5896 /*
5897 * atomic_sub_and_test - subtract value from variable and test result
5898@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5899 * other cases.
5900 */
5901 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5902+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5903+{
5904+ return atomic_add_return_unchecked(1, v) == 0;
5905+}
5906
5907 /*
5908 * atomic_dec_and_test - decrement by 1 and test
5909@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5910 * Atomically increments @v by 1.
5911 */
5912 #define atomic_inc(v) atomic_add(1, (v))
5913+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5914+{
5915+ atomic_add_unchecked(1, v);
5916+}
5917
5918 /*
5919 * atomic_dec - decrement and test
5920@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5921 * Atomically decrements @v by 1.
5922 */
5923 #define atomic_dec(v) atomic_sub(1, (v))
5924+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5925+{
5926+ atomic_sub_unchecked(1, v);
5927+}
5928
5929 /*
5930 * atomic_add_negative - add and test if negative
5931@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5932 * @v: pointer of type atomic64_t
5933 *
5934 */
5935-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5936+static inline long atomic64_read(const atomic64_t *v)
5937+{
5938+ return (*(volatile const long *) &v->counter);
5939+}
5940+
5941+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5942+{
5943+ return (*(volatile const long *) &v->counter);
5944+}
5945
5946 /*
5947 * atomic64_set - set atomic variable
5948 * @v: pointer of type atomic64_t
5949 * @i: required value
5950 */
5951-#define atomic64_set(v, i) ((v)->counter = (i))
5952+static inline void atomic64_set(atomic64_t *v, long i)
5953+{
5954+ v->counter = i;
5955+}
5956+
5957+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5958+{
5959+ v->counter = i;
5960+}
5961
5962 /*
5963 * atomic64_add - add integer to atomic variable
5964@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5965 *
5966 * Atomically adds @i to @v.
5967 */
5968-static __inline__ void atomic64_add(long i, atomic64_t * v)
5969+static __inline__ void atomic64_add(long i, atomic64_t *v)
5970+{
5971+ long temp;
5972+
5973+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5974+ __asm__ __volatile__(
5975+ " .set mips3 \n"
5976+ "1: lld %0, %1 # atomic64_add \n"
5977+#ifdef CONFIG_PAX_REFCOUNT
5978+ /* Exception on overflow. */
5979+ "2: dadd %0, %2 \n"
5980+#else
5981+ " daddu %0, %2 \n"
5982+#endif
5983+ " scd %0, %1 \n"
5984+ " beqzl %0, 1b \n"
5985+#ifdef CONFIG_PAX_REFCOUNT
5986+ "3: \n"
5987+ _ASM_EXTABLE(2b, 3b)
5988+#endif
5989+ " .set mips0 \n"
5990+ : "=&r" (temp), "+m" (v->counter)
5991+ : "Ir" (i));
5992+ } else if (kernel_uses_llsc) {
5993+ __asm__ __volatile__(
5994+ " .set mips3 \n"
5995+ "1: lld %0, %1 # atomic64_add \n"
5996+#ifdef CONFIG_PAX_REFCOUNT
5997+ /* Exception on overflow. */
5998+ "2: dadd %0, %2 \n"
5999+#else
6000+ " daddu %0, %2 \n"
6001+#endif
6002+ " scd %0, %1 \n"
6003+ " beqz %0, 1b \n"
6004+#ifdef CONFIG_PAX_REFCOUNT
6005+ "3: \n"
6006+ _ASM_EXTABLE(2b, 3b)
6007+#endif
6008+ " .set mips0 \n"
6009+ : "=&r" (temp), "+m" (v->counter)
6010+ : "Ir" (i));
6011+ } else {
6012+ unsigned long flags;
6013+
6014+ raw_local_irq_save(flags);
6015+ __asm__ __volatile__(
6016+#ifdef CONFIG_PAX_REFCOUNT
6017+ /* Exception on overflow. */
6018+ "1: dadd %0, %1 \n"
6019+ "2: \n"
6020+ _ASM_EXTABLE(1b, 2b)
6021+#else
6022+ " daddu %0, %1 \n"
6023+#endif
6024+ : "+r" (v->counter) : "Ir" (i));
6025+ raw_local_irq_restore(flags);
6026+ }
6027+}
6028+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6029 {
6030 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6031 long temp;
6032@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6033 *
6034 * Atomically subtracts @i from @v.
6035 */
6036-static __inline__ void atomic64_sub(long i, atomic64_t * v)
6037+static __inline__ void atomic64_sub(long i, atomic64_t *v)
6038+{
6039+ long temp;
6040+
6041+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6042+ __asm__ __volatile__(
6043+ " .set mips3 \n"
6044+ "1: lld %0, %1 # atomic64_sub \n"
6045+#ifdef CONFIG_PAX_REFCOUNT
6046+ /* Exception on overflow. */
6047+ "2: dsub %0, %2 \n"
6048+#else
6049+ " dsubu %0, %2 \n"
6050+#endif
6051+ " scd %0, %1 \n"
6052+ " beqzl %0, 1b \n"
6053+#ifdef CONFIG_PAX_REFCOUNT
6054+ "3: \n"
6055+ _ASM_EXTABLE(2b, 3b)
6056+#endif
6057+ " .set mips0 \n"
6058+ : "=&r" (temp), "+m" (v->counter)
6059+ : "Ir" (i));
6060+ } else if (kernel_uses_llsc) {
6061+ __asm__ __volatile__(
6062+ " .set mips3 \n"
6063+ "1: lld %0, %1 # atomic64_sub \n"
6064+#ifdef CONFIG_PAX_REFCOUNT
6065+ /* Exception on overflow. */
6066+ "2: dsub %0, %2 \n"
6067+#else
6068+ " dsubu %0, %2 \n"
6069+#endif
6070+ " scd %0, %1 \n"
6071+ " beqz %0, 1b \n"
6072+#ifdef CONFIG_PAX_REFCOUNT
6073+ "3: \n"
6074+ _ASM_EXTABLE(2b, 3b)
6075+#endif
6076+ " .set mips0 \n"
6077+ : "=&r" (temp), "+m" (v->counter)
6078+ : "Ir" (i));
6079+ } else {
6080+ unsigned long flags;
6081+
6082+ raw_local_irq_save(flags);
6083+ __asm__ __volatile__(
6084+#ifdef CONFIG_PAX_REFCOUNT
6085+ /* Exception on overflow. */
6086+ "1: dsub %0, %1 \n"
6087+ "2: \n"
6088+ _ASM_EXTABLE(1b, 2b)
6089+#else
6090+ " dsubu %0, %1 \n"
6091+#endif
6092+ : "+r" (v->counter) : "Ir" (i));
6093+ raw_local_irq_restore(flags);
6094+ }
6095+}
6096+
6097+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6098 {
6099 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6100 long temp;
6101@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6102 /*
6103 * Same as above, but return the result value
6104 */
6105-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6106+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6107+{
6108+ long result;
6109+ long temp;
6110+
6111+ smp_mb__before_llsc();
6112+
6113+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6114+ __asm__ __volatile__(
6115+ " .set mips3 \n"
6116+ "1: lld %1, %2 # atomic64_add_return \n"
6117+#ifdef CONFIG_PAX_REFCOUNT
6118+ "2: dadd %0, %1, %3 \n"
6119+#else
6120+ " daddu %0, %1, %3 \n"
6121+#endif
6122+ " scd %0, %2 \n"
6123+ " beqzl %0, 1b \n"
6124+#ifdef CONFIG_PAX_REFCOUNT
6125+ " b 4f \n"
6126+ " .set noreorder \n"
6127+ "3: b 5f \n"
6128+ " move %0, %1 \n"
6129+ " .set reorder \n"
6130+ _ASM_EXTABLE(2b, 3b)
6131+#endif
6132+ "4: daddu %0, %1, %3 \n"
6133+#ifdef CONFIG_PAX_REFCOUNT
6134+ "5: \n"
6135+#endif
6136+ " .set mips0 \n"
6137+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6138+ : "Ir" (i));
6139+ } else if (kernel_uses_llsc) {
6140+ __asm__ __volatile__(
6141+ " .set mips3 \n"
6142+ "1: lld %1, %2 # atomic64_add_return \n"
6143+#ifdef CONFIG_PAX_REFCOUNT
6144+ "2: dadd %0, %1, %3 \n"
6145+#else
6146+ " daddu %0, %1, %3 \n"
6147+#endif
6148+ " scd %0, %2 \n"
6149+ " bnez %0, 4f \n"
6150+ " b 1b \n"
6151+#ifdef CONFIG_PAX_REFCOUNT
6152+ " .set noreorder \n"
6153+ "3: b 5f \n"
6154+ " move %0, %1 \n"
6155+ " .set reorder \n"
6156+ _ASM_EXTABLE(2b, 3b)
6157+#endif
6158+ "4: daddu %0, %1, %3 \n"
6159+#ifdef CONFIG_PAX_REFCOUNT
6160+ "5: \n"
6161+#endif
6162+ " .set mips0 \n"
6163+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6164+ : "Ir" (i), "m" (v->counter)
6165+ : "memory");
6166+ } else {
6167+ unsigned long flags;
6168+
6169+ raw_local_irq_save(flags);
6170+ __asm__ __volatile__(
6171+ " ld %0, %1 \n"
6172+#ifdef CONFIG_PAX_REFCOUNT
6173+ /* Exception on overflow. */
6174+ "1: dadd %0, %2 \n"
6175+#else
6176+ " daddu %0, %2 \n"
6177+#endif
6178+ " sd %0, %1 \n"
6179+#ifdef CONFIG_PAX_REFCOUNT
6180+ /* Note: Dest reg is not modified on overflow */
6181+ "2: \n"
6182+ _ASM_EXTABLE(1b, 2b)
6183+#endif
6184+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6185+ raw_local_irq_restore(flags);
6186+ }
6187+
6188+ smp_llsc_mb();
6189+
6190+ return result;
6191+}
6192+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6193 {
6194 long result;
6195
6196@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6197 return result;
6198 }
6199
6200-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6201+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6202+{
6203+ long result;
6204+ long temp;
6205+
6206+ smp_mb__before_llsc();
6207+
6208+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6209+ long temp;
6210+
6211+ __asm__ __volatile__(
6212+ " .set mips3 \n"
6213+ "1: lld %1, %2 # atomic64_sub_return \n"
6214+#ifdef CONFIG_PAX_REFCOUNT
6215+ "2: dsub %0, %1, %3 \n"
6216+#else
6217+ " dsubu %0, %1, %3 \n"
6218+#endif
6219+ " scd %0, %2 \n"
6220+ " beqzl %0, 1b \n"
6221+#ifdef CONFIG_PAX_REFCOUNT
6222+ " b 4f \n"
6223+ " .set noreorder \n"
6224+ "3: b 5f \n"
6225+ " move %0, %1 \n"
6226+ " .set reorder \n"
6227+ _ASM_EXTABLE(2b, 3b)
6228+#endif
6229+ "4: dsubu %0, %1, %3 \n"
6230+#ifdef CONFIG_PAX_REFCOUNT
6231+ "5: \n"
6232+#endif
6233+ " .set mips0 \n"
6234+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6235+ : "Ir" (i), "m" (v->counter)
6236+ : "memory");
6237+ } else if (kernel_uses_llsc) {
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+ " bnez %0, 4f \n"
6248+ " b 1b \n"
6249+#ifdef CONFIG_PAX_REFCOUNT
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 {
6265+ unsigned long flags;
6266+
6267+ raw_local_irq_save(flags);
6268+ __asm__ __volatile__(
6269+ " ld %0, %1 \n"
6270+#ifdef CONFIG_PAX_REFCOUNT
6271+ /* Exception on overflow. */
6272+ "1: dsub %0, %2 \n"
6273+#else
6274+ " dsubu %0, %2 \n"
6275+#endif
6276+ " sd %0, %1 \n"
6277+#ifdef CONFIG_PAX_REFCOUNT
6278+ /* Note: Dest reg is not modified on overflow */
6279+ "2: \n"
6280+ _ASM_EXTABLE(1b, 2b)
6281+#endif
6282+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6283+ raw_local_irq_restore(flags);
6284+ }
6285+
6286+ smp_llsc_mb();
6287+
6288+ return result;
6289+}
6290+
6291+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6292 {
6293 long result;
6294
6295@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6296 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6297 * The function returns the old value of @v minus @i.
6298 */
6299-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6300+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6301 {
6302 long result;
6303
6304@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6305 return result;
6306 }
6307
6308-#define atomic64_cmpxchg(v, o, n) \
6309- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6310-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6311+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6312+{
6313+ return cmpxchg(&v->counter, old, new);
6314+}
6315+
6316+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6317+ long new)
6318+{
6319+ return cmpxchg(&(v->counter), old, new);
6320+}
6321+
6322+static inline long atomic64_xchg(atomic64_t *v, long new)
6323+{
6324+ return xchg(&v->counter, new);
6325+}
6326+
6327+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6328+{
6329+ return xchg(&(v->counter), new);
6330+}
6331
6332 /**
6333 * atomic64_add_unless - add unless the number is a given value
6334@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6335
6336 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6337 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6338+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6339
6340 /*
6341 * atomic64_sub_and_test - subtract value from variable and test result
6342@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6343 * other cases.
6344 */
6345 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6346+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6347
6348 /*
6349 * atomic64_dec_and_test - decrement by 1 and test
6350@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6351 * Atomically increments @v by 1.
6352 */
6353 #define atomic64_inc(v) atomic64_add(1, (v))
6354+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6355
6356 /*
6357 * atomic64_dec - decrement and test
6358@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6359 * Atomically decrements @v by 1.
6360 */
6361 #define atomic64_dec(v) atomic64_sub(1, (v))
6362+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6363
6364 /*
6365 * atomic64_add_negative - add and test if negative
6366diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6367index b4db69f..8f3b093 100644
6368--- a/arch/mips/include/asm/cache.h
6369+++ b/arch/mips/include/asm/cache.h
6370@@ -9,10 +9,11 @@
6371 #ifndef _ASM_CACHE_H
6372 #define _ASM_CACHE_H
6373
6374+#include <linux/const.h>
6375 #include <kmalloc.h>
6376
6377 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6378-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6379+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6380
6381 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6382 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6383diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6384index a66359e..d3d474a 100644
6385--- a/arch/mips/include/asm/elf.h
6386+++ b/arch/mips/include/asm/elf.h
6387@@ -373,13 +373,16 @@ extern const char *__elf_platform;
6388 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6389 #endif
6390
6391+#ifdef CONFIG_PAX_ASLR
6392+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6393+
6394+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6395+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6396+#endif
6397+
6398 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6399 struct linux_binprm;
6400 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6401 int uses_interp);
6402
6403-struct mm_struct;
6404-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6405-#define arch_randomize_brk arch_randomize_brk
6406-
6407 #endif /* _ASM_ELF_H */
6408diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6409index c1f6afa..38cc6e9 100644
6410--- a/arch/mips/include/asm/exec.h
6411+++ b/arch/mips/include/asm/exec.h
6412@@ -12,6 +12,6 @@
6413 #ifndef _ASM_EXEC_H
6414 #define _ASM_EXEC_H
6415
6416-extern unsigned long arch_align_stack(unsigned long sp);
6417+#define arch_align_stack(x) ((x) & ~0xfUL)
6418
6419 #endif /* _ASM_EXEC_H */
6420diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6421index d44622c..64990d2 100644
6422--- a/arch/mips/include/asm/local.h
6423+++ b/arch/mips/include/asm/local.h
6424@@ -12,15 +12,25 @@ typedef struct
6425 atomic_long_t a;
6426 } local_t;
6427
6428+typedef struct {
6429+ atomic_long_unchecked_t a;
6430+} local_unchecked_t;
6431+
6432 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6433
6434 #define local_read(l) atomic_long_read(&(l)->a)
6435+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6436 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6437+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6438
6439 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6440+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6441 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6442+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6443 #define local_inc(l) atomic_long_inc(&(l)->a)
6444+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6445 #define local_dec(l) atomic_long_dec(&(l)->a)
6446+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6447
6448 /*
6449 * Same as above, but return the result value
6450@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6451 return result;
6452 }
6453
6454+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6455+{
6456+ unsigned long result;
6457+
6458+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6459+ unsigned long temp;
6460+
6461+ __asm__ __volatile__(
6462+ " .set mips3 \n"
6463+ "1:" __LL "%1, %2 # local_add_return \n"
6464+ " addu %0, %1, %3 \n"
6465+ __SC "%0, %2 \n"
6466+ " beqzl %0, 1b \n"
6467+ " addu %0, %1, %3 \n"
6468+ " .set mips0 \n"
6469+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6470+ : "Ir" (i), "m" (l->a.counter)
6471+ : "memory");
6472+ } else if (kernel_uses_llsc) {
6473+ unsigned long temp;
6474+
6475+ __asm__ __volatile__(
6476+ " .set mips3 \n"
6477+ "1:" __LL "%1, %2 # local_add_return \n"
6478+ " addu %0, %1, %3 \n"
6479+ __SC "%0, %2 \n"
6480+ " beqz %0, 1b \n"
6481+ " addu %0, %1, %3 \n"
6482+ " .set mips0 \n"
6483+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6484+ : "Ir" (i), "m" (l->a.counter)
6485+ : "memory");
6486+ } else {
6487+ unsigned long flags;
6488+
6489+ local_irq_save(flags);
6490+ result = l->a.counter;
6491+ result += i;
6492+ l->a.counter = result;
6493+ local_irq_restore(flags);
6494+ }
6495+
6496+ return result;
6497+}
6498+
6499 static __inline__ long local_sub_return(long i, local_t * l)
6500 {
6501 unsigned long result;
6502@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6503
6504 #define local_cmpxchg(l, o, n) \
6505 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6506+#define local_cmpxchg_unchecked(l, o, n) \
6507+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6508 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6509
6510 /**
6511diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6512index f6be474..12ad554 100644
6513--- a/arch/mips/include/asm/page.h
6514+++ b/arch/mips/include/asm/page.h
6515@@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6516 #ifdef CONFIG_CPU_MIPS32
6517 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6518 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6519- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6520+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6521 #else
6522 typedef struct { unsigned long long pte; } pte_t;
6523 #define pte_val(x) ((x).pte)
6524diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6525index b336037..5b874cc 100644
6526--- a/arch/mips/include/asm/pgalloc.h
6527+++ b/arch/mips/include/asm/pgalloc.h
6528@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6529 {
6530 set_pud(pud, __pud((unsigned long)pmd));
6531 }
6532+
6533+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6534+{
6535+ pud_populate(mm, pud, pmd);
6536+}
6537 #endif
6538
6539 /*
6540diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6541index 25da651..ae2a259 100644
6542--- a/arch/mips/include/asm/smtc_proc.h
6543+++ b/arch/mips/include/asm/smtc_proc.h
6544@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6545
6546 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6547
6548-extern atomic_t smtc_fpu_recoveries;
6549+extern atomic_unchecked_t smtc_fpu_recoveries;
6550
6551 #endif /* __ASM_SMTC_PROC_H */
6552diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6553index 4f58ef6..5e7081b 100644
6554--- a/arch/mips/include/asm/thread_info.h
6555+++ b/arch/mips/include/asm/thread_info.h
6556@@ -115,6 +115,8 @@ static inline struct thread_info *current_thread_info(void)
6557 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6558 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6559 #define TIF_SYSCALL_TRACEPOINT 26 /* syscall tracepoint instrumentation */
6560+/* li takes a 32bit immediate */
6561+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6562 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6563
6564 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6565@@ -132,13 +134,14 @@ static inline struct thread_info *current_thread_info(void)
6566 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6567 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6568 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6569+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6570
6571 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6572- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6573+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6574
6575 /* work to do in syscall_trace_leave() */
6576 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6577- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6578+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6579
6580 /* work to do on interrupt/exception return */
6581 #define _TIF_WORK_MASK \
6582@@ -146,7 +149,7 @@ static inline struct thread_info *current_thread_info(void)
6583 /* work to do on any return to u-space */
6584 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6585 _TIF_WORK_SYSCALL_EXIT | \
6586- _TIF_SYSCALL_TRACEPOINT)
6587+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6588
6589 /*
6590 * We stash processor id into a COP0 register to retrieve it fast
6591diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6592index 1188e00..41cf144 100644
6593--- a/arch/mips/kernel/binfmt_elfn32.c
6594+++ b/arch/mips/kernel/binfmt_elfn32.c
6595@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6596 #undef ELF_ET_DYN_BASE
6597 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6598
6599+#ifdef CONFIG_PAX_ASLR
6600+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6601+
6602+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6603+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6604+#endif
6605+
6606 #include <asm/processor.h>
6607 #include <linux/module.h>
6608 #include <linux/elfcore.h>
6609diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6610index 202e581..689ca79 100644
6611--- a/arch/mips/kernel/binfmt_elfo32.c
6612+++ b/arch/mips/kernel/binfmt_elfo32.c
6613@@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6614 #undef ELF_ET_DYN_BASE
6615 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6616
6617+#ifdef CONFIG_PAX_ASLR
6618+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6619+
6620+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6621+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6622+#endif
6623+
6624 #include <asm/processor.h>
6625
6626 /*
6627diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6628index d1fea7a..45602ea 100644
6629--- a/arch/mips/kernel/irq.c
6630+++ b/arch/mips/kernel/irq.c
6631@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6632 printk("unexpected IRQ # %d\n", irq);
6633 }
6634
6635-atomic_t irq_err_count;
6636+atomic_unchecked_t irq_err_count;
6637
6638 int arch_show_interrupts(struct seq_file *p, int prec)
6639 {
6640- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6641+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6642 return 0;
6643 }
6644
6645 asmlinkage void spurious_interrupt(void)
6646 {
6647- atomic_inc(&irq_err_count);
6648+ atomic_inc_unchecked(&irq_err_count);
6649 }
6650
6651 void __init init_IRQ(void)
6652diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6653index ddc7610..8c58f17 100644
6654--- a/arch/mips/kernel/process.c
6655+++ b/arch/mips/kernel/process.c
6656@@ -566,15 +566,3 @@ unsigned long get_wchan(struct task_struct *task)
6657 out:
6658 return pc;
6659 }
6660-
6661-/*
6662- * Don't forget that the stack pointer must be aligned on a 8 bytes
6663- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6664- */
6665-unsigned long arch_align_stack(unsigned long sp)
6666-{
6667- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6668- sp -= get_random_int() & ~PAGE_MASK;
6669-
6670- return sp & ALMASK;
6671-}
6672diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6673index b52e1d2..1a3ca09 100644
6674--- a/arch/mips/kernel/ptrace.c
6675+++ b/arch/mips/kernel/ptrace.c
6676@@ -652,6 +652,10 @@ long arch_ptrace(struct task_struct *child, long request,
6677 return ret;
6678 }
6679
6680+#ifdef CONFIG_GRKERNSEC_SETXID
6681+extern void gr_delayed_cred_worker(void);
6682+#endif
6683+
6684 /*
6685 * Notification of system call entry/exit
6686 * - triggered by current->work.syscall_trace
6687@@ -668,6 +672,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6688 tracehook_report_syscall_entry(regs))
6689 ret = -1;
6690
6691+#ifdef CONFIG_GRKERNSEC_SETXID
6692+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6693+ gr_delayed_cred_worker();
6694+#endif
6695+
6696 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6697 trace_sys_enter(regs, regs->regs[2]);
6698
6699diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6700index c10aa84..9ec2e60 100644
6701--- a/arch/mips/kernel/smtc-proc.c
6702+++ b/arch/mips/kernel/smtc-proc.c
6703@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6704
6705 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6706
6707-atomic_t smtc_fpu_recoveries;
6708+atomic_unchecked_t smtc_fpu_recoveries;
6709
6710 static int smtc_proc_show(struct seq_file *m, void *v)
6711 {
6712@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6713 for(i = 0; i < NR_CPUS; i++)
6714 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6715 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6716- atomic_read(&smtc_fpu_recoveries));
6717+ atomic_read_unchecked(&smtc_fpu_recoveries));
6718 return 0;
6719 }
6720
6721@@ -73,7 +73,7 @@ void init_smtc_stats(void)
6722 smtc_cpu_stats[i].selfipis = 0;
6723 }
6724
6725- atomic_set(&smtc_fpu_recoveries, 0);
6726+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6727
6728 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6729 }
6730diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6731index dfc1b91..11a2c07 100644
6732--- a/arch/mips/kernel/smtc.c
6733+++ b/arch/mips/kernel/smtc.c
6734@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6735 }
6736 smtc_ipi_qdump();
6737 printk("%d Recoveries of \"stolen\" FPU\n",
6738- atomic_read(&smtc_fpu_recoveries));
6739+ atomic_read_unchecked(&smtc_fpu_recoveries));
6740 }
6741
6742
6743diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6744index 84536bf..79caa4d 100644
6745--- a/arch/mips/kernel/sync-r4k.c
6746+++ b/arch/mips/kernel/sync-r4k.c
6747@@ -21,8 +21,8 @@
6748 #include <asm/mipsregs.h>
6749
6750 static atomic_t count_start_flag = ATOMIC_INIT(0);
6751-static atomic_t count_count_start = ATOMIC_INIT(0);
6752-static atomic_t count_count_stop = ATOMIC_INIT(0);
6753+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6754+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6755 static atomic_t count_reference = ATOMIC_INIT(0);
6756
6757 #define COUNTON 100
6758@@ -69,13 +69,13 @@ void synchronise_count_master(int cpu)
6759
6760 for (i = 0; i < NR_LOOPS; i++) {
6761 /* slaves loop on '!= 2' */
6762- while (atomic_read(&count_count_start) != 1)
6763+ while (atomic_read_unchecked(&count_count_start) != 1)
6764 mb();
6765- atomic_set(&count_count_stop, 0);
6766+ atomic_set_unchecked(&count_count_stop, 0);
6767 smp_wmb();
6768
6769 /* this lets the slaves write their count register */
6770- atomic_inc(&count_count_start);
6771+ atomic_inc_unchecked(&count_count_start);
6772
6773 /*
6774 * Everyone initialises count in the last loop:
6775@@ -86,11 +86,11 @@ void synchronise_count_master(int cpu)
6776 /*
6777 * Wait for all slaves to leave the synchronization point:
6778 */
6779- while (atomic_read(&count_count_stop) != 1)
6780+ while (atomic_read_unchecked(&count_count_stop) != 1)
6781 mb();
6782- atomic_set(&count_count_start, 0);
6783+ atomic_set_unchecked(&count_count_start, 0);
6784 smp_wmb();
6785- atomic_inc(&count_count_stop);
6786+ atomic_inc_unchecked(&count_count_stop);
6787 }
6788 /* Arrange for an interrupt in a short while */
6789 write_c0_compare(read_c0_count() + COUNTON);
6790@@ -131,8 +131,8 @@ void synchronise_count_slave(int cpu)
6791 initcount = atomic_read(&count_reference);
6792
6793 for (i = 0; i < NR_LOOPS; i++) {
6794- atomic_inc(&count_count_start);
6795- while (atomic_read(&count_count_start) != 2)
6796+ atomic_inc_unchecked(&count_count_start);
6797+ while (atomic_read_unchecked(&count_count_start) != 2)
6798 mb();
6799
6800 /*
6801@@ -141,8 +141,8 @@ void synchronise_count_slave(int cpu)
6802 if (i == NR_LOOPS-1)
6803 write_c0_count(initcount);
6804
6805- atomic_inc(&count_count_stop);
6806- while (atomic_read(&count_count_stop) != 2)
6807+ atomic_inc_unchecked(&count_count_stop);
6808+ while (atomic_read_unchecked(&count_count_stop) != 2)
6809 mb();
6810 }
6811 /* Arrange for an interrupt in a short while */
6812diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6813index f9c8746..78b64e3 100644
6814--- a/arch/mips/kernel/traps.c
6815+++ b/arch/mips/kernel/traps.c
6816@@ -690,7 +690,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6817 siginfo_t info;
6818
6819 prev_state = exception_enter();
6820- die_if_kernel("Integer overflow", regs);
6821+ if (unlikely(!user_mode(regs))) {
6822+
6823+#ifdef CONFIG_PAX_REFCOUNT
6824+ if (fixup_exception(regs)) {
6825+ pax_report_refcount_overflow(regs);
6826+ exception_exit(prev_state);
6827+ return;
6828+ }
6829+#endif
6830+
6831+ die("Integer overflow", regs);
6832+ }
6833
6834 info.si_code = FPE_INTOVF;
6835 info.si_signo = SIGFPE;
6836diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6837index becc42b..9e43d4b 100644
6838--- a/arch/mips/mm/fault.c
6839+++ b/arch/mips/mm/fault.c
6840@@ -28,6 +28,23 @@
6841 #include <asm/highmem.h> /* For VMALLOC_END */
6842 #include <linux/kdebug.h>
6843
6844+#ifdef CONFIG_PAX_PAGEEXEC
6845+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6846+{
6847+ unsigned long i;
6848+
6849+ printk(KERN_ERR "PAX: bytes at PC: ");
6850+ for (i = 0; i < 5; i++) {
6851+ unsigned int c;
6852+ if (get_user(c, (unsigned int *)pc+i))
6853+ printk(KERN_CONT "???????? ");
6854+ else
6855+ printk(KERN_CONT "%08x ", c);
6856+ }
6857+ printk("\n");
6858+}
6859+#endif
6860+
6861 /*
6862 * This routine handles page faults. It determines the address,
6863 * and the problem, and then passes it off to one of the appropriate
6864@@ -199,6 +216,14 @@ bad_area:
6865 bad_area_nosemaphore:
6866 /* User mode accesses just cause a SIGSEGV */
6867 if (user_mode(regs)) {
6868+
6869+#ifdef CONFIG_PAX_PAGEEXEC
6870+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6871+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6872+ do_group_exit(SIGKILL);
6873+ }
6874+#endif
6875+
6876 tsk->thread.cp0_badvaddr = address;
6877 tsk->thread.error_code = write;
6878 #if 0
6879diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6880index f1baadd..8537544 100644
6881--- a/arch/mips/mm/mmap.c
6882+++ b/arch/mips/mm/mmap.c
6883@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6884 struct vm_area_struct *vma;
6885 unsigned long addr = addr0;
6886 int do_color_align;
6887+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6888 struct vm_unmapped_area_info info;
6889
6890 if (unlikely(len > TASK_SIZE))
6891@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6892 do_color_align = 1;
6893
6894 /* requesting a specific address */
6895+
6896+#ifdef CONFIG_PAX_RANDMMAP
6897+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6898+#endif
6899+
6900 if (addr) {
6901 if (do_color_align)
6902 addr = COLOUR_ALIGN(addr, pgoff);
6903@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6904 addr = PAGE_ALIGN(addr);
6905
6906 vma = find_vma(mm, addr);
6907- if (TASK_SIZE - len >= addr &&
6908- (!vma || addr + len <= vma->vm_start))
6909+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
6910 return addr;
6911 }
6912
6913 info.length = len;
6914 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6915 info.align_offset = pgoff << PAGE_SHIFT;
6916+ info.threadstack_offset = offset;
6917
6918 if (dir == DOWN) {
6919 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6920@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6921 {
6922 unsigned long random_factor = 0UL;
6923
6924+#ifdef CONFIG_PAX_RANDMMAP
6925+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6926+#endif
6927+
6928 if (current->flags & PF_RANDOMIZE) {
6929 random_factor = get_random_int();
6930 random_factor = random_factor << PAGE_SHIFT;
6931@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6932
6933 if (mmap_is_legacy()) {
6934 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6935+
6936+#ifdef CONFIG_PAX_RANDMMAP
6937+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6938+ mm->mmap_base += mm->delta_mmap;
6939+#endif
6940+
6941 mm->get_unmapped_area = arch_get_unmapped_area;
6942 } else {
6943 mm->mmap_base = mmap_base(random_factor);
6944+
6945+#ifdef CONFIG_PAX_RANDMMAP
6946+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6947+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6948+#endif
6949+
6950 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6951 }
6952 }
6953
6954-static inline unsigned long brk_rnd(void)
6955-{
6956- unsigned long rnd = get_random_int();
6957-
6958- rnd = rnd << PAGE_SHIFT;
6959- /* 8MB for 32bit, 256MB for 64bit */
6960- if (TASK_IS_32BIT_ADDR)
6961- rnd = rnd & 0x7ffffful;
6962- else
6963- rnd = rnd & 0xffffffful;
6964-
6965- return rnd;
6966-}
6967-
6968-unsigned long arch_randomize_brk(struct mm_struct *mm)
6969-{
6970- unsigned long base = mm->brk;
6971- unsigned long ret;
6972-
6973- ret = PAGE_ALIGN(base + brk_rnd());
6974-
6975- if (ret < mm->brk)
6976- return mm->brk;
6977-
6978- return ret;
6979-}
6980-
6981 int __virt_addr_valid(const volatile void *kaddr)
6982 {
6983 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
6984diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
6985index a2358b4..7cead4f 100644
6986--- a/arch/mips/sgi-ip27/ip27-nmi.c
6987+++ b/arch/mips/sgi-ip27/ip27-nmi.c
6988@@ -187,9 +187,9 @@ void
6989 cont_nmi_dump(void)
6990 {
6991 #ifndef REAL_NMI_SIGNAL
6992- static atomic_t nmied_cpus = ATOMIC_INIT(0);
6993+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
6994
6995- atomic_inc(&nmied_cpus);
6996+ atomic_inc_unchecked(&nmied_cpus);
6997 #endif
6998 /*
6999 * Only allow 1 cpu to proceed
7000@@ -233,7 +233,7 @@ cont_nmi_dump(void)
7001 udelay(10000);
7002 }
7003 #else
7004- while (atomic_read(&nmied_cpus) != num_online_cpus());
7005+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7006 #endif
7007
7008 /*
7009diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7010index 967d144..db12197 100644
7011--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7012+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7013@@ -11,12 +11,14 @@
7014 #ifndef _ASM_PROC_CACHE_H
7015 #define _ASM_PROC_CACHE_H
7016
7017+#include <linux/const.h>
7018+
7019 /* L1 cache */
7020
7021 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7022 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7023-#define L1_CACHE_BYTES 16 /* bytes per entry */
7024 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7025+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7026 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7027
7028 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7029diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7030index bcb5df2..84fabd2 100644
7031--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7032+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7033@@ -16,13 +16,15 @@
7034 #ifndef _ASM_PROC_CACHE_H
7035 #define _ASM_PROC_CACHE_H
7036
7037+#include <linux/const.h>
7038+
7039 /*
7040 * L1 cache
7041 */
7042 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7043 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7044-#define L1_CACHE_BYTES 32 /* bytes per entry */
7045 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7046+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7047 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7048
7049 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7050diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7051index 4ce7a01..449202a 100644
7052--- a/arch/openrisc/include/asm/cache.h
7053+++ b/arch/openrisc/include/asm/cache.h
7054@@ -19,11 +19,13 @@
7055 #ifndef __ASM_OPENRISC_CACHE_H
7056 #define __ASM_OPENRISC_CACHE_H
7057
7058+#include <linux/const.h>
7059+
7060 /* FIXME: How can we replace these with values from the CPU...
7061 * they shouldn't be hard-coded!
7062 */
7063
7064-#define L1_CACHE_BYTES 16
7065 #define L1_CACHE_SHIFT 4
7066+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7067
7068 #endif /* __ASM_OPENRISC_CACHE_H */
7069diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7070index 472886c..00e7df9 100644
7071--- a/arch/parisc/include/asm/atomic.h
7072+++ b/arch/parisc/include/asm/atomic.h
7073@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7074 return dec;
7075 }
7076
7077+#define atomic64_read_unchecked(v) atomic64_read(v)
7078+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7079+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7080+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7081+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7082+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7083+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7084+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7085+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7086+
7087 #endif /* !CONFIG_64BIT */
7088
7089
7090diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7091index 47f11c7..3420df2 100644
7092--- a/arch/parisc/include/asm/cache.h
7093+++ b/arch/parisc/include/asm/cache.h
7094@@ -5,6 +5,7 @@
7095 #ifndef __ARCH_PARISC_CACHE_H
7096 #define __ARCH_PARISC_CACHE_H
7097
7098+#include <linux/const.h>
7099
7100 /*
7101 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7102@@ -15,13 +16,13 @@
7103 * just ruin performance.
7104 */
7105 #ifdef CONFIG_PA20
7106-#define L1_CACHE_BYTES 64
7107 #define L1_CACHE_SHIFT 6
7108 #else
7109-#define L1_CACHE_BYTES 32
7110 #define L1_CACHE_SHIFT 5
7111 #endif
7112
7113+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7114+
7115 #ifndef __ASSEMBLY__
7116
7117 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7118diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7119index ad2b503..bdf1651 100644
7120--- a/arch/parisc/include/asm/elf.h
7121+++ b/arch/parisc/include/asm/elf.h
7122@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7123
7124 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7125
7126+#ifdef CONFIG_PAX_ASLR
7127+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7128+
7129+#define PAX_DELTA_MMAP_LEN 16
7130+#define PAX_DELTA_STACK_LEN 16
7131+#endif
7132+
7133 /* This yields a mask that user programs can use to figure out what
7134 instruction set this CPU supports. This could be done in user space,
7135 but it's not easy, and we've already done it here. */
7136diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7137index f213f5b..0af3e8e 100644
7138--- a/arch/parisc/include/asm/pgalloc.h
7139+++ b/arch/parisc/include/asm/pgalloc.h
7140@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7141 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7142 }
7143
7144+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7145+{
7146+ pgd_populate(mm, pgd, pmd);
7147+}
7148+
7149 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7150 {
7151 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7152@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7153 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7154 #define pmd_free(mm, x) do { } while (0)
7155 #define pgd_populate(mm, pmd, pte) BUG()
7156+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7157
7158 #endif
7159
7160diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7161index 34899b5..02dd060 100644
7162--- a/arch/parisc/include/asm/pgtable.h
7163+++ b/arch/parisc/include/asm/pgtable.h
7164@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7165 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7166 #define PAGE_COPY PAGE_EXECREAD
7167 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7168+
7169+#ifdef CONFIG_PAX_PAGEEXEC
7170+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7171+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7172+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7173+#else
7174+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7175+# define PAGE_COPY_NOEXEC PAGE_COPY
7176+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7177+#endif
7178+
7179 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7180 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7181 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7182diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7183index 4006964..fcb3cc2 100644
7184--- a/arch/parisc/include/asm/uaccess.h
7185+++ b/arch/parisc/include/asm/uaccess.h
7186@@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7187 const void __user *from,
7188 unsigned long n)
7189 {
7190- int sz = __compiletime_object_size(to);
7191+ size_t sz = __compiletime_object_size(to);
7192 int ret = -EFAULT;
7193
7194- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7195+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7196 ret = __copy_from_user(to, from, n);
7197 else
7198 copy_from_user_overflow();
7199diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7200index 50dfafc..b9fc230 100644
7201--- a/arch/parisc/kernel/module.c
7202+++ b/arch/parisc/kernel/module.c
7203@@ -98,16 +98,38 @@
7204
7205 /* three functions to determine where in the module core
7206 * or init pieces the location is */
7207+static inline int in_init_rx(struct module *me, void *loc)
7208+{
7209+ return (loc >= me->module_init_rx &&
7210+ loc < (me->module_init_rx + me->init_size_rx));
7211+}
7212+
7213+static inline int in_init_rw(struct module *me, void *loc)
7214+{
7215+ return (loc >= me->module_init_rw &&
7216+ loc < (me->module_init_rw + me->init_size_rw));
7217+}
7218+
7219 static inline int in_init(struct module *me, void *loc)
7220 {
7221- return (loc >= me->module_init &&
7222- loc <= (me->module_init + me->init_size));
7223+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7224+}
7225+
7226+static inline int in_core_rx(struct module *me, void *loc)
7227+{
7228+ return (loc >= me->module_core_rx &&
7229+ loc < (me->module_core_rx + me->core_size_rx));
7230+}
7231+
7232+static inline int in_core_rw(struct module *me, void *loc)
7233+{
7234+ return (loc >= me->module_core_rw &&
7235+ loc < (me->module_core_rw + me->core_size_rw));
7236 }
7237
7238 static inline int in_core(struct module *me, void *loc)
7239 {
7240- return (loc >= me->module_core &&
7241- loc <= (me->module_core + me->core_size));
7242+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7243 }
7244
7245 static inline int in_local(struct module *me, void *loc)
7246@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7247 }
7248
7249 /* align things a bit */
7250- me->core_size = ALIGN(me->core_size, 16);
7251- me->arch.got_offset = me->core_size;
7252- me->core_size += gots * sizeof(struct got_entry);
7253+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7254+ me->arch.got_offset = me->core_size_rw;
7255+ me->core_size_rw += gots * sizeof(struct got_entry);
7256
7257- me->core_size = ALIGN(me->core_size, 16);
7258- me->arch.fdesc_offset = me->core_size;
7259- me->core_size += fdescs * sizeof(Elf_Fdesc);
7260+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7261+ me->arch.fdesc_offset = me->core_size_rw;
7262+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7263
7264 me->arch.got_max = gots;
7265 me->arch.fdesc_max = fdescs;
7266@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7267
7268 BUG_ON(value == 0);
7269
7270- got = me->module_core + me->arch.got_offset;
7271+ got = me->module_core_rw + me->arch.got_offset;
7272 for (i = 0; got[i].addr; i++)
7273 if (got[i].addr == value)
7274 goto out;
7275@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7276 #ifdef CONFIG_64BIT
7277 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7278 {
7279- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7280+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7281
7282 if (!value) {
7283 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7284@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7285
7286 /* Create new one */
7287 fdesc->addr = value;
7288- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7289+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7290 return (Elf_Addr)fdesc;
7291 }
7292 #endif /* CONFIG_64BIT */
7293@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7294
7295 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7296 end = table + sechdrs[me->arch.unwind_section].sh_size;
7297- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7298+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7299
7300 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7301 me->arch.unwind_section, table, end, gp);
7302diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7303index 0d3a9d4..20a99b0 100644
7304--- a/arch/parisc/kernel/sys_parisc.c
7305+++ b/arch/parisc/kernel/sys_parisc.c
7306@@ -33,9 +33,11 @@
7307 #include <linux/utsname.h>
7308 #include <linux/personality.h>
7309
7310-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7311+static unsigned long get_unshared_area(unsigned long addr, unsigned long len,
7312+ unsigned long flags)
7313 {
7314 struct vm_unmapped_area_info info;
7315+ unsigned long offset = gr_rand_threadstack_offset(current->mm, NULL, flags);
7316
7317 info.flags = 0;
7318 info.length = len;
7319@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7320 info.high_limit = TASK_SIZE;
7321 info.align_mask = 0;
7322 info.align_offset = 0;
7323+ info.threadstack_offset = offset;
7324 return vm_unmapped_area(&info);
7325 }
7326
7327@@ -69,9 +72,10 @@ static unsigned long shared_align_offset(struct file *filp, unsigned long pgoff)
7328 }
7329
7330 static unsigned long get_shared_area(struct file *filp, unsigned long addr,
7331- unsigned long len, unsigned long pgoff)
7332+ unsigned long len, unsigned long pgoff, unsigned long flags)
7333 {
7334 struct vm_unmapped_area_info info;
7335+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7336
7337 info.flags = 0;
7338 info.length = len;
7339@@ -79,6 +83,7 @@ static unsigned long get_shared_area(struct file *filp, unsigned long addr,
7340 info.high_limit = TASK_SIZE;
7341 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7342 info.align_offset = shared_align_offset(filp, pgoff);
7343+ info.threadstack_offset = offset;
7344 return vm_unmapped_area(&info);
7345 }
7346
7347@@ -93,13 +98,20 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7348 return -EINVAL;
7349 return addr;
7350 }
7351- if (!addr)
7352+ if (!addr) {
7353 addr = TASK_UNMAPPED_BASE;
7354
7355+#ifdef CONFIG_PAX_RANDMMAP
7356+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7357+ addr += current->mm->delta_mmap;
7358+#endif
7359+
7360+ }
7361+
7362 if (filp || (flags & MAP_SHARED))
7363- addr = get_shared_area(filp, addr, len, pgoff);
7364+ addr = get_shared_area(filp, addr, len, pgoff, flags);
7365 else
7366- addr = get_unshared_area(addr, len);
7367+ addr = get_unshared_area(addr, len, flags);
7368
7369 return addr;
7370 }
7371diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7372index 1cd1d0c..44ec918 100644
7373--- a/arch/parisc/kernel/traps.c
7374+++ b/arch/parisc/kernel/traps.c
7375@@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7376
7377 down_read(&current->mm->mmap_sem);
7378 vma = find_vma(current->mm,regs->iaoq[0]);
7379- if (vma && (regs->iaoq[0] >= vma->vm_start)
7380- && (vma->vm_flags & VM_EXEC)) {
7381-
7382+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7383 fault_address = regs->iaoq[0];
7384 fault_space = regs->iasq[0];
7385
7386diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7387index 9d08c71..e2b4d20 100644
7388--- a/arch/parisc/mm/fault.c
7389+++ b/arch/parisc/mm/fault.c
7390@@ -15,6 +15,7 @@
7391 #include <linux/sched.h>
7392 #include <linux/interrupt.h>
7393 #include <linux/module.h>
7394+#include <linux/unistd.h>
7395
7396 #include <asm/uaccess.h>
7397 #include <asm/traps.h>
7398@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7399 static unsigned long
7400 parisc_acctyp(unsigned long code, unsigned int inst)
7401 {
7402- if (code == 6 || code == 16)
7403+ if (code == 6 || code == 7 || code == 16)
7404 return VM_EXEC;
7405
7406 switch (inst & 0xf0000000) {
7407@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7408 }
7409 #endif
7410
7411+#ifdef CONFIG_PAX_PAGEEXEC
7412+/*
7413+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7414+ *
7415+ * returns 1 when task should be killed
7416+ * 2 when rt_sigreturn trampoline was detected
7417+ * 3 when unpatched PLT trampoline was detected
7418+ */
7419+static int pax_handle_fetch_fault(struct pt_regs *regs)
7420+{
7421+
7422+#ifdef CONFIG_PAX_EMUPLT
7423+ int err;
7424+
7425+ do { /* PaX: unpatched PLT emulation */
7426+ unsigned int bl, depwi;
7427+
7428+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7429+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7430+
7431+ if (err)
7432+ break;
7433+
7434+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7435+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7436+
7437+ err = get_user(ldw, (unsigned int *)addr);
7438+ err |= get_user(bv, (unsigned int *)(addr+4));
7439+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7440+
7441+ if (err)
7442+ break;
7443+
7444+ if (ldw == 0x0E801096U &&
7445+ bv == 0xEAC0C000U &&
7446+ ldw2 == 0x0E881095U)
7447+ {
7448+ unsigned int resolver, map;
7449+
7450+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7451+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7452+ if (err)
7453+ break;
7454+
7455+ regs->gr[20] = instruction_pointer(regs)+8;
7456+ regs->gr[21] = map;
7457+ regs->gr[22] = resolver;
7458+ regs->iaoq[0] = resolver | 3UL;
7459+ regs->iaoq[1] = regs->iaoq[0] + 4;
7460+ return 3;
7461+ }
7462+ }
7463+ } while (0);
7464+#endif
7465+
7466+#ifdef CONFIG_PAX_EMUTRAMP
7467+
7468+#ifndef CONFIG_PAX_EMUSIGRT
7469+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7470+ return 1;
7471+#endif
7472+
7473+ do { /* PaX: rt_sigreturn emulation */
7474+ unsigned int ldi1, ldi2, bel, nop;
7475+
7476+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7477+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7478+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7479+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7480+
7481+ if (err)
7482+ break;
7483+
7484+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7485+ ldi2 == 0x3414015AU &&
7486+ bel == 0xE4008200U &&
7487+ nop == 0x08000240U)
7488+ {
7489+ regs->gr[25] = (ldi1 & 2) >> 1;
7490+ regs->gr[20] = __NR_rt_sigreturn;
7491+ regs->gr[31] = regs->iaoq[1] + 16;
7492+ regs->sr[0] = regs->iasq[1];
7493+ regs->iaoq[0] = 0x100UL;
7494+ regs->iaoq[1] = regs->iaoq[0] + 4;
7495+ regs->iasq[0] = regs->sr[2];
7496+ regs->iasq[1] = regs->sr[2];
7497+ return 2;
7498+ }
7499+ } while (0);
7500+#endif
7501+
7502+ return 1;
7503+}
7504+
7505+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7506+{
7507+ unsigned long i;
7508+
7509+ printk(KERN_ERR "PAX: bytes at PC: ");
7510+ for (i = 0; i < 5; i++) {
7511+ unsigned int c;
7512+ if (get_user(c, (unsigned int *)pc+i))
7513+ printk(KERN_CONT "???????? ");
7514+ else
7515+ printk(KERN_CONT "%08x ", c);
7516+ }
7517+ printk("\n");
7518+}
7519+#endif
7520+
7521 int fixup_exception(struct pt_regs *regs)
7522 {
7523 const struct exception_table_entry *fix;
7524@@ -210,8 +321,33 @@ retry:
7525
7526 good_area:
7527
7528- if ((vma->vm_flags & acc_type) != acc_type)
7529+ if ((vma->vm_flags & acc_type) != acc_type) {
7530+
7531+#ifdef CONFIG_PAX_PAGEEXEC
7532+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7533+ (address & ~3UL) == instruction_pointer(regs))
7534+ {
7535+ up_read(&mm->mmap_sem);
7536+ switch (pax_handle_fetch_fault(regs)) {
7537+
7538+#ifdef CONFIG_PAX_EMUPLT
7539+ case 3:
7540+ return;
7541+#endif
7542+
7543+#ifdef CONFIG_PAX_EMUTRAMP
7544+ case 2:
7545+ return;
7546+#endif
7547+
7548+ }
7549+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7550+ do_group_exit(SIGKILL);
7551+ }
7552+#endif
7553+
7554 goto bad_area;
7555+ }
7556
7557 /*
7558 * If for any reason at all we couldn't handle the fault, make
7559diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7560index b44b52c..4cd253c 100644
7561--- a/arch/powerpc/Kconfig
7562+++ b/arch/powerpc/Kconfig
7563@@ -382,6 +382,7 @@ config ARCH_ENABLE_MEMORY_HOTREMOVE
7564 config KEXEC
7565 bool "kexec system call"
7566 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7567+ depends on !GRKERNSEC_KMEM
7568 help
7569 kexec is a system call that implements the ability to shutdown your
7570 current kernel, and to start another kernel. It is like a reboot
7571diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7572index e3b1d41..8e81edf 100644
7573--- a/arch/powerpc/include/asm/atomic.h
7574+++ b/arch/powerpc/include/asm/atomic.h
7575@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7576 return t1;
7577 }
7578
7579+#define atomic64_read_unchecked(v) atomic64_read(v)
7580+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7581+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7582+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7583+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7584+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7585+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7586+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7587+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7588+
7589 #endif /* __powerpc64__ */
7590
7591 #endif /* __KERNEL__ */
7592diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7593index 9e495c9..b6878e5 100644
7594--- a/arch/powerpc/include/asm/cache.h
7595+++ b/arch/powerpc/include/asm/cache.h
7596@@ -3,6 +3,7 @@
7597
7598 #ifdef __KERNEL__
7599
7600+#include <linux/const.h>
7601
7602 /* bytes per L1 cache line */
7603 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7604@@ -22,7 +23,7 @@
7605 #define L1_CACHE_SHIFT 7
7606 #endif
7607
7608-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7609+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7610
7611 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7612
7613diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7614index 935b5e7..7001d2d 100644
7615--- a/arch/powerpc/include/asm/elf.h
7616+++ b/arch/powerpc/include/asm/elf.h
7617@@ -28,8 +28,19 @@
7618 the loader. We need to make sure that it is out of the way of the program
7619 that it will "exec", and that there is sufficient room for the brk. */
7620
7621-extern unsigned long randomize_et_dyn(unsigned long base);
7622-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7623+#define ELF_ET_DYN_BASE (0x20000000)
7624+
7625+#ifdef CONFIG_PAX_ASLR
7626+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7627+
7628+#ifdef __powerpc64__
7629+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7630+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7631+#else
7632+#define PAX_DELTA_MMAP_LEN 15
7633+#define PAX_DELTA_STACK_LEN 15
7634+#endif
7635+#endif
7636
7637 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
7638
7639@@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7640 (0x7ff >> (PAGE_SHIFT - 12)) : \
7641 (0x3ffff >> (PAGE_SHIFT - 12)))
7642
7643-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7644-#define arch_randomize_brk arch_randomize_brk
7645-
7646-
7647 #ifdef CONFIG_SPU_BASE
7648 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7649 #define NT_SPU 1
7650diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7651index 8196e9c..d83a9f3 100644
7652--- a/arch/powerpc/include/asm/exec.h
7653+++ b/arch/powerpc/include/asm/exec.h
7654@@ -4,6 +4,6 @@
7655 #ifndef _ASM_POWERPC_EXEC_H
7656 #define _ASM_POWERPC_EXEC_H
7657
7658-extern unsigned long arch_align_stack(unsigned long sp);
7659+#define arch_align_stack(x) ((x) & ~0xfUL)
7660
7661 #endif /* _ASM_POWERPC_EXEC_H */
7662diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7663index 5acabbd..7ea14fa 100644
7664--- a/arch/powerpc/include/asm/kmap_types.h
7665+++ b/arch/powerpc/include/asm/kmap_types.h
7666@@ -10,7 +10,7 @@
7667 * 2 of the License, or (at your option) any later version.
7668 */
7669
7670-#define KM_TYPE_NR 16
7671+#define KM_TYPE_NR 17
7672
7673 #endif /* __KERNEL__ */
7674 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
7675diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
7676index 8565c25..2865190 100644
7677--- a/arch/powerpc/include/asm/mman.h
7678+++ b/arch/powerpc/include/asm/mman.h
7679@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
7680 }
7681 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
7682
7683-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
7684+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
7685 {
7686 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
7687 }
7688diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
7689index 32e4e21..62afb12 100644
7690--- a/arch/powerpc/include/asm/page.h
7691+++ b/arch/powerpc/include/asm/page.h
7692@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
7693 * and needs to be executable. This means the whole heap ends
7694 * up being executable.
7695 */
7696-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7697- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7698+#define VM_DATA_DEFAULT_FLAGS32 \
7699+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7700+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7701
7702 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7703 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7704@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
7705 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
7706 #endif
7707
7708+#define ktla_ktva(addr) (addr)
7709+#define ktva_ktla(addr) (addr)
7710+
7711 #ifndef CONFIG_PPC_BOOK3S_64
7712 /*
7713 * Use the top bit of the higher-level page table entries to indicate whether
7714diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
7715index 88693ce..ac6f9ab 100644
7716--- a/arch/powerpc/include/asm/page_64.h
7717+++ b/arch/powerpc/include/asm/page_64.h
7718@@ -153,15 +153,18 @@ do { \
7719 * stack by default, so in the absence of a PT_GNU_STACK program header
7720 * we turn execute permission off.
7721 */
7722-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7723- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7724+#define VM_STACK_DEFAULT_FLAGS32 \
7725+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7726+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7727
7728 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7729 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7730
7731+#ifndef CONFIG_PAX_PAGEEXEC
7732 #define VM_STACK_DEFAULT_FLAGS \
7733 (is_32bit_task() ? \
7734 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
7735+#endif
7736
7737 #include <asm-generic/getorder.h>
7738
7739diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
7740index 4b0be20..c15a27d 100644
7741--- a/arch/powerpc/include/asm/pgalloc-64.h
7742+++ b/arch/powerpc/include/asm/pgalloc-64.h
7743@@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7744 #ifndef CONFIG_PPC_64K_PAGES
7745
7746 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
7747+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
7748
7749 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
7750 {
7751@@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7752 pud_set(pud, (unsigned long)pmd);
7753 }
7754
7755+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7756+{
7757+ pud_populate(mm, pud, pmd);
7758+}
7759+
7760 #define pmd_populate(mm, pmd, pte_page) \
7761 pmd_populate_kernel(mm, pmd, page_address(pte_page))
7762 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
7763@@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
7764 #endif
7765
7766 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
7767+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7768
7769 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
7770 pte_t *pte)
7771diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
7772index 7d6eacf..14c0240 100644
7773--- a/arch/powerpc/include/asm/pgtable.h
7774+++ b/arch/powerpc/include/asm/pgtable.h
7775@@ -2,6 +2,7 @@
7776 #define _ASM_POWERPC_PGTABLE_H
7777 #ifdef __KERNEL__
7778
7779+#include <linux/const.h>
7780 #ifndef __ASSEMBLY__
7781 #include <asm/processor.h> /* For TASK_SIZE */
7782 #include <asm/mmu.h>
7783diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
7784index 4aad413..85d86bf 100644
7785--- a/arch/powerpc/include/asm/pte-hash32.h
7786+++ b/arch/powerpc/include/asm/pte-hash32.h
7787@@ -21,6 +21,7 @@
7788 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
7789 #define _PAGE_USER 0x004 /* usermode access allowed */
7790 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
7791+#define _PAGE_EXEC _PAGE_GUARDED
7792 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
7793 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
7794 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
7795diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
7796index fa8388e..f985549 100644
7797--- a/arch/powerpc/include/asm/reg.h
7798+++ b/arch/powerpc/include/asm/reg.h
7799@@ -239,6 +239,7 @@
7800 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
7801 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
7802 #define DSISR_NOHPTE 0x40000000 /* no translation found */
7803+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
7804 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
7805 #define DSISR_ISSTORE 0x02000000 /* access was a store */
7806 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
7807diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
7808index 084e080..9415a3d 100644
7809--- a/arch/powerpc/include/asm/smp.h
7810+++ b/arch/powerpc/include/asm/smp.h
7811@@ -51,7 +51,7 @@ struct smp_ops_t {
7812 int (*cpu_disable)(void);
7813 void (*cpu_die)(unsigned int nr);
7814 int (*cpu_bootable)(unsigned int nr);
7815-};
7816+} __no_const;
7817
7818 extern void smp_send_debugger_break(void);
7819 extern void start_secondary_resume(void);
7820diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
7821index 9854c56..7517190 100644
7822--- a/arch/powerpc/include/asm/thread_info.h
7823+++ b/arch/powerpc/include/asm/thread_info.h
7824@@ -91,7 +91,6 @@ static inline struct thread_info *current_thread_info(void)
7825 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
7826 TIF_NEED_RESCHED */
7827 #define TIF_32BIT 4 /* 32 bit binary */
7828-#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
7829 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
7830 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
7831 #define TIF_SINGLESTEP 8 /* singlestepping active */
7832@@ -108,6 +107,9 @@ static inline struct thread_info *current_thread_info(void)
7833 #if defined(CONFIG_PPC64)
7834 #define TIF_ELF2ABI 18 /* function descriptors must die! */
7835 #endif
7836+#define TIF_PERFMON_WORK 19 /* work for pfm_handle_work() */
7837+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
7838+#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
7839
7840 /* as above, but as bit values */
7841 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
7842@@ -127,9 +129,10 @@ static inline struct thread_info *current_thread_info(void)
7843 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7844 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
7845 #define _TIF_NOHZ (1<<TIF_NOHZ)
7846+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7847 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
7848 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
7849- _TIF_NOHZ)
7850+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
7851
7852 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
7853 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
7854diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
7855index 9485b43..4718d50 100644
7856--- a/arch/powerpc/include/asm/uaccess.h
7857+++ b/arch/powerpc/include/asm/uaccess.h
7858@@ -318,52 +318,6 @@ do { \
7859 extern unsigned long __copy_tofrom_user(void __user *to,
7860 const void __user *from, unsigned long size);
7861
7862-#ifndef __powerpc64__
7863-
7864-static inline unsigned long copy_from_user(void *to,
7865- const void __user *from, unsigned long n)
7866-{
7867- unsigned long over;
7868-
7869- if (access_ok(VERIFY_READ, from, n))
7870- return __copy_tofrom_user((__force void __user *)to, from, n);
7871- if ((unsigned long)from < TASK_SIZE) {
7872- over = (unsigned long)from + n - TASK_SIZE;
7873- return __copy_tofrom_user((__force void __user *)to, from,
7874- n - over) + over;
7875- }
7876- return n;
7877-}
7878-
7879-static inline unsigned long copy_to_user(void __user *to,
7880- const void *from, unsigned long n)
7881-{
7882- unsigned long over;
7883-
7884- if (access_ok(VERIFY_WRITE, to, n))
7885- return __copy_tofrom_user(to, (__force void __user *)from, n);
7886- if ((unsigned long)to < TASK_SIZE) {
7887- over = (unsigned long)to + n - TASK_SIZE;
7888- return __copy_tofrom_user(to, (__force void __user *)from,
7889- n - over) + over;
7890- }
7891- return n;
7892-}
7893-
7894-#else /* __powerpc64__ */
7895-
7896-#define __copy_in_user(to, from, size) \
7897- __copy_tofrom_user((to), (from), (size))
7898-
7899-extern unsigned long copy_from_user(void *to, const void __user *from,
7900- unsigned long n);
7901-extern unsigned long copy_to_user(void __user *to, const void *from,
7902- unsigned long n);
7903-extern unsigned long copy_in_user(void __user *to, const void __user *from,
7904- unsigned long n);
7905-
7906-#endif /* __powerpc64__ */
7907-
7908 static inline unsigned long __copy_from_user_inatomic(void *to,
7909 const void __user *from, unsigned long n)
7910 {
7911@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
7912 if (ret == 0)
7913 return 0;
7914 }
7915+
7916+ if (!__builtin_constant_p(n))
7917+ check_object_size(to, n, false);
7918+
7919 return __copy_tofrom_user((__force void __user *)to, from, n);
7920 }
7921
7922@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
7923 if (ret == 0)
7924 return 0;
7925 }
7926+
7927+ if (!__builtin_constant_p(n))
7928+ check_object_size(from, n, true);
7929+
7930 return __copy_tofrom_user(to, (__force const void __user *)from, n);
7931 }
7932
7933@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
7934 return __copy_to_user_inatomic(to, from, size);
7935 }
7936
7937+#ifndef __powerpc64__
7938+
7939+static inline unsigned long __must_check copy_from_user(void *to,
7940+ const void __user *from, unsigned long n)
7941+{
7942+ unsigned long over;
7943+
7944+ if ((long)n < 0)
7945+ return n;
7946+
7947+ if (access_ok(VERIFY_READ, from, n)) {
7948+ if (!__builtin_constant_p(n))
7949+ check_object_size(to, n, false);
7950+ return __copy_tofrom_user((__force void __user *)to, from, n);
7951+ }
7952+ if ((unsigned long)from < TASK_SIZE) {
7953+ over = (unsigned long)from + n - TASK_SIZE;
7954+ if (!__builtin_constant_p(n - over))
7955+ check_object_size(to, n - over, false);
7956+ return __copy_tofrom_user((__force void __user *)to, from,
7957+ n - over) + over;
7958+ }
7959+ return n;
7960+}
7961+
7962+static inline unsigned long __must_check copy_to_user(void __user *to,
7963+ const void *from, unsigned long n)
7964+{
7965+ unsigned long over;
7966+
7967+ if ((long)n < 0)
7968+ return n;
7969+
7970+ if (access_ok(VERIFY_WRITE, to, n)) {
7971+ if (!__builtin_constant_p(n))
7972+ check_object_size(from, n, true);
7973+ return __copy_tofrom_user(to, (__force void __user *)from, n);
7974+ }
7975+ if ((unsigned long)to < TASK_SIZE) {
7976+ over = (unsigned long)to + n - TASK_SIZE;
7977+ if (!__builtin_constant_p(n))
7978+ check_object_size(from, n - over, true);
7979+ return __copy_tofrom_user(to, (__force void __user *)from,
7980+ n - over) + over;
7981+ }
7982+ return n;
7983+}
7984+
7985+#else /* __powerpc64__ */
7986+
7987+#define __copy_in_user(to, from, size) \
7988+ __copy_tofrom_user((to), (from), (size))
7989+
7990+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
7991+{
7992+ if ((long)n < 0 || n > INT_MAX)
7993+ return n;
7994+
7995+ if (!__builtin_constant_p(n))
7996+ check_object_size(to, n, false);
7997+
7998+ if (likely(access_ok(VERIFY_READ, from, n)))
7999+ n = __copy_from_user(to, from, n);
8000+ else
8001+ memset(to, 0, n);
8002+ return n;
8003+}
8004+
8005+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8006+{
8007+ if ((long)n < 0 || n > INT_MAX)
8008+ return n;
8009+
8010+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
8011+ if (!__builtin_constant_p(n))
8012+ check_object_size(from, n, true);
8013+ n = __copy_to_user(to, from, n);
8014+ }
8015+ return n;
8016+}
8017+
8018+extern unsigned long copy_in_user(void __user *to, const void __user *from,
8019+ unsigned long n);
8020+
8021+#endif /* __powerpc64__ */
8022+
8023 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8024
8025 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8026diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8027index e775156..af2d1c0 100644
8028--- a/arch/powerpc/kernel/exceptions-64e.S
8029+++ b/arch/powerpc/kernel/exceptions-64e.S
8030@@ -759,6 +759,7 @@ storage_fault_common:
8031 std r14,_DAR(r1)
8032 std r15,_DSISR(r1)
8033 addi r3,r1,STACK_FRAME_OVERHEAD
8034+ bl .save_nvgprs
8035 mr r4,r14
8036 mr r5,r15
8037 ld r14,PACA_EXGEN+EX_R14(r13)
8038@@ -767,8 +768,7 @@ storage_fault_common:
8039 cmpdi r3,0
8040 bne- 1f
8041 b .ret_from_except_lite
8042-1: bl .save_nvgprs
8043- mr r5,r3
8044+1: mr r5,r3
8045 addi r3,r1,STACK_FRAME_OVERHEAD
8046 ld r4,_DAR(r1)
8047 bl .bad_page_fault
8048diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8049index 9f905e4..1d6b3d2 100644
8050--- a/arch/powerpc/kernel/exceptions-64s.S
8051+++ b/arch/powerpc/kernel/exceptions-64s.S
8052@@ -1390,10 +1390,10 @@ handle_page_fault:
8053 11: ld r4,_DAR(r1)
8054 ld r5,_DSISR(r1)
8055 addi r3,r1,STACK_FRAME_OVERHEAD
8056+ bl .save_nvgprs
8057 bl .do_page_fault
8058 cmpdi r3,0
8059 beq+ 12f
8060- bl .save_nvgprs
8061 mr r5,r3
8062 addi r3,r1,STACK_FRAME_OVERHEAD
8063 lwz r4,_DAR(r1)
8064diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8065index 6cff040..74ac5d1 100644
8066--- a/arch/powerpc/kernel/module_32.c
8067+++ b/arch/powerpc/kernel/module_32.c
8068@@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8069 me->arch.core_plt_section = i;
8070 }
8071 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8072- printk("Module doesn't contain .plt or .init.plt sections.\n");
8073+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8074 return -ENOEXEC;
8075 }
8076
8077@@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8078
8079 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8080 /* Init, or core PLT? */
8081- if (location >= mod->module_core
8082- && location < mod->module_core + mod->core_size)
8083+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8084+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8085 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8086- else
8087+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8088+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8089 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8090+ else {
8091+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8092+ return ~0UL;
8093+ }
8094
8095 /* Find this entry, or if that fails, the next avail. entry */
8096 while (entry->jump[0]) {
8097@@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8098 }
8099 #ifdef CONFIG_DYNAMIC_FTRACE
8100 module->arch.tramp =
8101- do_plt_call(module->module_core,
8102+ do_plt_call(module->module_core_rx,
8103 (unsigned long)ftrace_caller,
8104 sechdrs, module);
8105 #endif
8106diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8107index 4a96556..dd95f6c 100644
8108--- a/arch/powerpc/kernel/process.c
8109+++ b/arch/powerpc/kernel/process.c
8110@@ -888,8 +888,8 @@ void show_regs(struct pt_regs * regs)
8111 * Lookup NIP late so we have the best change of getting the
8112 * above info out without failing
8113 */
8114- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8115- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8116+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8117+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8118 #endif
8119 show_stack(current, (unsigned long *) regs->gpr[1]);
8120 if (!user_mode(regs))
8121@@ -1376,10 +1376,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8122 newsp = stack[0];
8123 ip = stack[STACK_FRAME_LR_SAVE];
8124 if (!firstframe || ip != lr) {
8125- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8126+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8127 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8128 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8129- printk(" (%pS)",
8130+ printk(" (%pA)",
8131 (void *)current->ret_stack[curr_frame].ret);
8132 curr_frame--;
8133 }
8134@@ -1399,7 +1399,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8135 struct pt_regs *regs = (struct pt_regs *)
8136 (sp + STACK_FRAME_OVERHEAD);
8137 lr = regs->link;
8138- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8139+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8140 regs->trap, (void *)regs->nip, (void *)lr);
8141 firstframe = 1;
8142 }
8143@@ -1435,58 +1435,3 @@ void notrace __ppc64_runlatch_off(void)
8144 mtspr(SPRN_CTRLT, ctrl);
8145 }
8146 #endif /* CONFIG_PPC64 */
8147-
8148-unsigned long arch_align_stack(unsigned long sp)
8149-{
8150- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8151- sp -= get_random_int() & ~PAGE_MASK;
8152- return sp & ~0xf;
8153-}
8154-
8155-static inline unsigned long brk_rnd(void)
8156-{
8157- unsigned long rnd = 0;
8158-
8159- /* 8MB for 32bit, 1GB for 64bit */
8160- if (is_32bit_task())
8161- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8162- else
8163- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8164-
8165- return rnd << PAGE_SHIFT;
8166-}
8167-
8168-unsigned long arch_randomize_brk(struct mm_struct *mm)
8169-{
8170- unsigned long base = mm->brk;
8171- unsigned long ret;
8172-
8173-#ifdef CONFIG_PPC_STD_MMU_64
8174- /*
8175- * If we are using 1TB segments and we are allowed to randomise
8176- * the heap, we can put it above 1TB so it is backed by a 1TB
8177- * segment. Otherwise the heap will be in the bottom 1TB
8178- * which always uses 256MB segments and this may result in a
8179- * performance penalty.
8180- */
8181- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8182- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8183-#endif
8184-
8185- ret = PAGE_ALIGN(base + brk_rnd());
8186-
8187- if (ret < mm->brk)
8188- return mm->brk;
8189-
8190- return ret;
8191-}
8192-
8193-unsigned long randomize_et_dyn(unsigned long base)
8194-{
8195- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8196-
8197- if (ret < base)
8198- return base;
8199-
8200- return ret;
8201-}
8202diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8203index 2e3d2bf..35df241 100644
8204--- a/arch/powerpc/kernel/ptrace.c
8205+++ b/arch/powerpc/kernel/ptrace.c
8206@@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8207 return ret;
8208 }
8209
8210+#ifdef CONFIG_GRKERNSEC_SETXID
8211+extern void gr_delayed_cred_worker(void);
8212+#endif
8213+
8214 /*
8215 * We must return the syscall number to actually look up in the table.
8216 * This can be -1L to skip running any syscall at all.
8217@@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8218
8219 secure_computing_strict(regs->gpr[0]);
8220
8221+#ifdef CONFIG_GRKERNSEC_SETXID
8222+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8223+ gr_delayed_cred_worker();
8224+#endif
8225+
8226 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8227 tracehook_report_syscall_entry(regs))
8228 /*
8229@@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8230 {
8231 int step;
8232
8233+#ifdef CONFIG_GRKERNSEC_SETXID
8234+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8235+ gr_delayed_cred_worker();
8236+#endif
8237+
8238 audit_syscall_exit(regs);
8239
8240 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8241diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8242index 68027bf..b26fd31 100644
8243--- a/arch/powerpc/kernel/signal_32.c
8244+++ b/arch/powerpc/kernel/signal_32.c
8245@@ -1004,7 +1004,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8246 /* Save user registers on the stack */
8247 frame = &rt_sf->uc.uc_mcontext;
8248 addr = frame;
8249- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8250+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8251 sigret = 0;
8252 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8253 } else {
8254diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8255index 4299104..29e2c51 100644
8256--- a/arch/powerpc/kernel/signal_64.c
8257+++ b/arch/powerpc/kernel/signal_64.c
8258@@ -758,7 +758,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8259 #endif
8260
8261 /* Set up to return from userspace. */
8262- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8263+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8264 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8265 } else {
8266 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8267diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8268index 907a472..4ba206f 100644
8269--- a/arch/powerpc/kernel/traps.c
8270+++ b/arch/powerpc/kernel/traps.c
8271@@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8272 return flags;
8273 }
8274
8275+extern void gr_handle_kernel_exploit(void);
8276+
8277 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8278 int signr)
8279 {
8280@@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8281 panic("Fatal exception in interrupt");
8282 if (panic_on_oops)
8283 panic("Fatal exception");
8284+
8285+ gr_handle_kernel_exploit();
8286+
8287 do_exit(signr);
8288 }
8289
8290diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8291index 094e45c..d82b848 100644
8292--- a/arch/powerpc/kernel/vdso.c
8293+++ b/arch/powerpc/kernel/vdso.c
8294@@ -35,6 +35,7 @@
8295 #include <asm/vdso.h>
8296 #include <asm/vdso_datapage.h>
8297 #include <asm/setup.h>
8298+#include <asm/mman.h>
8299
8300 #undef DEBUG
8301
8302@@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8303 vdso_base = VDSO32_MBASE;
8304 #endif
8305
8306- current->mm->context.vdso_base = 0;
8307+ current->mm->context.vdso_base = ~0UL;
8308
8309 /* vDSO has a problem and was disabled, just don't "enable" it for the
8310 * process
8311@@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8312 vdso_base = get_unmapped_area(NULL, vdso_base,
8313 (vdso_pages << PAGE_SHIFT) +
8314 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8315- 0, 0);
8316+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8317 if (IS_ERR_VALUE(vdso_base)) {
8318 rc = vdso_base;
8319 goto fail_mmapsem;
8320diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8321index 5eea6f3..5d10396 100644
8322--- a/arch/powerpc/lib/usercopy_64.c
8323+++ b/arch/powerpc/lib/usercopy_64.c
8324@@ -9,22 +9,6 @@
8325 #include <linux/module.h>
8326 #include <asm/uaccess.h>
8327
8328-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8329-{
8330- if (likely(access_ok(VERIFY_READ, from, n)))
8331- n = __copy_from_user(to, from, n);
8332- else
8333- memset(to, 0, n);
8334- return n;
8335-}
8336-
8337-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8338-{
8339- if (likely(access_ok(VERIFY_WRITE, to, n)))
8340- n = __copy_to_user(to, from, n);
8341- return n;
8342-}
8343-
8344 unsigned long copy_in_user(void __user *to, const void __user *from,
8345 unsigned long n)
8346 {
8347@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8348 return n;
8349 }
8350
8351-EXPORT_SYMBOL(copy_from_user);
8352-EXPORT_SYMBOL(copy_to_user);
8353 EXPORT_SYMBOL(copy_in_user);
8354
8355diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8356index 51ab9e7..7d3c78b 100644
8357--- a/arch/powerpc/mm/fault.c
8358+++ b/arch/powerpc/mm/fault.c
8359@@ -33,6 +33,10 @@
8360 #include <linux/magic.h>
8361 #include <linux/ratelimit.h>
8362 #include <linux/context_tracking.h>
8363+#include <linux/slab.h>
8364+#include <linux/pagemap.h>
8365+#include <linux/compiler.h>
8366+#include <linux/unistd.h>
8367
8368 #include <asm/firmware.h>
8369 #include <asm/page.h>
8370@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8371 }
8372 #endif
8373
8374+#ifdef CONFIG_PAX_PAGEEXEC
8375+/*
8376+ * PaX: decide what to do with offenders (regs->nip = fault address)
8377+ *
8378+ * returns 1 when task should be killed
8379+ */
8380+static int pax_handle_fetch_fault(struct pt_regs *regs)
8381+{
8382+ return 1;
8383+}
8384+
8385+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8386+{
8387+ unsigned long i;
8388+
8389+ printk(KERN_ERR "PAX: bytes at PC: ");
8390+ for (i = 0; i < 5; i++) {
8391+ unsigned int c;
8392+ if (get_user(c, (unsigned int __user *)pc+i))
8393+ printk(KERN_CONT "???????? ");
8394+ else
8395+ printk(KERN_CONT "%08x ", c);
8396+ }
8397+ printk("\n");
8398+}
8399+#endif
8400+
8401 /*
8402 * Check whether the instruction at regs->nip is a store using
8403 * an update addressing form which will update r1.
8404@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8405 * indicate errors in DSISR but can validly be set in SRR1.
8406 */
8407 if (trap == 0x400)
8408- error_code &= 0x48200000;
8409+ error_code &= 0x58200000;
8410 else
8411 is_write = error_code & DSISR_ISSTORE;
8412 #else
8413@@ -378,7 +409,7 @@ good_area:
8414 * "undefined". Of those that can be set, this is the only
8415 * one which seems bad.
8416 */
8417- if (error_code & 0x10000000)
8418+ if (error_code & DSISR_GUARDED)
8419 /* Guarded storage error. */
8420 goto bad_area;
8421 #endif /* CONFIG_8xx */
8422@@ -393,7 +424,7 @@ good_area:
8423 * processors use the same I/D cache coherency mechanism
8424 * as embedded.
8425 */
8426- if (error_code & DSISR_PROTFAULT)
8427+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8428 goto bad_area;
8429 #endif /* CONFIG_PPC_STD_MMU */
8430
8431@@ -483,6 +514,23 @@ bad_area:
8432 bad_area_nosemaphore:
8433 /* User mode accesses cause a SIGSEGV */
8434 if (user_mode(regs)) {
8435+
8436+#ifdef CONFIG_PAX_PAGEEXEC
8437+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8438+#ifdef CONFIG_PPC_STD_MMU
8439+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8440+#else
8441+ if (is_exec && regs->nip == address) {
8442+#endif
8443+ switch (pax_handle_fetch_fault(regs)) {
8444+ }
8445+
8446+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8447+ do_group_exit(SIGKILL);
8448+ }
8449+ }
8450+#endif
8451+
8452 _exception(SIGSEGV, regs, code, address);
8453 goto bail;
8454 }
8455diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8456index cb8bdbe..d770680 100644
8457--- a/arch/powerpc/mm/mmap.c
8458+++ b/arch/powerpc/mm/mmap.c
8459@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
8460 {
8461 unsigned long rnd = 0;
8462
8463+#ifdef CONFIG_PAX_RANDMMAP
8464+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8465+#endif
8466+
8467 if (current->flags & PF_RANDOMIZE) {
8468 /* 8MB for 32bit, 1GB for 64bit */
8469 if (is_32bit_task())
8470@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8471 */
8472 if (mmap_is_legacy()) {
8473 mm->mmap_base = TASK_UNMAPPED_BASE;
8474+
8475+#ifdef CONFIG_PAX_RANDMMAP
8476+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8477+ mm->mmap_base += mm->delta_mmap;
8478+#endif
8479+
8480 mm->get_unmapped_area = arch_get_unmapped_area;
8481 } else {
8482 mm->mmap_base = mmap_base();
8483+
8484+#ifdef CONFIG_PAX_RANDMMAP
8485+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8486+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8487+#endif
8488+
8489 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8490 }
8491 }
8492diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8493index 7ce9cf3..a964087 100644
8494--- a/arch/powerpc/mm/slice.c
8495+++ b/arch/powerpc/mm/slice.c
8496@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8497 if ((mm->task_size - len) < addr)
8498 return 0;
8499 vma = find_vma(mm, addr);
8500- return (!vma || (addr + len) <= vma->vm_start);
8501+ return check_heap_stack_gap(vma, addr, len, 0);
8502 }
8503
8504 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8505@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8506 info.align_offset = 0;
8507
8508 addr = TASK_UNMAPPED_BASE;
8509+
8510+#ifdef CONFIG_PAX_RANDMMAP
8511+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8512+ addr += mm->delta_mmap;
8513+#endif
8514+
8515 while (addr < TASK_SIZE) {
8516 info.low_limit = addr;
8517 if (!slice_scan_available(addr, available, 1, &addr))
8518@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8519 if (fixed && addr > (mm->task_size - len))
8520 return -EINVAL;
8521
8522+#ifdef CONFIG_PAX_RANDMMAP
8523+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8524+ addr = 0;
8525+#endif
8526+
8527 /* If hint, make sure it matches our alignment restrictions */
8528 if (!fixed && addr) {
8529 addr = _ALIGN_UP(addr, 1ul << pshift);
8530diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8531index 9098692..3d54cd1 100644
8532--- a/arch/powerpc/platforms/cell/spufs/file.c
8533+++ b/arch/powerpc/platforms/cell/spufs/file.c
8534@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8535 return VM_FAULT_NOPAGE;
8536 }
8537
8538-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
8539+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
8540 unsigned long address,
8541- void *buf, int len, int write)
8542+ void *buf, size_t len, int write)
8543 {
8544 struct spu_context *ctx = vma->vm_file->private_data;
8545 unsigned long offset = address - vma->vm_start;
8546diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
8547index fa9aaf7..3f5d836 100644
8548--- a/arch/s390/include/asm/atomic.h
8549+++ b/arch/s390/include/asm/atomic.h
8550@@ -398,6 +398,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
8551 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
8552 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8553
8554+#define atomic64_read_unchecked(v) atomic64_read(v)
8555+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8556+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8557+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8558+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8559+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8560+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8561+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8562+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8563+
8564 #define smp_mb__before_atomic_dec() smp_mb()
8565 #define smp_mb__after_atomic_dec() smp_mb()
8566 #define smp_mb__before_atomic_inc() smp_mb()
8567diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
8568index 4d7ccac..d03d0ad 100644
8569--- a/arch/s390/include/asm/cache.h
8570+++ b/arch/s390/include/asm/cache.h
8571@@ -9,8 +9,10 @@
8572 #ifndef __ARCH_S390_CACHE_H
8573 #define __ARCH_S390_CACHE_H
8574
8575-#define L1_CACHE_BYTES 256
8576+#include <linux/const.h>
8577+
8578 #define L1_CACHE_SHIFT 8
8579+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8580 #define NET_SKB_PAD 32
8581
8582 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8583diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
8584index 78f4f87..598ce39 100644
8585--- a/arch/s390/include/asm/elf.h
8586+++ b/arch/s390/include/asm/elf.h
8587@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
8588 the loader. We need to make sure that it is out of the way of the program
8589 that it will "exec", and that there is sufficient room for the brk. */
8590
8591-extern unsigned long randomize_et_dyn(unsigned long base);
8592-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
8593+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
8594+
8595+#ifdef CONFIG_PAX_ASLR
8596+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
8597+
8598+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8599+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8600+#endif
8601
8602 /* This yields a mask that user programs can use to figure out what
8603 instruction set this CPU supports. */
8604@@ -222,9 +228,6 @@ struct linux_binprm;
8605 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
8606 int arch_setup_additional_pages(struct linux_binprm *, int);
8607
8608-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8609-#define arch_randomize_brk arch_randomize_brk
8610-
8611 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
8612
8613 #endif
8614diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
8615index c4a93d6..4d2a9b4 100644
8616--- a/arch/s390/include/asm/exec.h
8617+++ b/arch/s390/include/asm/exec.h
8618@@ -7,6 +7,6 @@
8619 #ifndef __ASM_EXEC_H
8620 #define __ASM_EXEC_H
8621
8622-extern unsigned long arch_align_stack(unsigned long sp);
8623+#define arch_align_stack(x) ((x) & ~0xfUL)
8624
8625 #endif /* __ASM_EXEC_H */
8626diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
8627index 79330af..a3a7b06 100644
8628--- a/arch/s390/include/asm/uaccess.h
8629+++ b/arch/s390/include/asm/uaccess.h
8630@@ -245,6 +245,10 @@ static inline unsigned long __must_check
8631 copy_to_user(void __user *to, const void *from, unsigned long n)
8632 {
8633 might_fault();
8634+
8635+ if ((long)n < 0)
8636+ return n;
8637+
8638 return __copy_to_user(to, from, n);
8639 }
8640
8641@@ -268,6 +272,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
8642 static inline unsigned long __must_check
8643 __copy_from_user(void *to, const void __user *from, unsigned long n)
8644 {
8645+ if ((long)n < 0)
8646+ return n;
8647+
8648 return uaccess.copy_from_user(n, from, to);
8649 }
8650
8651@@ -296,10 +303,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
8652 static inline unsigned long __must_check
8653 copy_from_user(void *to, const void __user *from, unsigned long n)
8654 {
8655- unsigned int sz = __compiletime_object_size(to);
8656+ size_t sz = __compiletime_object_size(to);
8657
8658 might_fault();
8659- if (unlikely(sz != -1 && sz < n)) {
8660+
8661+ if ((long)n < 0)
8662+ return n;
8663+
8664+ if (unlikely(sz != (size_t)-1 && sz < n)) {
8665 copy_from_user_overflow();
8666 return n;
8667 }
8668diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
8669index b89b591..fd9609d 100644
8670--- a/arch/s390/kernel/module.c
8671+++ b/arch/s390/kernel/module.c
8672@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
8673
8674 /* Increase core size by size of got & plt and set start
8675 offsets for got and plt. */
8676- me->core_size = ALIGN(me->core_size, 4);
8677- me->arch.got_offset = me->core_size;
8678- me->core_size += me->arch.got_size;
8679- me->arch.plt_offset = me->core_size;
8680- me->core_size += me->arch.plt_size;
8681+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
8682+ me->arch.got_offset = me->core_size_rw;
8683+ me->core_size_rw += me->arch.got_size;
8684+ me->arch.plt_offset = me->core_size_rx;
8685+ me->core_size_rx += me->arch.plt_size;
8686 return 0;
8687 }
8688
8689@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8690 if (info->got_initialized == 0) {
8691 Elf_Addr *gotent;
8692
8693- gotent = me->module_core + me->arch.got_offset +
8694+ gotent = me->module_core_rw + me->arch.got_offset +
8695 info->got_offset;
8696 *gotent = val;
8697 info->got_initialized = 1;
8698@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8699 rc = apply_rela_bits(loc, val, 0, 64, 0);
8700 else if (r_type == R_390_GOTENT ||
8701 r_type == R_390_GOTPLTENT) {
8702- val += (Elf_Addr) me->module_core - loc;
8703+ val += (Elf_Addr) me->module_core_rw - loc;
8704 rc = apply_rela_bits(loc, val, 1, 32, 1);
8705 }
8706 break;
8707@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8708 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
8709 if (info->plt_initialized == 0) {
8710 unsigned int *ip;
8711- ip = me->module_core + me->arch.plt_offset +
8712+ ip = me->module_core_rx + me->arch.plt_offset +
8713 info->plt_offset;
8714 #ifndef CONFIG_64BIT
8715 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
8716@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8717 val - loc + 0xffffUL < 0x1ffffeUL) ||
8718 (r_type == R_390_PLT32DBL &&
8719 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
8720- val = (Elf_Addr) me->module_core +
8721+ val = (Elf_Addr) me->module_core_rx +
8722 me->arch.plt_offset +
8723 info->plt_offset;
8724 val += rela->r_addend - loc;
8725@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8726 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
8727 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
8728 val = val + rela->r_addend -
8729- ((Elf_Addr) me->module_core + me->arch.got_offset);
8730+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
8731 if (r_type == R_390_GOTOFF16)
8732 rc = apply_rela_bits(loc, val, 0, 16, 0);
8733 else if (r_type == R_390_GOTOFF32)
8734@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8735 break;
8736 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
8737 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
8738- val = (Elf_Addr) me->module_core + me->arch.got_offset +
8739+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
8740 rela->r_addend - loc;
8741 if (r_type == R_390_GOTPC)
8742 rc = apply_rela_bits(loc, val, 1, 32, 0);
8743diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
8744index 7ed0d4e..1dfc145 100644
8745--- a/arch/s390/kernel/process.c
8746+++ b/arch/s390/kernel/process.c
8747@@ -242,39 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
8748 }
8749 return 0;
8750 }
8751-
8752-unsigned long arch_align_stack(unsigned long sp)
8753-{
8754- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8755- sp -= get_random_int() & ~PAGE_MASK;
8756- return sp & ~0xf;
8757-}
8758-
8759-static inline unsigned long brk_rnd(void)
8760-{
8761- /* 8MB for 32bit, 1GB for 64bit */
8762- if (is_32bit_task())
8763- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
8764- else
8765- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
8766-}
8767-
8768-unsigned long arch_randomize_brk(struct mm_struct *mm)
8769-{
8770- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
8771-
8772- if (ret < mm->brk)
8773- return mm->brk;
8774- return ret;
8775-}
8776-
8777-unsigned long randomize_et_dyn(unsigned long base)
8778-{
8779- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8780-
8781- if (!(current->flags & PF_RANDOMIZE))
8782- return base;
8783- if (ret < base)
8784- return base;
8785- return ret;
8786-}
8787diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
8788index 9b436c2..54fbf0a 100644
8789--- a/arch/s390/mm/mmap.c
8790+++ b/arch/s390/mm/mmap.c
8791@@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8792 */
8793 if (mmap_is_legacy()) {
8794 mm->mmap_base = mmap_base_legacy();
8795+
8796+#ifdef CONFIG_PAX_RANDMMAP
8797+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8798+ mm->mmap_base += mm->delta_mmap;
8799+#endif
8800+
8801 mm->get_unmapped_area = arch_get_unmapped_area;
8802 } else {
8803 mm->mmap_base = mmap_base();
8804+
8805+#ifdef CONFIG_PAX_RANDMMAP
8806+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8807+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8808+#endif
8809+
8810 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8811 }
8812 }
8813@@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8814 */
8815 if (mmap_is_legacy()) {
8816 mm->mmap_base = mmap_base_legacy();
8817+
8818+#ifdef CONFIG_PAX_RANDMMAP
8819+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8820+ mm->mmap_base += mm->delta_mmap;
8821+#endif
8822+
8823 mm->get_unmapped_area = s390_get_unmapped_area;
8824 } else {
8825 mm->mmap_base = mmap_base();
8826+
8827+#ifdef CONFIG_PAX_RANDMMAP
8828+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8829+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8830+#endif
8831+
8832 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
8833 }
8834 }
8835diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
8836index ae3d59f..f65f075 100644
8837--- a/arch/score/include/asm/cache.h
8838+++ b/arch/score/include/asm/cache.h
8839@@ -1,7 +1,9 @@
8840 #ifndef _ASM_SCORE_CACHE_H
8841 #define _ASM_SCORE_CACHE_H
8842
8843+#include <linux/const.h>
8844+
8845 #define L1_CACHE_SHIFT 4
8846-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8847+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8848
8849 #endif /* _ASM_SCORE_CACHE_H */
8850diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
8851index f9f3cd5..58ff438 100644
8852--- a/arch/score/include/asm/exec.h
8853+++ b/arch/score/include/asm/exec.h
8854@@ -1,6 +1,6 @@
8855 #ifndef _ASM_SCORE_EXEC_H
8856 #define _ASM_SCORE_EXEC_H
8857
8858-extern unsigned long arch_align_stack(unsigned long sp);
8859+#define arch_align_stack(x) (x)
8860
8861 #endif /* _ASM_SCORE_EXEC_H */
8862diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
8863index a1519ad3..e8ac1ff 100644
8864--- a/arch/score/kernel/process.c
8865+++ b/arch/score/kernel/process.c
8866@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
8867
8868 return task_pt_regs(task)->cp0_epc;
8869 }
8870-
8871-unsigned long arch_align_stack(unsigned long sp)
8872-{
8873- return sp;
8874-}
8875diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
8876index ef9e555..331bd29 100644
8877--- a/arch/sh/include/asm/cache.h
8878+++ b/arch/sh/include/asm/cache.h
8879@@ -9,10 +9,11 @@
8880 #define __ASM_SH_CACHE_H
8881 #ifdef __KERNEL__
8882
8883+#include <linux/const.h>
8884 #include <linux/init.h>
8885 #include <cpu/cache.h>
8886
8887-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8888+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8889
8890 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8891
8892diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
8893index 6777177..cb5e44f 100644
8894--- a/arch/sh/mm/mmap.c
8895+++ b/arch/sh/mm/mmap.c
8896@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8897 struct mm_struct *mm = current->mm;
8898 struct vm_area_struct *vma;
8899 int do_colour_align;
8900+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8901 struct vm_unmapped_area_info info;
8902
8903 if (flags & MAP_FIXED) {
8904@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8905 if (filp || (flags & MAP_SHARED))
8906 do_colour_align = 1;
8907
8908+#ifdef CONFIG_PAX_RANDMMAP
8909+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8910+#endif
8911+
8912 if (addr) {
8913 if (do_colour_align)
8914 addr = COLOUR_ALIGN(addr, pgoff);
8915@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8916 addr = PAGE_ALIGN(addr);
8917
8918 vma = find_vma(mm, addr);
8919- if (TASK_SIZE - len >= addr &&
8920- (!vma || addr + len <= vma->vm_start))
8921+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8922 return addr;
8923 }
8924
8925 info.flags = 0;
8926 info.length = len;
8927- info.low_limit = TASK_UNMAPPED_BASE;
8928+ info.low_limit = mm->mmap_base;
8929 info.high_limit = TASK_SIZE;
8930 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
8931 info.align_offset = pgoff << PAGE_SHIFT;
8932@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8933 struct mm_struct *mm = current->mm;
8934 unsigned long addr = addr0;
8935 int do_colour_align;
8936+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8937 struct vm_unmapped_area_info info;
8938
8939 if (flags & MAP_FIXED) {
8940@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8941 if (filp || (flags & MAP_SHARED))
8942 do_colour_align = 1;
8943
8944+#ifdef CONFIG_PAX_RANDMMAP
8945+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8946+#endif
8947+
8948 /* requesting a specific address */
8949 if (addr) {
8950 if (do_colour_align)
8951@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8952 addr = PAGE_ALIGN(addr);
8953
8954 vma = find_vma(mm, addr);
8955- if (TASK_SIZE - len >= addr &&
8956- (!vma || addr + len <= vma->vm_start))
8957+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8958 return addr;
8959 }
8960
8961@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8962 VM_BUG_ON(addr != -ENOMEM);
8963 info.flags = 0;
8964 info.low_limit = TASK_UNMAPPED_BASE;
8965+
8966+#ifdef CONFIG_PAX_RANDMMAP
8967+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8968+ info.low_limit += mm->delta_mmap;
8969+#endif
8970+
8971 info.high_limit = TASK_SIZE;
8972 addr = vm_unmapped_area(&info);
8973 }
8974diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
8975index be56a24..443328f 100644
8976--- a/arch/sparc/include/asm/atomic_64.h
8977+++ b/arch/sparc/include/asm/atomic_64.h
8978@@ -14,18 +14,40 @@
8979 #define ATOMIC64_INIT(i) { (i) }
8980
8981 #define atomic_read(v) (*(volatile int *)&(v)->counter)
8982+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8983+{
8984+ return v->counter;
8985+}
8986 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
8987+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8988+{
8989+ return v->counter;
8990+}
8991
8992 #define atomic_set(v, i) (((v)->counter) = i)
8993+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8994+{
8995+ v->counter = i;
8996+}
8997 #define atomic64_set(v, i) (((v)->counter) = i)
8998+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8999+{
9000+ v->counter = i;
9001+}
9002
9003 extern void atomic_add(int, atomic_t *);
9004+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9005 extern void atomic64_add(long, atomic64_t *);
9006+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9007 extern void atomic_sub(int, atomic_t *);
9008+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9009 extern void atomic64_sub(long, atomic64_t *);
9010+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9011
9012 extern int atomic_add_ret(int, atomic_t *);
9013+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9014 extern long atomic64_add_ret(long, atomic64_t *);
9015+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9016 extern int atomic_sub_ret(int, atomic_t *);
9017 extern long atomic64_sub_ret(long, atomic64_t *);
9018
9019@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9020 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9021
9022 #define atomic_inc_return(v) atomic_add_ret(1, v)
9023+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9024+{
9025+ return atomic_add_ret_unchecked(1, v);
9026+}
9027 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9028+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9029+{
9030+ return atomic64_add_ret_unchecked(1, v);
9031+}
9032
9033 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9034 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9035
9036 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9037+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9038+{
9039+ return atomic_add_ret_unchecked(i, v);
9040+}
9041 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9042+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9043+{
9044+ return atomic64_add_ret_unchecked(i, v);
9045+}
9046
9047 /*
9048 * atomic_inc_and_test - increment and test
9049@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9050 * other cases.
9051 */
9052 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9053+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9054+{
9055+ return atomic_inc_return_unchecked(v) == 0;
9056+}
9057 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9058
9059 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9060@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9061 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9062
9063 #define atomic_inc(v) atomic_add(1, v)
9064+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9065+{
9066+ atomic_add_unchecked(1, v);
9067+}
9068 #define atomic64_inc(v) atomic64_add(1, v)
9069+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9070+{
9071+ atomic64_add_unchecked(1, v);
9072+}
9073
9074 #define atomic_dec(v) atomic_sub(1, v)
9075+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9076+{
9077+ atomic_sub_unchecked(1, v);
9078+}
9079 #define atomic64_dec(v) atomic64_sub(1, v)
9080+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9081+{
9082+ atomic64_sub_unchecked(1, v);
9083+}
9084
9085 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9086 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9087
9088 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9089+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9090+{
9091+ return cmpxchg(&v->counter, old, new);
9092+}
9093 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9094+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9095+{
9096+ return xchg(&v->counter, new);
9097+}
9098
9099 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9100 {
9101- int c, old;
9102+ int c, old, new;
9103 c = atomic_read(v);
9104 for (;;) {
9105- if (unlikely(c == (u)))
9106+ if (unlikely(c == u))
9107 break;
9108- old = atomic_cmpxchg((v), c, c + (a));
9109+
9110+ asm volatile("addcc %2, %0, %0\n"
9111+
9112+#ifdef CONFIG_PAX_REFCOUNT
9113+ "tvs %%icc, 6\n"
9114+#endif
9115+
9116+ : "=r" (new)
9117+ : "0" (c), "ir" (a)
9118+ : "cc");
9119+
9120+ old = atomic_cmpxchg(v, c, new);
9121 if (likely(old == c))
9122 break;
9123 c = old;
9124@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9125 #define atomic64_cmpxchg(v, o, n) \
9126 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9127 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9128+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9129+{
9130+ return xchg(&v->counter, new);
9131+}
9132
9133 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9134 {
9135- long c, old;
9136+ long c, old, new;
9137 c = atomic64_read(v);
9138 for (;;) {
9139- if (unlikely(c == (u)))
9140+ if (unlikely(c == u))
9141 break;
9142- old = atomic64_cmpxchg((v), c, c + (a));
9143+
9144+ asm volatile("addcc %2, %0, %0\n"
9145+
9146+#ifdef CONFIG_PAX_REFCOUNT
9147+ "tvs %%xcc, 6\n"
9148+#endif
9149+
9150+ : "=r" (new)
9151+ : "0" (c), "ir" (a)
9152+ : "cc");
9153+
9154+ old = atomic64_cmpxchg(v, c, new);
9155 if (likely(old == c))
9156 break;
9157 c = old;
9158 }
9159- return c != (u);
9160+ return c != u;
9161 }
9162
9163 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9164diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9165index 5bb6991..5c2132e 100644
9166--- a/arch/sparc/include/asm/cache.h
9167+++ b/arch/sparc/include/asm/cache.h
9168@@ -7,10 +7,12 @@
9169 #ifndef _SPARC_CACHE_H
9170 #define _SPARC_CACHE_H
9171
9172+#include <linux/const.h>
9173+
9174 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9175
9176 #define L1_CACHE_SHIFT 5
9177-#define L1_CACHE_BYTES 32
9178+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9179
9180 #ifdef CONFIG_SPARC32
9181 #define SMP_CACHE_BYTES_SHIFT 5
9182diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9183index a24e41f..47677ff 100644
9184--- a/arch/sparc/include/asm/elf_32.h
9185+++ b/arch/sparc/include/asm/elf_32.h
9186@@ -114,6 +114,13 @@ typedef struct {
9187
9188 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9189
9190+#ifdef CONFIG_PAX_ASLR
9191+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9192+
9193+#define PAX_DELTA_MMAP_LEN 16
9194+#define PAX_DELTA_STACK_LEN 16
9195+#endif
9196+
9197 /* This yields a mask that user programs can use to figure out what
9198 instruction set this cpu supports. This can NOT be done in userspace
9199 on Sparc. */
9200diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9201index 370ca1e..d4f4a98 100644
9202--- a/arch/sparc/include/asm/elf_64.h
9203+++ b/arch/sparc/include/asm/elf_64.h
9204@@ -189,6 +189,13 @@ typedef struct {
9205 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9206 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9207
9208+#ifdef CONFIG_PAX_ASLR
9209+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9210+
9211+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9212+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9213+#endif
9214+
9215 extern unsigned long sparc64_elf_hwcap;
9216 #define ELF_HWCAP sparc64_elf_hwcap
9217
9218diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9219index 9b1c36d..209298b 100644
9220--- a/arch/sparc/include/asm/pgalloc_32.h
9221+++ b/arch/sparc/include/asm/pgalloc_32.h
9222@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9223 }
9224
9225 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9226+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9227
9228 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9229 unsigned long address)
9230diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9231index bcfe063..b333142 100644
9232--- a/arch/sparc/include/asm/pgalloc_64.h
9233+++ b/arch/sparc/include/asm/pgalloc_64.h
9234@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9235 }
9236
9237 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9238+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9239
9240 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9241 {
9242diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9243index 502f632..da1917f 100644
9244--- a/arch/sparc/include/asm/pgtable_32.h
9245+++ b/arch/sparc/include/asm/pgtable_32.h
9246@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9247 #define PAGE_SHARED SRMMU_PAGE_SHARED
9248 #define PAGE_COPY SRMMU_PAGE_COPY
9249 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9250+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9251+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9252+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9253 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9254
9255 /* Top-level page directory - dummy used by init-mm.
9256@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9257
9258 /* xwr */
9259 #define __P000 PAGE_NONE
9260-#define __P001 PAGE_READONLY
9261-#define __P010 PAGE_COPY
9262-#define __P011 PAGE_COPY
9263+#define __P001 PAGE_READONLY_NOEXEC
9264+#define __P010 PAGE_COPY_NOEXEC
9265+#define __P011 PAGE_COPY_NOEXEC
9266 #define __P100 PAGE_READONLY
9267 #define __P101 PAGE_READONLY
9268 #define __P110 PAGE_COPY
9269 #define __P111 PAGE_COPY
9270
9271 #define __S000 PAGE_NONE
9272-#define __S001 PAGE_READONLY
9273-#define __S010 PAGE_SHARED
9274-#define __S011 PAGE_SHARED
9275+#define __S001 PAGE_READONLY_NOEXEC
9276+#define __S010 PAGE_SHARED_NOEXEC
9277+#define __S011 PAGE_SHARED_NOEXEC
9278 #define __S100 PAGE_READONLY
9279 #define __S101 PAGE_READONLY
9280 #define __S110 PAGE_SHARED
9281diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9282index 79da178..c2eede8 100644
9283--- a/arch/sparc/include/asm/pgtsrmmu.h
9284+++ b/arch/sparc/include/asm/pgtsrmmu.h
9285@@ -115,6 +115,11 @@
9286 SRMMU_EXEC | SRMMU_REF)
9287 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9288 SRMMU_EXEC | SRMMU_REF)
9289+
9290+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9291+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9292+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9293+
9294 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9295 SRMMU_DIRTY | SRMMU_REF)
9296
9297diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9298index 9689176..63c18ea 100644
9299--- a/arch/sparc/include/asm/spinlock_64.h
9300+++ b/arch/sparc/include/asm/spinlock_64.h
9301@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9302
9303 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9304
9305-static void inline arch_read_lock(arch_rwlock_t *lock)
9306+static inline void arch_read_lock(arch_rwlock_t *lock)
9307 {
9308 unsigned long tmp1, tmp2;
9309
9310 __asm__ __volatile__ (
9311 "1: ldsw [%2], %0\n"
9312 " brlz,pn %0, 2f\n"
9313-"4: add %0, 1, %1\n"
9314+"4: addcc %0, 1, %1\n"
9315+
9316+#ifdef CONFIG_PAX_REFCOUNT
9317+" tvs %%icc, 6\n"
9318+#endif
9319+
9320 " cas [%2], %0, %1\n"
9321 " cmp %0, %1\n"
9322 " bne,pn %%icc, 1b\n"
9323@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9324 " .previous"
9325 : "=&r" (tmp1), "=&r" (tmp2)
9326 : "r" (lock)
9327- : "memory");
9328+ : "memory", "cc");
9329 }
9330
9331-static int inline arch_read_trylock(arch_rwlock_t *lock)
9332+static inline int arch_read_trylock(arch_rwlock_t *lock)
9333 {
9334 int tmp1, tmp2;
9335
9336@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9337 "1: ldsw [%2], %0\n"
9338 " brlz,a,pn %0, 2f\n"
9339 " mov 0, %0\n"
9340-" add %0, 1, %1\n"
9341+" addcc %0, 1, %1\n"
9342+
9343+#ifdef CONFIG_PAX_REFCOUNT
9344+" tvs %%icc, 6\n"
9345+#endif
9346+
9347 " cas [%2], %0, %1\n"
9348 " cmp %0, %1\n"
9349 " bne,pn %%icc, 1b\n"
9350@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9351 return tmp1;
9352 }
9353
9354-static void inline arch_read_unlock(arch_rwlock_t *lock)
9355+static inline void arch_read_unlock(arch_rwlock_t *lock)
9356 {
9357 unsigned long tmp1, tmp2;
9358
9359 __asm__ __volatile__(
9360 "1: lduw [%2], %0\n"
9361-" sub %0, 1, %1\n"
9362+" subcc %0, 1, %1\n"
9363+
9364+#ifdef CONFIG_PAX_REFCOUNT
9365+" tvs %%icc, 6\n"
9366+#endif
9367+
9368 " cas [%2], %0, %1\n"
9369 " cmp %0, %1\n"
9370 " bne,pn %%xcc, 1b\n"
9371@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9372 : "memory");
9373 }
9374
9375-static void inline arch_write_lock(arch_rwlock_t *lock)
9376+static inline void arch_write_lock(arch_rwlock_t *lock)
9377 {
9378 unsigned long mask, tmp1, tmp2;
9379
9380@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9381 : "memory");
9382 }
9383
9384-static void inline arch_write_unlock(arch_rwlock_t *lock)
9385+static inline void arch_write_unlock(arch_rwlock_t *lock)
9386 {
9387 __asm__ __volatile__(
9388 " stw %%g0, [%0]"
9389@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9390 : "memory");
9391 }
9392
9393-static int inline arch_write_trylock(arch_rwlock_t *lock)
9394+static inline int arch_write_trylock(arch_rwlock_t *lock)
9395 {
9396 unsigned long mask, tmp1, tmp2, result;
9397
9398diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9399index 96efa7a..16858bf 100644
9400--- a/arch/sparc/include/asm/thread_info_32.h
9401+++ b/arch/sparc/include/asm/thread_info_32.h
9402@@ -49,6 +49,8 @@ struct thread_info {
9403 unsigned long w_saved;
9404
9405 struct restart_block restart_block;
9406+
9407+ unsigned long lowest_stack;
9408 };
9409
9410 /*
9411diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9412index a5f01ac..703b554 100644
9413--- a/arch/sparc/include/asm/thread_info_64.h
9414+++ b/arch/sparc/include/asm/thread_info_64.h
9415@@ -63,6 +63,8 @@ struct thread_info {
9416 struct pt_regs *kern_una_regs;
9417 unsigned int kern_una_insn;
9418
9419+ unsigned long lowest_stack;
9420+
9421 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9422 };
9423
9424@@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
9425 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
9426 /* flag bit 4 is available */
9427 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9428-/* flag bit 6 is available */
9429+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
9430 #define TIF_32BIT 7 /* 32-bit binary */
9431 #define TIF_NOHZ 8 /* in adaptive nohz mode */
9432 #define TIF_SECCOMP 9 /* secure computing */
9433 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9434 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9435+
9436 /* NOTE: Thread flags >= 12 should be ones we have no interest
9437 * in using in assembly, else we can't use the mask as
9438 * an immediate value in instructions such as andcc.
9439@@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9440 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9441 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9442 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9443+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9444
9445 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9446 _TIF_DO_NOTIFY_RESUME_MASK | \
9447 _TIF_NEED_RESCHED)
9448 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9449
9450+#define _TIF_WORK_SYSCALL \
9451+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9452+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
9453+
9454+
9455 /*
9456 * Thread-synchronous status.
9457 *
9458diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9459index 0167d26..767bb0c 100644
9460--- a/arch/sparc/include/asm/uaccess.h
9461+++ b/arch/sparc/include/asm/uaccess.h
9462@@ -1,5 +1,6 @@
9463 #ifndef ___ASM_SPARC_UACCESS_H
9464 #define ___ASM_SPARC_UACCESS_H
9465+
9466 #if defined(__sparc__) && defined(__arch64__)
9467 #include <asm/uaccess_64.h>
9468 #else
9469diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9470index 53a28dd..50c38c3 100644
9471--- a/arch/sparc/include/asm/uaccess_32.h
9472+++ b/arch/sparc/include/asm/uaccess_32.h
9473@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9474
9475 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9476 {
9477- if (n && __access_ok((unsigned long) to, n))
9478+ if ((long)n < 0)
9479+ return n;
9480+
9481+ if (n && __access_ok((unsigned long) to, n)) {
9482+ if (!__builtin_constant_p(n))
9483+ check_object_size(from, n, true);
9484 return __copy_user(to, (__force void __user *) from, n);
9485- else
9486+ } else
9487 return n;
9488 }
9489
9490 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9491 {
9492+ if ((long)n < 0)
9493+ return n;
9494+
9495+ if (!__builtin_constant_p(n))
9496+ check_object_size(from, n, true);
9497+
9498 return __copy_user(to, (__force void __user *) from, n);
9499 }
9500
9501 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9502 {
9503- if (n && __access_ok((unsigned long) from, n))
9504+ if ((long)n < 0)
9505+ return n;
9506+
9507+ if (n && __access_ok((unsigned long) from, n)) {
9508+ if (!__builtin_constant_p(n))
9509+ check_object_size(to, n, false);
9510 return __copy_user((__force void __user *) to, from, n);
9511- else
9512+ } else
9513 return n;
9514 }
9515
9516 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
9517 {
9518+ if ((long)n < 0)
9519+ return n;
9520+
9521 return __copy_user((__force void __user *) to, from, n);
9522 }
9523
9524diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
9525index ad7e178..c9e7423 100644
9526--- a/arch/sparc/include/asm/uaccess_64.h
9527+++ b/arch/sparc/include/asm/uaccess_64.h
9528@@ -10,6 +10,7 @@
9529 #include <linux/compiler.h>
9530 #include <linux/string.h>
9531 #include <linux/thread_info.h>
9532+#include <linux/kernel.h>
9533 #include <asm/asi.h>
9534 #include <asm/spitfire.h>
9535 #include <asm-generic/uaccess-unaligned.h>
9536@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
9537 static inline unsigned long __must_check
9538 copy_from_user(void *to, const void __user *from, unsigned long size)
9539 {
9540- unsigned long ret = ___copy_from_user(to, from, size);
9541+ unsigned long ret;
9542
9543+ if ((long)size < 0 || size > INT_MAX)
9544+ return size;
9545+
9546+ if (!__builtin_constant_p(size))
9547+ check_object_size(to, size, false);
9548+
9549+ ret = ___copy_from_user(to, from, size);
9550 if (unlikely(ret))
9551 ret = copy_from_user_fixup(to, from, size);
9552
9553@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
9554 static inline unsigned long __must_check
9555 copy_to_user(void __user *to, const void *from, unsigned long size)
9556 {
9557- unsigned long ret = ___copy_to_user(to, from, size);
9558+ unsigned long ret;
9559
9560+ if ((long)size < 0 || size > INT_MAX)
9561+ return size;
9562+
9563+ if (!__builtin_constant_p(size))
9564+ check_object_size(from, size, true);
9565+
9566+ ret = ___copy_to_user(to, from, size);
9567 if (unlikely(ret))
9568 ret = copy_to_user_fixup(to, from, size);
9569 return ret;
9570diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
9571index d15cc17..d0ae796 100644
9572--- a/arch/sparc/kernel/Makefile
9573+++ b/arch/sparc/kernel/Makefile
9574@@ -4,7 +4,7 @@
9575 #
9576
9577 asflags-y := -ansi
9578-ccflags-y := -Werror
9579+#ccflags-y := -Werror
9580
9581 extra-y := head_$(BITS).o
9582
9583diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
9584index fdd819d..5af08c8 100644
9585--- a/arch/sparc/kernel/process_32.c
9586+++ b/arch/sparc/kernel/process_32.c
9587@@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
9588
9589 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
9590 r->psr, r->pc, r->npc, r->y, print_tainted());
9591- printk("PC: <%pS>\n", (void *) r->pc);
9592+ printk("PC: <%pA>\n", (void *) r->pc);
9593 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9594 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
9595 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
9596 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9597 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
9598 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
9599- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
9600+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
9601
9602 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9603 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
9604@@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9605 rw = (struct reg_window32 *) fp;
9606 pc = rw->ins[7];
9607 printk("[%08lx : ", pc);
9608- printk("%pS ] ", (void *) pc);
9609+ printk("%pA ] ", (void *) pc);
9610 fp = rw->ins[6];
9611 } while (++count < 16);
9612 printk("\n");
9613diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
9614index 32a280e..84fc6a9 100644
9615--- a/arch/sparc/kernel/process_64.c
9616+++ b/arch/sparc/kernel/process_64.c
9617@@ -159,7 +159,7 @@ static void show_regwindow(struct pt_regs *regs)
9618 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
9619 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
9620 if (regs->tstate & TSTATE_PRIV)
9621- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
9622+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
9623 }
9624
9625 void show_regs(struct pt_regs *regs)
9626@@ -168,7 +168,7 @@ void show_regs(struct pt_regs *regs)
9627
9628 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
9629 regs->tpc, regs->tnpc, regs->y, print_tainted());
9630- printk("TPC: <%pS>\n", (void *) regs->tpc);
9631+ printk("TPC: <%pA>\n", (void *) regs->tpc);
9632 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
9633 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
9634 regs->u_regs[3]);
9635@@ -181,7 +181,7 @@ void show_regs(struct pt_regs *regs)
9636 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
9637 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
9638 regs->u_regs[15]);
9639- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
9640+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
9641 show_regwindow(regs);
9642 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
9643 }
9644@@ -270,7 +270,7 @@ void arch_trigger_all_cpu_backtrace(void)
9645 ((tp && tp->task) ? tp->task->pid : -1));
9646
9647 if (gp->tstate & TSTATE_PRIV) {
9648- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
9649+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
9650 (void *) gp->tpc,
9651 (void *) gp->o7,
9652 (void *) gp->i7,
9653diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
9654index 79cc0d1..ec62734 100644
9655--- a/arch/sparc/kernel/prom_common.c
9656+++ b/arch/sparc/kernel/prom_common.c
9657@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
9658
9659 unsigned int prom_early_allocated __initdata;
9660
9661-static struct of_pdt_ops prom_sparc_ops __initdata = {
9662+static struct of_pdt_ops prom_sparc_ops __initconst = {
9663 .nextprop = prom_common_nextprop,
9664 .getproplen = prom_getproplen,
9665 .getproperty = prom_getproperty,
9666diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
9667index c13c9f2..d572c34 100644
9668--- a/arch/sparc/kernel/ptrace_64.c
9669+++ b/arch/sparc/kernel/ptrace_64.c
9670@@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
9671 return ret;
9672 }
9673
9674+#ifdef CONFIG_GRKERNSEC_SETXID
9675+extern void gr_delayed_cred_worker(void);
9676+#endif
9677+
9678 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9679 {
9680 int ret = 0;
9681@@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9682 if (test_thread_flag(TIF_NOHZ))
9683 user_exit();
9684
9685+#ifdef CONFIG_GRKERNSEC_SETXID
9686+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9687+ gr_delayed_cred_worker();
9688+#endif
9689+
9690 if (test_thread_flag(TIF_SYSCALL_TRACE))
9691 ret = tracehook_report_syscall_entry(regs);
9692
9693@@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
9694 if (test_thread_flag(TIF_NOHZ))
9695 user_exit();
9696
9697+#ifdef CONFIG_GRKERNSEC_SETXID
9698+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9699+ gr_delayed_cred_worker();
9700+#endif
9701+
9702 audit_syscall_exit(regs);
9703
9704 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9705diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
9706index b085311..6f885f7 100644
9707--- a/arch/sparc/kernel/smp_64.c
9708+++ b/arch/sparc/kernel/smp_64.c
9709@@ -870,8 +870,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
9710 extern unsigned long xcall_flush_dcache_page_spitfire;
9711
9712 #ifdef CONFIG_DEBUG_DCFLUSH
9713-extern atomic_t dcpage_flushes;
9714-extern atomic_t dcpage_flushes_xcall;
9715+extern atomic_unchecked_t dcpage_flushes;
9716+extern atomic_unchecked_t dcpage_flushes_xcall;
9717 #endif
9718
9719 static inline void __local_flush_dcache_page(struct page *page)
9720@@ -895,7 +895,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9721 return;
9722
9723 #ifdef CONFIG_DEBUG_DCFLUSH
9724- atomic_inc(&dcpage_flushes);
9725+ atomic_inc_unchecked(&dcpage_flushes);
9726 #endif
9727
9728 this_cpu = get_cpu();
9729@@ -919,7 +919,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9730 xcall_deliver(data0, __pa(pg_addr),
9731 (u64) pg_addr, cpumask_of(cpu));
9732 #ifdef CONFIG_DEBUG_DCFLUSH
9733- atomic_inc(&dcpage_flushes_xcall);
9734+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9735 #endif
9736 }
9737 }
9738@@ -938,7 +938,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9739 preempt_disable();
9740
9741 #ifdef CONFIG_DEBUG_DCFLUSH
9742- atomic_inc(&dcpage_flushes);
9743+ atomic_inc_unchecked(&dcpage_flushes);
9744 #endif
9745 data0 = 0;
9746 pg_addr = page_address(page);
9747@@ -955,7 +955,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9748 xcall_deliver(data0, __pa(pg_addr),
9749 (u64) pg_addr, cpu_online_mask);
9750 #ifdef CONFIG_DEBUG_DCFLUSH
9751- atomic_inc(&dcpage_flushes_xcall);
9752+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9753 #endif
9754 }
9755 __local_flush_dcache_page(page);
9756diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
9757index 3a8d184..49498a8 100644
9758--- a/arch/sparc/kernel/sys_sparc_32.c
9759+++ b/arch/sparc/kernel/sys_sparc_32.c
9760@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9761 if (len > TASK_SIZE - PAGE_SIZE)
9762 return -ENOMEM;
9763 if (!addr)
9764- addr = TASK_UNMAPPED_BASE;
9765+ addr = current->mm->mmap_base;
9766
9767 info.flags = 0;
9768 info.length = len;
9769diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
9770index beb0b5a..5a153f7 100644
9771--- a/arch/sparc/kernel/sys_sparc_64.c
9772+++ b/arch/sparc/kernel/sys_sparc_64.c
9773@@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9774 struct vm_area_struct * vma;
9775 unsigned long task_size = TASK_SIZE;
9776 int do_color_align;
9777+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9778 struct vm_unmapped_area_info info;
9779
9780 if (flags & MAP_FIXED) {
9781 /* We do not accept a shared mapping if it would violate
9782 * cache aliasing constraints.
9783 */
9784- if ((flags & MAP_SHARED) &&
9785+ if ((filp || (flags & MAP_SHARED)) &&
9786 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9787 return -EINVAL;
9788 return addr;
9789@@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9790 if (filp || (flags & MAP_SHARED))
9791 do_color_align = 1;
9792
9793+#ifdef CONFIG_PAX_RANDMMAP
9794+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9795+#endif
9796+
9797 if (addr) {
9798 if (do_color_align)
9799 addr = COLOR_ALIGN(addr, pgoff);
9800@@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9801 addr = PAGE_ALIGN(addr);
9802
9803 vma = find_vma(mm, addr);
9804- if (task_size - len >= addr &&
9805- (!vma || addr + len <= vma->vm_start))
9806+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9807 return addr;
9808 }
9809
9810 info.flags = 0;
9811 info.length = len;
9812- info.low_limit = TASK_UNMAPPED_BASE;
9813+ info.low_limit = mm->mmap_base;
9814 info.high_limit = min(task_size, VA_EXCLUDE_START);
9815 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9816 info.align_offset = pgoff << PAGE_SHIFT;
9817+ info.threadstack_offset = offset;
9818 addr = vm_unmapped_area(&info);
9819
9820 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9821 VM_BUG_ON(addr != -ENOMEM);
9822 info.low_limit = VA_EXCLUDE_END;
9823+
9824+#ifdef CONFIG_PAX_RANDMMAP
9825+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9826+ info.low_limit += mm->delta_mmap;
9827+#endif
9828+
9829 info.high_limit = task_size;
9830 addr = vm_unmapped_area(&info);
9831 }
9832@@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9833 unsigned long task_size = STACK_TOP32;
9834 unsigned long addr = addr0;
9835 int do_color_align;
9836+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9837 struct vm_unmapped_area_info info;
9838
9839 /* This should only ever run for 32-bit processes. */
9840@@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9841 /* We do not accept a shared mapping if it would violate
9842 * cache aliasing constraints.
9843 */
9844- if ((flags & MAP_SHARED) &&
9845+ if ((filp || (flags & MAP_SHARED)) &&
9846 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9847 return -EINVAL;
9848 return addr;
9849@@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9850 if (filp || (flags & MAP_SHARED))
9851 do_color_align = 1;
9852
9853+#ifdef CONFIG_PAX_RANDMMAP
9854+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9855+#endif
9856+
9857 /* requesting a specific address */
9858 if (addr) {
9859 if (do_color_align)
9860@@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9861 addr = PAGE_ALIGN(addr);
9862
9863 vma = find_vma(mm, addr);
9864- if (task_size - len >= addr &&
9865- (!vma || addr + len <= vma->vm_start))
9866+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9867 return addr;
9868 }
9869
9870@@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9871 info.high_limit = mm->mmap_base;
9872 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9873 info.align_offset = pgoff << PAGE_SHIFT;
9874+ info.threadstack_offset = offset;
9875 addr = vm_unmapped_area(&info);
9876
9877 /*
9878@@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9879 VM_BUG_ON(addr != -ENOMEM);
9880 info.flags = 0;
9881 info.low_limit = TASK_UNMAPPED_BASE;
9882+
9883+#ifdef CONFIG_PAX_RANDMMAP
9884+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9885+ info.low_limit += mm->delta_mmap;
9886+#endif
9887+
9888 info.high_limit = STACK_TOP32;
9889 addr = vm_unmapped_area(&info);
9890 }
9891@@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
9892 EXPORT_SYMBOL(get_fb_unmapped_area);
9893
9894 /* Essentially the same as PowerPC. */
9895-static unsigned long mmap_rnd(void)
9896+static unsigned long mmap_rnd(struct mm_struct *mm)
9897 {
9898 unsigned long rnd = 0UL;
9899
9900+#ifdef CONFIG_PAX_RANDMMAP
9901+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9902+#endif
9903+
9904 if (current->flags & PF_RANDOMIZE) {
9905 unsigned long val = get_random_int();
9906 if (test_thread_flag(TIF_32BIT))
9907@@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
9908
9909 void arch_pick_mmap_layout(struct mm_struct *mm)
9910 {
9911- unsigned long random_factor = mmap_rnd();
9912+ unsigned long random_factor = mmap_rnd(mm);
9913 unsigned long gap;
9914
9915 /*
9916@@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9917 gap == RLIM_INFINITY ||
9918 sysctl_legacy_va_layout) {
9919 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
9920+
9921+#ifdef CONFIG_PAX_RANDMMAP
9922+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9923+ mm->mmap_base += mm->delta_mmap;
9924+#endif
9925+
9926 mm->get_unmapped_area = arch_get_unmapped_area;
9927 } else {
9928 /* We know it's 32-bit */
9929@@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9930 gap = (task_size / 6 * 5);
9931
9932 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
9933+
9934+#ifdef CONFIG_PAX_RANDMMAP
9935+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9936+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9937+#endif
9938+
9939 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9940 }
9941 }
9942diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
9943index 87729ff..192f9d8 100644
9944--- a/arch/sparc/kernel/syscalls.S
9945+++ b/arch/sparc/kernel/syscalls.S
9946@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
9947 #endif
9948 .align 32
9949 1: ldx [%g6 + TI_FLAGS], %l5
9950- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
9951+ andcc %l5, _TIF_WORK_SYSCALL, %g0
9952 be,pt %icc, rtrap
9953 nop
9954 call syscall_trace_leave
9955@@ -184,7 +184,7 @@ linux_sparc_syscall32:
9956
9957 srl %i3, 0, %o3 ! IEU0
9958 srl %i2, 0, %o2 ! IEU0 Group
9959- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
9960+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9961 bne,pn %icc, linux_syscall_trace32 ! CTI
9962 mov %i0, %l5 ! IEU1
9963 5: call %l7 ! CTI Group brk forced
9964@@ -207,7 +207,7 @@ linux_sparc_syscall:
9965
9966 mov %i3, %o3 ! IEU1
9967 mov %i4, %o4 ! IEU0 Group
9968- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
9969+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9970 bne,pn %icc, linux_syscall_trace ! CTI Group
9971 mov %i0, %l5 ! IEU0
9972 2: call %l7 ! CTI Group brk forced
9973@@ -223,7 +223,7 @@ ret_sys_call:
9974
9975 cmp %o0, -ERESTART_RESTARTBLOCK
9976 bgeu,pn %xcc, 1f
9977- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
9978+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9979 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
9980
9981 2:
9982diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
9983index 6629829..036032d 100644
9984--- a/arch/sparc/kernel/traps_32.c
9985+++ b/arch/sparc/kernel/traps_32.c
9986@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
9987 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
9988 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
9989
9990+extern void gr_handle_kernel_exploit(void);
9991+
9992 void die_if_kernel(char *str, struct pt_regs *regs)
9993 {
9994 static int die_counter;
9995@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9996 count++ < 30 &&
9997 (((unsigned long) rw) >= PAGE_OFFSET) &&
9998 !(((unsigned long) rw) & 0x7)) {
9999- printk("Caller[%08lx]: %pS\n", rw->ins[7],
10000+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
10001 (void *) rw->ins[7]);
10002 rw = (struct reg_window32 *)rw->ins[6];
10003 }
10004 }
10005 printk("Instruction DUMP:");
10006 instruction_dump ((unsigned long *) regs->pc);
10007- if(regs->psr & PSR_PS)
10008+ if(regs->psr & PSR_PS) {
10009+ gr_handle_kernel_exploit();
10010 do_exit(SIGKILL);
10011+ }
10012 do_exit(SIGSEGV);
10013 }
10014
10015diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10016index 4ced92f..965eeed 100644
10017--- a/arch/sparc/kernel/traps_64.c
10018+++ b/arch/sparc/kernel/traps_64.c
10019@@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10020 i + 1,
10021 p->trapstack[i].tstate, p->trapstack[i].tpc,
10022 p->trapstack[i].tnpc, p->trapstack[i].tt);
10023- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10024+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10025 }
10026 }
10027
10028@@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10029
10030 lvl -= 0x100;
10031 if (regs->tstate & TSTATE_PRIV) {
10032+
10033+#ifdef CONFIG_PAX_REFCOUNT
10034+ if (lvl == 6)
10035+ pax_report_refcount_overflow(regs);
10036+#endif
10037+
10038 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10039 die_if_kernel(buffer, regs);
10040 }
10041@@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10042 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10043 {
10044 char buffer[32];
10045-
10046+
10047 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10048 0, lvl, SIGTRAP) == NOTIFY_STOP)
10049 return;
10050
10051+#ifdef CONFIG_PAX_REFCOUNT
10052+ if (lvl == 6)
10053+ pax_report_refcount_overflow(regs);
10054+#endif
10055+
10056 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10057
10058 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10059@@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10060 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10061 printk("%s" "ERROR(%d): ",
10062 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10063- printk("TPC<%pS>\n", (void *) regs->tpc);
10064+ printk("TPC<%pA>\n", (void *) regs->tpc);
10065 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10066 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10067 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10068@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10069 smp_processor_id(),
10070 (type & 0x1) ? 'I' : 'D',
10071 regs->tpc);
10072- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10073+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10074 panic("Irrecoverable Cheetah+ parity error.");
10075 }
10076
10077@@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10078 smp_processor_id(),
10079 (type & 0x1) ? 'I' : 'D',
10080 regs->tpc);
10081- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10082+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10083 }
10084
10085 struct sun4v_error_entry {
10086@@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10087 /*0x38*/u64 reserved_5;
10088 };
10089
10090-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10091-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10092+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10093+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10094
10095 static const char *sun4v_err_type_to_str(u8 type)
10096 {
10097@@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10098 }
10099
10100 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10101- int cpu, const char *pfx, atomic_t *ocnt)
10102+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10103 {
10104 u64 *raw_ptr = (u64 *) ent;
10105 u32 attrs;
10106@@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10107
10108 show_regs(regs);
10109
10110- if ((cnt = atomic_read(ocnt)) != 0) {
10111- atomic_set(ocnt, 0);
10112+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10113+ atomic_set_unchecked(ocnt, 0);
10114 wmb();
10115 printk("%s: Queue overflowed %d times.\n",
10116 pfx, cnt);
10117@@ -2046,7 +2057,7 @@ out:
10118 */
10119 void sun4v_resum_overflow(struct pt_regs *regs)
10120 {
10121- atomic_inc(&sun4v_resum_oflow_cnt);
10122+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10123 }
10124
10125 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10126@@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10127 /* XXX Actually even this can make not that much sense. Perhaps
10128 * XXX we should just pull the plug and panic directly from here?
10129 */
10130- atomic_inc(&sun4v_nonresum_oflow_cnt);
10131+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10132 }
10133
10134 unsigned long sun4v_err_itlb_vaddr;
10135@@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10136
10137 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10138 regs->tpc, tl);
10139- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10140+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10141 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10142- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10143+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10144 (void *) regs->u_regs[UREG_I7]);
10145 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10146 "pte[%lx] error[%lx]\n",
10147@@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10148
10149 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10150 regs->tpc, tl);
10151- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10152+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10153 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10154- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10155+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10156 (void *) regs->u_regs[UREG_I7]);
10157 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10158 "pte[%lx] error[%lx]\n",
10159@@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10160 fp = (unsigned long)sf->fp + STACK_BIAS;
10161 }
10162
10163- printk(" [%016lx] %pS\n", pc, (void *) pc);
10164+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10165 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10166 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10167 int index = tsk->curr_ret_stack;
10168 if (tsk->ret_stack && index >= graph) {
10169 pc = tsk->ret_stack[index - graph].ret;
10170- printk(" [%016lx] %pS\n", pc, (void *) pc);
10171+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10172 graph++;
10173 }
10174 }
10175@@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10176 return (struct reg_window *) (fp + STACK_BIAS);
10177 }
10178
10179+extern void gr_handle_kernel_exploit(void);
10180+
10181 void die_if_kernel(char *str, struct pt_regs *regs)
10182 {
10183 static int die_counter;
10184@@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10185 while (rw &&
10186 count++ < 30 &&
10187 kstack_valid(tp, (unsigned long) rw)) {
10188- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10189+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10190 (void *) rw->ins[7]);
10191
10192 rw = kernel_stack_up(rw);
10193@@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10194 }
10195 user_instruction_dump ((unsigned int __user *) regs->tpc);
10196 }
10197- if (regs->tstate & TSTATE_PRIV)
10198+ if (regs->tstate & TSTATE_PRIV) {
10199+ gr_handle_kernel_exploit();
10200 do_exit(SIGKILL);
10201+ }
10202 do_exit(SIGSEGV);
10203 }
10204 EXPORT_SYMBOL(die_if_kernel);
10205diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10206index 3c1a7cb..73e1923 100644
10207--- a/arch/sparc/kernel/unaligned_64.c
10208+++ b/arch/sparc/kernel/unaligned_64.c
10209@@ -289,7 +289,7 @@ static void log_unaligned(struct pt_regs *regs)
10210 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10211
10212 if (__ratelimit(&ratelimit)) {
10213- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10214+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10215 regs->tpc, (void *) regs->tpc);
10216 }
10217 }
10218diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10219index dbe119b..089c7c1 100644
10220--- a/arch/sparc/lib/Makefile
10221+++ b/arch/sparc/lib/Makefile
10222@@ -2,7 +2,7 @@
10223 #
10224
10225 asflags-y := -ansi -DST_DIV0=0x02
10226-ccflags-y := -Werror
10227+#ccflags-y := -Werror
10228
10229 lib-$(CONFIG_SPARC32) += ashrdi3.o
10230 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10231diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10232index 85c233d..68500e0 100644
10233--- a/arch/sparc/lib/atomic_64.S
10234+++ b/arch/sparc/lib/atomic_64.S
10235@@ -17,7 +17,12 @@
10236 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10237 BACKOFF_SETUP(%o2)
10238 1: lduw [%o1], %g1
10239- add %g1, %o0, %g7
10240+ addcc %g1, %o0, %g7
10241+
10242+#ifdef CONFIG_PAX_REFCOUNT
10243+ tvs %icc, 6
10244+#endif
10245+
10246 cas [%o1], %g1, %g7
10247 cmp %g1, %g7
10248 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10249@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10250 2: BACKOFF_SPIN(%o2, %o3, 1b)
10251 ENDPROC(atomic_add)
10252
10253+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10254+ BACKOFF_SETUP(%o2)
10255+1: lduw [%o1], %g1
10256+ add %g1, %o0, %g7
10257+ cas [%o1], %g1, %g7
10258+ cmp %g1, %g7
10259+ bne,pn %icc, 2f
10260+ nop
10261+ retl
10262+ nop
10263+2: BACKOFF_SPIN(%o2, %o3, 1b)
10264+ENDPROC(atomic_add_unchecked)
10265+
10266 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10267 BACKOFF_SETUP(%o2)
10268 1: lduw [%o1], %g1
10269- sub %g1, %o0, %g7
10270+ subcc %g1, %o0, %g7
10271+
10272+#ifdef CONFIG_PAX_REFCOUNT
10273+ tvs %icc, 6
10274+#endif
10275+
10276 cas [%o1], %g1, %g7
10277 cmp %g1, %g7
10278 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10279@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10280 2: BACKOFF_SPIN(%o2, %o3, 1b)
10281 ENDPROC(atomic_sub)
10282
10283+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10284+ BACKOFF_SETUP(%o2)
10285+1: lduw [%o1], %g1
10286+ sub %g1, %o0, %g7
10287+ cas [%o1], %g1, %g7
10288+ cmp %g1, %g7
10289+ bne,pn %icc, 2f
10290+ nop
10291+ retl
10292+ nop
10293+2: BACKOFF_SPIN(%o2, %o3, 1b)
10294+ENDPROC(atomic_sub_unchecked)
10295+
10296 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10297 BACKOFF_SETUP(%o2)
10298 1: lduw [%o1], %g1
10299- add %g1, %o0, %g7
10300+ addcc %g1, %o0, %g7
10301+
10302+#ifdef CONFIG_PAX_REFCOUNT
10303+ tvs %icc, 6
10304+#endif
10305+
10306 cas [%o1], %g1, %g7
10307 cmp %g1, %g7
10308 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10309@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10310 2: BACKOFF_SPIN(%o2, %o3, 1b)
10311 ENDPROC(atomic_add_ret)
10312
10313+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10314+ BACKOFF_SETUP(%o2)
10315+1: lduw [%o1], %g1
10316+ addcc %g1, %o0, %g7
10317+ cas [%o1], %g1, %g7
10318+ cmp %g1, %g7
10319+ bne,pn %icc, 2f
10320+ add %g7, %o0, %g7
10321+ sra %g7, 0, %o0
10322+ retl
10323+ nop
10324+2: BACKOFF_SPIN(%o2, %o3, 1b)
10325+ENDPROC(atomic_add_ret_unchecked)
10326+
10327 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10328 BACKOFF_SETUP(%o2)
10329 1: lduw [%o1], %g1
10330- sub %g1, %o0, %g7
10331+ subcc %g1, %o0, %g7
10332+
10333+#ifdef CONFIG_PAX_REFCOUNT
10334+ tvs %icc, 6
10335+#endif
10336+
10337 cas [%o1], %g1, %g7
10338 cmp %g1, %g7
10339 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10340@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10341 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10342 BACKOFF_SETUP(%o2)
10343 1: ldx [%o1], %g1
10344- add %g1, %o0, %g7
10345+ addcc %g1, %o0, %g7
10346+
10347+#ifdef CONFIG_PAX_REFCOUNT
10348+ tvs %xcc, 6
10349+#endif
10350+
10351 casx [%o1], %g1, %g7
10352 cmp %g1, %g7
10353 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10354@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10355 2: BACKOFF_SPIN(%o2, %o3, 1b)
10356 ENDPROC(atomic64_add)
10357
10358+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10359+ BACKOFF_SETUP(%o2)
10360+1: ldx [%o1], %g1
10361+ addcc %g1, %o0, %g7
10362+ casx [%o1], %g1, %g7
10363+ cmp %g1, %g7
10364+ bne,pn %xcc, 2f
10365+ nop
10366+ retl
10367+ nop
10368+2: BACKOFF_SPIN(%o2, %o3, 1b)
10369+ENDPROC(atomic64_add_unchecked)
10370+
10371 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10372 BACKOFF_SETUP(%o2)
10373 1: ldx [%o1], %g1
10374- sub %g1, %o0, %g7
10375+ subcc %g1, %o0, %g7
10376+
10377+#ifdef CONFIG_PAX_REFCOUNT
10378+ tvs %xcc, 6
10379+#endif
10380+
10381 casx [%o1], %g1, %g7
10382 cmp %g1, %g7
10383 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10384@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10385 2: BACKOFF_SPIN(%o2, %o3, 1b)
10386 ENDPROC(atomic64_sub)
10387
10388+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10389+ BACKOFF_SETUP(%o2)
10390+1: ldx [%o1], %g1
10391+ subcc %g1, %o0, %g7
10392+ casx [%o1], %g1, %g7
10393+ cmp %g1, %g7
10394+ bne,pn %xcc, 2f
10395+ nop
10396+ retl
10397+ nop
10398+2: BACKOFF_SPIN(%o2, %o3, 1b)
10399+ENDPROC(atomic64_sub_unchecked)
10400+
10401 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10402 BACKOFF_SETUP(%o2)
10403 1: ldx [%o1], %g1
10404- add %g1, %o0, %g7
10405+ addcc %g1, %o0, %g7
10406+
10407+#ifdef CONFIG_PAX_REFCOUNT
10408+ tvs %xcc, 6
10409+#endif
10410+
10411 casx [%o1], %g1, %g7
10412 cmp %g1, %g7
10413 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10414@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10415 2: BACKOFF_SPIN(%o2, %o3, 1b)
10416 ENDPROC(atomic64_add_ret)
10417
10418+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10419+ BACKOFF_SETUP(%o2)
10420+1: ldx [%o1], %g1
10421+ addcc %g1, %o0, %g7
10422+ casx [%o1], %g1, %g7
10423+ cmp %g1, %g7
10424+ bne,pn %xcc, 2f
10425+ add %g7, %o0, %g7
10426+ mov %g7, %o0
10427+ retl
10428+ nop
10429+2: BACKOFF_SPIN(%o2, %o3, 1b)
10430+ENDPROC(atomic64_add_ret_unchecked)
10431+
10432 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10433 BACKOFF_SETUP(%o2)
10434 1: ldx [%o1], %g1
10435- sub %g1, %o0, %g7
10436+ subcc %g1, %o0, %g7
10437+
10438+#ifdef CONFIG_PAX_REFCOUNT
10439+ tvs %xcc, 6
10440+#endif
10441+
10442 casx [%o1], %g1, %g7
10443 cmp %g1, %g7
10444 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10445diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10446index 323335b..ed85ea2 100644
10447--- a/arch/sparc/lib/ksyms.c
10448+++ b/arch/sparc/lib/ksyms.c
10449@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10450
10451 /* Atomic counter implementation. */
10452 EXPORT_SYMBOL(atomic_add);
10453+EXPORT_SYMBOL(atomic_add_unchecked);
10454 EXPORT_SYMBOL(atomic_add_ret);
10455+EXPORT_SYMBOL(atomic_add_ret_unchecked);
10456 EXPORT_SYMBOL(atomic_sub);
10457+EXPORT_SYMBOL(atomic_sub_unchecked);
10458 EXPORT_SYMBOL(atomic_sub_ret);
10459 EXPORT_SYMBOL(atomic64_add);
10460+EXPORT_SYMBOL(atomic64_add_unchecked);
10461 EXPORT_SYMBOL(atomic64_add_ret);
10462+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10463 EXPORT_SYMBOL(atomic64_sub);
10464+EXPORT_SYMBOL(atomic64_sub_unchecked);
10465 EXPORT_SYMBOL(atomic64_sub_ret);
10466 EXPORT_SYMBOL(atomic64_dec_if_positive);
10467
10468diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10469index 30c3ecc..736f015 100644
10470--- a/arch/sparc/mm/Makefile
10471+++ b/arch/sparc/mm/Makefile
10472@@ -2,7 +2,7 @@
10473 #
10474
10475 asflags-y := -ansi
10476-ccflags-y := -Werror
10477+#ccflags-y := -Werror
10478
10479 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10480 obj-y += fault_$(BITS).o
10481diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10482index 59dbd46..1dd7f5e 100644
10483--- a/arch/sparc/mm/fault_32.c
10484+++ b/arch/sparc/mm/fault_32.c
10485@@ -21,6 +21,9 @@
10486 #include <linux/perf_event.h>
10487 #include <linux/interrupt.h>
10488 #include <linux/kdebug.h>
10489+#include <linux/slab.h>
10490+#include <linux/pagemap.h>
10491+#include <linux/compiler.h>
10492
10493 #include <asm/page.h>
10494 #include <asm/pgtable.h>
10495@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10496 return safe_compute_effective_address(regs, insn);
10497 }
10498
10499+#ifdef CONFIG_PAX_PAGEEXEC
10500+#ifdef CONFIG_PAX_DLRESOLVE
10501+static void pax_emuplt_close(struct vm_area_struct *vma)
10502+{
10503+ vma->vm_mm->call_dl_resolve = 0UL;
10504+}
10505+
10506+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10507+{
10508+ unsigned int *kaddr;
10509+
10510+ vmf->page = alloc_page(GFP_HIGHUSER);
10511+ if (!vmf->page)
10512+ return VM_FAULT_OOM;
10513+
10514+ kaddr = kmap(vmf->page);
10515+ memset(kaddr, 0, PAGE_SIZE);
10516+ kaddr[0] = 0x9DE3BFA8U; /* save */
10517+ flush_dcache_page(vmf->page);
10518+ kunmap(vmf->page);
10519+ return VM_FAULT_MAJOR;
10520+}
10521+
10522+static const struct vm_operations_struct pax_vm_ops = {
10523+ .close = pax_emuplt_close,
10524+ .fault = pax_emuplt_fault
10525+};
10526+
10527+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10528+{
10529+ int ret;
10530+
10531+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10532+ vma->vm_mm = current->mm;
10533+ vma->vm_start = addr;
10534+ vma->vm_end = addr + PAGE_SIZE;
10535+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10536+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10537+ vma->vm_ops = &pax_vm_ops;
10538+
10539+ ret = insert_vm_struct(current->mm, vma);
10540+ if (ret)
10541+ return ret;
10542+
10543+ ++current->mm->total_vm;
10544+ return 0;
10545+}
10546+#endif
10547+
10548+/*
10549+ * PaX: decide what to do with offenders (regs->pc = fault address)
10550+ *
10551+ * returns 1 when task should be killed
10552+ * 2 when patched PLT trampoline was detected
10553+ * 3 when unpatched PLT trampoline was detected
10554+ */
10555+static int pax_handle_fetch_fault(struct pt_regs *regs)
10556+{
10557+
10558+#ifdef CONFIG_PAX_EMUPLT
10559+ int err;
10560+
10561+ do { /* PaX: patched PLT emulation #1 */
10562+ unsigned int sethi1, sethi2, jmpl;
10563+
10564+ err = get_user(sethi1, (unsigned int *)regs->pc);
10565+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
10566+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
10567+
10568+ if (err)
10569+ break;
10570+
10571+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10572+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10573+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10574+ {
10575+ unsigned int addr;
10576+
10577+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10578+ addr = regs->u_regs[UREG_G1];
10579+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10580+ regs->pc = addr;
10581+ regs->npc = addr+4;
10582+ return 2;
10583+ }
10584+ } while (0);
10585+
10586+ do { /* PaX: patched PLT emulation #2 */
10587+ unsigned int ba;
10588+
10589+ err = get_user(ba, (unsigned int *)regs->pc);
10590+
10591+ if (err)
10592+ break;
10593+
10594+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10595+ unsigned int addr;
10596+
10597+ if ((ba & 0xFFC00000U) == 0x30800000U)
10598+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10599+ else
10600+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10601+ regs->pc = addr;
10602+ regs->npc = addr+4;
10603+ return 2;
10604+ }
10605+ } while (0);
10606+
10607+ do { /* PaX: patched PLT emulation #3 */
10608+ unsigned int sethi, bajmpl, nop;
10609+
10610+ err = get_user(sethi, (unsigned int *)regs->pc);
10611+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
10612+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10613+
10614+ if (err)
10615+ break;
10616+
10617+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10618+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10619+ nop == 0x01000000U)
10620+ {
10621+ unsigned int addr;
10622+
10623+ addr = (sethi & 0x003FFFFFU) << 10;
10624+ regs->u_regs[UREG_G1] = addr;
10625+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10626+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10627+ else
10628+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10629+ regs->pc = addr;
10630+ regs->npc = addr+4;
10631+ return 2;
10632+ }
10633+ } while (0);
10634+
10635+ do { /* PaX: unpatched PLT emulation step 1 */
10636+ unsigned int sethi, ba, nop;
10637+
10638+ err = get_user(sethi, (unsigned int *)regs->pc);
10639+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
10640+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10641+
10642+ if (err)
10643+ break;
10644+
10645+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10646+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10647+ nop == 0x01000000U)
10648+ {
10649+ unsigned int addr, save, call;
10650+
10651+ if ((ba & 0xFFC00000U) == 0x30800000U)
10652+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10653+ else
10654+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10655+
10656+ err = get_user(save, (unsigned int *)addr);
10657+ err |= get_user(call, (unsigned int *)(addr+4));
10658+ err |= get_user(nop, (unsigned int *)(addr+8));
10659+ if (err)
10660+ break;
10661+
10662+#ifdef CONFIG_PAX_DLRESOLVE
10663+ if (save == 0x9DE3BFA8U &&
10664+ (call & 0xC0000000U) == 0x40000000U &&
10665+ nop == 0x01000000U)
10666+ {
10667+ struct vm_area_struct *vma;
10668+ unsigned long call_dl_resolve;
10669+
10670+ down_read(&current->mm->mmap_sem);
10671+ call_dl_resolve = current->mm->call_dl_resolve;
10672+ up_read(&current->mm->mmap_sem);
10673+ if (likely(call_dl_resolve))
10674+ goto emulate;
10675+
10676+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10677+
10678+ down_write(&current->mm->mmap_sem);
10679+ if (current->mm->call_dl_resolve) {
10680+ call_dl_resolve = current->mm->call_dl_resolve;
10681+ up_write(&current->mm->mmap_sem);
10682+ if (vma)
10683+ kmem_cache_free(vm_area_cachep, vma);
10684+ goto emulate;
10685+ }
10686+
10687+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10688+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10689+ up_write(&current->mm->mmap_sem);
10690+ if (vma)
10691+ kmem_cache_free(vm_area_cachep, vma);
10692+ return 1;
10693+ }
10694+
10695+ if (pax_insert_vma(vma, call_dl_resolve)) {
10696+ up_write(&current->mm->mmap_sem);
10697+ kmem_cache_free(vm_area_cachep, vma);
10698+ return 1;
10699+ }
10700+
10701+ current->mm->call_dl_resolve = call_dl_resolve;
10702+ up_write(&current->mm->mmap_sem);
10703+
10704+emulate:
10705+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10706+ regs->pc = call_dl_resolve;
10707+ regs->npc = addr+4;
10708+ return 3;
10709+ }
10710+#endif
10711+
10712+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10713+ if ((save & 0xFFC00000U) == 0x05000000U &&
10714+ (call & 0xFFFFE000U) == 0x85C0A000U &&
10715+ nop == 0x01000000U)
10716+ {
10717+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10718+ regs->u_regs[UREG_G2] = addr + 4;
10719+ addr = (save & 0x003FFFFFU) << 10;
10720+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10721+ regs->pc = addr;
10722+ regs->npc = addr+4;
10723+ return 3;
10724+ }
10725+ }
10726+ } while (0);
10727+
10728+ do { /* PaX: unpatched PLT emulation step 2 */
10729+ unsigned int save, call, nop;
10730+
10731+ err = get_user(save, (unsigned int *)(regs->pc-4));
10732+ err |= get_user(call, (unsigned int *)regs->pc);
10733+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
10734+ if (err)
10735+ break;
10736+
10737+ if (save == 0x9DE3BFA8U &&
10738+ (call & 0xC0000000U) == 0x40000000U &&
10739+ nop == 0x01000000U)
10740+ {
10741+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
10742+
10743+ regs->u_regs[UREG_RETPC] = regs->pc;
10744+ regs->pc = dl_resolve;
10745+ regs->npc = dl_resolve+4;
10746+ return 3;
10747+ }
10748+ } while (0);
10749+#endif
10750+
10751+ return 1;
10752+}
10753+
10754+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
10755+{
10756+ unsigned long i;
10757+
10758+ printk(KERN_ERR "PAX: bytes at PC: ");
10759+ for (i = 0; i < 8; i++) {
10760+ unsigned int c;
10761+ if (get_user(c, (unsigned int *)pc+i))
10762+ printk(KERN_CONT "???????? ");
10763+ else
10764+ printk(KERN_CONT "%08x ", c);
10765+ }
10766+ printk("\n");
10767+}
10768+#endif
10769+
10770 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
10771 int text_fault)
10772 {
10773@@ -229,6 +503,24 @@ good_area:
10774 if (!(vma->vm_flags & VM_WRITE))
10775 goto bad_area;
10776 } else {
10777+
10778+#ifdef CONFIG_PAX_PAGEEXEC
10779+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
10780+ up_read(&mm->mmap_sem);
10781+ switch (pax_handle_fetch_fault(regs)) {
10782+
10783+#ifdef CONFIG_PAX_EMUPLT
10784+ case 2:
10785+ case 3:
10786+ return;
10787+#endif
10788+
10789+ }
10790+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
10791+ do_group_exit(SIGKILL);
10792+ }
10793+#endif
10794+
10795 /* Allow reads even for write-only mappings */
10796 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
10797 goto bad_area;
10798diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
10799index 69bb818..6ca35c8 100644
10800--- a/arch/sparc/mm/fault_64.c
10801+++ b/arch/sparc/mm/fault_64.c
10802@@ -22,6 +22,9 @@
10803 #include <linux/kdebug.h>
10804 #include <linux/percpu.h>
10805 #include <linux/context_tracking.h>
10806+#include <linux/slab.h>
10807+#include <linux/pagemap.h>
10808+#include <linux/compiler.h>
10809
10810 #include <asm/page.h>
10811 #include <asm/pgtable.h>
10812@@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
10813 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
10814 regs->tpc);
10815 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
10816- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
10817+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
10818 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
10819 dump_stack();
10820 unhandled_fault(regs->tpc, current, regs);
10821@@ -271,6 +274,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
10822 show_regs(regs);
10823 }
10824
10825+#ifdef CONFIG_PAX_PAGEEXEC
10826+#ifdef CONFIG_PAX_DLRESOLVE
10827+static void pax_emuplt_close(struct vm_area_struct *vma)
10828+{
10829+ vma->vm_mm->call_dl_resolve = 0UL;
10830+}
10831+
10832+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10833+{
10834+ unsigned int *kaddr;
10835+
10836+ vmf->page = alloc_page(GFP_HIGHUSER);
10837+ if (!vmf->page)
10838+ return VM_FAULT_OOM;
10839+
10840+ kaddr = kmap(vmf->page);
10841+ memset(kaddr, 0, PAGE_SIZE);
10842+ kaddr[0] = 0x9DE3BFA8U; /* save */
10843+ flush_dcache_page(vmf->page);
10844+ kunmap(vmf->page);
10845+ return VM_FAULT_MAJOR;
10846+}
10847+
10848+static const struct vm_operations_struct pax_vm_ops = {
10849+ .close = pax_emuplt_close,
10850+ .fault = pax_emuplt_fault
10851+};
10852+
10853+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10854+{
10855+ int ret;
10856+
10857+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10858+ vma->vm_mm = current->mm;
10859+ vma->vm_start = addr;
10860+ vma->vm_end = addr + PAGE_SIZE;
10861+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10862+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10863+ vma->vm_ops = &pax_vm_ops;
10864+
10865+ ret = insert_vm_struct(current->mm, vma);
10866+ if (ret)
10867+ return ret;
10868+
10869+ ++current->mm->total_vm;
10870+ return 0;
10871+}
10872+#endif
10873+
10874+/*
10875+ * PaX: decide what to do with offenders (regs->tpc = fault address)
10876+ *
10877+ * returns 1 when task should be killed
10878+ * 2 when patched PLT trampoline was detected
10879+ * 3 when unpatched PLT trampoline was detected
10880+ */
10881+static int pax_handle_fetch_fault(struct pt_regs *regs)
10882+{
10883+
10884+#ifdef CONFIG_PAX_EMUPLT
10885+ int err;
10886+
10887+ do { /* PaX: patched PLT emulation #1 */
10888+ unsigned int sethi1, sethi2, jmpl;
10889+
10890+ err = get_user(sethi1, (unsigned int *)regs->tpc);
10891+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
10892+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
10893+
10894+ if (err)
10895+ break;
10896+
10897+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10898+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10899+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10900+ {
10901+ unsigned long addr;
10902+
10903+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10904+ addr = regs->u_regs[UREG_G1];
10905+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10906+
10907+ if (test_thread_flag(TIF_32BIT))
10908+ addr &= 0xFFFFFFFFUL;
10909+
10910+ regs->tpc = addr;
10911+ regs->tnpc = addr+4;
10912+ return 2;
10913+ }
10914+ } while (0);
10915+
10916+ do { /* PaX: patched PLT emulation #2 */
10917+ unsigned int ba;
10918+
10919+ err = get_user(ba, (unsigned int *)regs->tpc);
10920+
10921+ if (err)
10922+ break;
10923+
10924+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10925+ unsigned long addr;
10926+
10927+ if ((ba & 0xFFC00000U) == 0x30800000U)
10928+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10929+ else
10930+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10931+
10932+ if (test_thread_flag(TIF_32BIT))
10933+ addr &= 0xFFFFFFFFUL;
10934+
10935+ regs->tpc = addr;
10936+ regs->tnpc = addr+4;
10937+ return 2;
10938+ }
10939+ } while (0);
10940+
10941+ do { /* PaX: patched PLT emulation #3 */
10942+ unsigned int sethi, bajmpl, nop;
10943+
10944+ err = get_user(sethi, (unsigned int *)regs->tpc);
10945+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
10946+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10947+
10948+ if (err)
10949+ break;
10950+
10951+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10952+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10953+ nop == 0x01000000U)
10954+ {
10955+ unsigned long addr;
10956+
10957+ addr = (sethi & 0x003FFFFFU) << 10;
10958+ regs->u_regs[UREG_G1] = addr;
10959+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10960+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10961+ else
10962+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10963+
10964+ if (test_thread_flag(TIF_32BIT))
10965+ addr &= 0xFFFFFFFFUL;
10966+
10967+ regs->tpc = addr;
10968+ regs->tnpc = addr+4;
10969+ return 2;
10970+ }
10971+ } while (0);
10972+
10973+ do { /* PaX: patched PLT emulation #4 */
10974+ unsigned int sethi, mov1, call, mov2;
10975+
10976+ err = get_user(sethi, (unsigned int *)regs->tpc);
10977+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
10978+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
10979+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
10980+
10981+ if (err)
10982+ break;
10983+
10984+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10985+ mov1 == 0x8210000FU &&
10986+ (call & 0xC0000000U) == 0x40000000U &&
10987+ mov2 == 0x9E100001U)
10988+ {
10989+ unsigned long addr;
10990+
10991+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
10992+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
10993+
10994+ if (test_thread_flag(TIF_32BIT))
10995+ addr &= 0xFFFFFFFFUL;
10996+
10997+ regs->tpc = addr;
10998+ regs->tnpc = addr+4;
10999+ return 2;
11000+ }
11001+ } while (0);
11002+
11003+ do { /* PaX: patched PLT emulation #5 */
11004+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11005+
11006+ err = get_user(sethi, (unsigned int *)regs->tpc);
11007+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11008+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11009+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11010+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11011+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11012+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11013+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11014+
11015+ if (err)
11016+ break;
11017+
11018+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11019+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11020+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11021+ (or1 & 0xFFFFE000U) == 0x82106000U &&
11022+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11023+ sllx == 0x83287020U &&
11024+ jmpl == 0x81C04005U &&
11025+ nop == 0x01000000U)
11026+ {
11027+ unsigned long addr;
11028+
11029+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11030+ regs->u_regs[UREG_G1] <<= 32;
11031+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11032+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11033+ regs->tpc = addr;
11034+ regs->tnpc = addr+4;
11035+ return 2;
11036+ }
11037+ } while (0);
11038+
11039+ do { /* PaX: patched PLT emulation #6 */
11040+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11041+
11042+ err = get_user(sethi, (unsigned int *)regs->tpc);
11043+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11044+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11045+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11046+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
11047+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11048+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11049+
11050+ if (err)
11051+ break;
11052+
11053+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11054+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11055+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11056+ sllx == 0x83287020U &&
11057+ (or & 0xFFFFE000U) == 0x8A116000U &&
11058+ jmpl == 0x81C04005U &&
11059+ nop == 0x01000000U)
11060+ {
11061+ unsigned long addr;
11062+
11063+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11064+ regs->u_regs[UREG_G1] <<= 32;
11065+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11066+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11067+ regs->tpc = addr;
11068+ regs->tnpc = addr+4;
11069+ return 2;
11070+ }
11071+ } while (0);
11072+
11073+ do { /* PaX: unpatched PLT emulation step 1 */
11074+ unsigned int sethi, ba, nop;
11075+
11076+ err = get_user(sethi, (unsigned int *)regs->tpc);
11077+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11078+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11079+
11080+ if (err)
11081+ break;
11082+
11083+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11084+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11085+ nop == 0x01000000U)
11086+ {
11087+ unsigned long addr;
11088+ unsigned int save, call;
11089+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11090+
11091+ if ((ba & 0xFFC00000U) == 0x30800000U)
11092+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11093+ else
11094+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11095+
11096+ if (test_thread_flag(TIF_32BIT))
11097+ addr &= 0xFFFFFFFFUL;
11098+
11099+ err = get_user(save, (unsigned int *)addr);
11100+ err |= get_user(call, (unsigned int *)(addr+4));
11101+ err |= get_user(nop, (unsigned int *)(addr+8));
11102+ if (err)
11103+ break;
11104+
11105+#ifdef CONFIG_PAX_DLRESOLVE
11106+ if (save == 0x9DE3BFA8U &&
11107+ (call & 0xC0000000U) == 0x40000000U &&
11108+ nop == 0x01000000U)
11109+ {
11110+ struct vm_area_struct *vma;
11111+ unsigned long call_dl_resolve;
11112+
11113+ down_read(&current->mm->mmap_sem);
11114+ call_dl_resolve = current->mm->call_dl_resolve;
11115+ up_read(&current->mm->mmap_sem);
11116+ if (likely(call_dl_resolve))
11117+ goto emulate;
11118+
11119+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11120+
11121+ down_write(&current->mm->mmap_sem);
11122+ if (current->mm->call_dl_resolve) {
11123+ call_dl_resolve = current->mm->call_dl_resolve;
11124+ up_write(&current->mm->mmap_sem);
11125+ if (vma)
11126+ kmem_cache_free(vm_area_cachep, vma);
11127+ goto emulate;
11128+ }
11129+
11130+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11131+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11132+ up_write(&current->mm->mmap_sem);
11133+ if (vma)
11134+ kmem_cache_free(vm_area_cachep, vma);
11135+ return 1;
11136+ }
11137+
11138+ if (pax_insert_vma(vma, call_dl_resolve)) {
11139+ up_write(&current->mm->mmap_sem);
11140+ kmem_cache_free(vm_area_cachep, vma);
11141+ return 1;
11142+ }
11143+
11144+ current->mm->call_dl_resolve = call_dl_resolve;
11145+ up_write(&current->mm->mmap_sem);
11146+
11147+emulate:
11148+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11149+ regs->tpc = call_dl_resolve;
11150+ regs->tnpc = addr+4;
11151+ return 3;
11152+ }
11153+#endif
11154+
11155+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11156+ if ((save & 0xFFC00000U) == 0x05000000U &&
11157+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11158+ nop == 0x01000000U)
11159+ {
11160+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11161+ regs->u_regs[UREG_G2] = addr + 4;
11162+ addr = (save & 0x003FFFFFU) << 10;
11163+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11164+
11165+ if (test_thread_flag(TIF_32BIT))
11166+ addr &= 0xFFFFFFFFUL;
11167+
11168+ regs->tpc = addr;
11169+ regs->tnpc = addr+4;
11170+ return 3;
11171+ }
11172+
11173+ /* PaX: 64-bit PLT stub */
11174+ err = get_user(sethi1, (unsigned int *)addr);
11175+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11176+ err |= get_user(or1, (unsigned int *)(addr+8));
11177+ err |= get_user(or2, (unsigned int *)(addr+12));
11178+ err |= get_user(sllx, (unsigned int *)(addr+16));
11179+ err |= get_user(add, (unsigned int *)(addr+20));
11180+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11181+ err |= get_user(nop, (unsigned int *)(addr+28));
11182+ if (err)
11183+ break;
11184+
11185+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11186+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11187+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11188+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11189+ sllx == 0x89293020U &&
11190+ add == 0x8A010005U &&
11191+ jmpl == 0x89C14000U &&
11192+ nop == 0x01000000U)
11193+ {
11194+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11195+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11196+ regs->u_regs[UREG_G4] <<= 32;
11197+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11198+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11199+ regs->u_regs[UREG_G4] = addr + 24;
11200+ addr = regs->u_regs[UREG_G5];
11201+ regs->tpc = addr;
11202+ regs->tnpc = addr+4;
11203+ return 3;
11204+ }
11205+ }
11206+ } while (0);
11207+
11208+#ifdef CONFIG_PAX_DLRESOLVE
11209+ do { /* PaX: unpatched PLT emulation step 2 */
11210+ unsigned int save, call, nop;
11211+
11212+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11213+ err |= get_user(call, (unsigned int *)regs->tpc);
11214+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11215+ if (err)
11216+ break;
11217+
11218+ if (save == 0x9DE3BFA8U &&
11219+ (call & 0xC0000000U) == 0x40000000U &&
11220+ nop == 0x01000000U)
11221+ {
11222+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11223+
11224+ if (test_thread_flag(TIF_32BIT))
11225+ dl_resolve &= 0xFFFFFFFFUL;
11226+
11227+ regs->u_regs[UREG_RETPC] = regs->tpc;
11228+ regs->tpc = dl_resolve;
11229+ regs->tnpc = dl_resolve+4;
11230+ return 3;
11231+ }
11232+ } while (0);
11233+#endif
11234+
11235+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11236+ unsigned int sethi, ba, nop;
11237+
11238+ err = get_user(sethi, (unsigned int *)regs->tpc);
11239+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11240+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11241+
11242+ if (err)
11243+ break;
11244+
11245+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11246+ (ba & 0xFFF00000U) == 0x30600000U &&
11247+ nop == 0x01000000U)
11248+ {
11249+ unsigned long addr;
11250+
11251+ addr = (sethi & 0x003FFFFFU) << 10;
11252+ regs->u_regs[UREG_G1] = addr;
11253+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11254+
11255+ if (test_thread_flag(TIF_32BIT))
11256+ addr &= 0xFFFFFFFFUL;
11257+
11258+ regs->tpc = addr;
11259+ regs->tnpc = addr+4;
11260+ return 2;
11261+ }
11262+ } while (0);
11263+
11264+#endif
11265+
11266+ return 1;
11267+}
11268+
11269+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11270+{
11271+ unsigned long i;
11272+
11273+ printk(KERN_ERR "PAX: bytes at PC: ");
11274+ for (i = 0; i < 8; i++) {
11275+ unsigned int c;
11276+ if (get_user(c, (unsigned int *)pc+i))
11277+ printk(KERN_CONT "???????? ");
11278+ else
11279+ printk(KERN_CONT "%08x ", c);
11280+ }
11281+ printk("\n");
11282+}
11283+#endif
11284+
11285 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11286 {
11287 enum ctx_state prev_state = exception_enter();
11288@@ -344,6 +807,29 @@ retry:
11289 if (!vma)
11290 goto bad_area;
11291
11292+#ifdef CONFIG_PAX_PAGEEXEC
11293+ /* PaX: detect ITLB misses on non-exec pages */
11294+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11295+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11296+ {
11297+ if (address != regs->tpc)
11298+ goto good_area;
11299+
11300+ up_read(&mm->mmap_sem);
11301+ switch (pax_handle_fetch_fault(regs)) {
11302+
11303+#ifdef CONFIG_PAX_EMUPLT
11304+ case 2:
11305+ case 3:
11306+ return;
11307+#endif
11308+
11309+ }
11310+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11311+ do_group_exit(SIGKILL);
11312+ }
11313+#endif
11314+
11315 /* Pure DTLB misses do not tell us whether the fault causing
11316 * load/store/atomic was a write or not, it only says that there
11317 * was no match. So in such a case we (carefully) read the
11318diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11319index 3096317..a7b7654 100644
11320--- a/arch/sparc/mm/hugetlbpage.c
11321+++ b/arch/sparc/mm/hugetlbpage.c
11322@@ -26,7 +26,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11323 unsigned long addr,
11324 unsigned long len,
11325 unsigned long pgoff,
11326- unsigned long flags)
11327+ unsigned long flags,
11328+ unsigned long offset)
11329 {
11330 unsigned long task_size = TASK_SIZE;
11331 struct vm_unmapped_area_info info;
11332@@ -36,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11333
11334 info.flags = 0;
11335 info.length = len;
11336- info.low_limit = TASK_UNMAPPED_BASE;
11337+ info.low_limit = mm->mmap_base;
11338 info.high_limit = min(task_size, VA_EXCLUDE_START);
11339 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11340 info.align_offset = 0;
11341+ info.threadstack_offset = offset;
11342 addr = vm_unmapped_area(&info);
11343
11344 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11345 VM_BUG_ON(addr != -ENOMEM);
11346 info.low_limit = VA_EXCLUDE_END;
11347+
11348+#ifdef CONFIG_PAX_RANDMMAP
11349+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11350+ info.low_limit += mm->delta_mmap;
11351+#endif
11352+
11353 info.high_limit = task_size;
11354 addr = vm_unmapped_area(&info);
11355 }
11356@@ -56,7 +64,8 @@ static unsigned long
11357 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11358 const unsigned long len,
11359 const unsigned long pgoff,
11360- const unsigned long flags)
11361+ const unsigned long flags,
11362+ const unsigned long offset)
11363 {
11364 struct mm_struct *mm = current->mm;
11365 unsigned long addr = addr0;
11366@@ -71,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11367 info.high_limit = mm->mmap_base;
11368 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11369 info.align_offset = 0;
11370+ info.threadstack_offset = offset;
11371 addr = vm_unmapped_area(&info);
11372
11373 /*
11374@@ -83,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11375 VM_BUG_ON(addr != -ENOMEM);
11376 info.flags = 0;
11377 info.low_limit = TASK_UNMAPPED_BASE;
11378+
11379+#ifdef CONFIG_PAX_RANDMMAP
11380+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11381+ info.low_limit += mm->delta_mmap;
11382+#endif
11383+
11384 info.high_limit = STACK_TOP32;
11385 addr = vm_unmapped_area(&info);
11386 }
11387@@ -97,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11388 struct mm_struct *mm = current->mm;
11389 struct vm_area_struct *vma;
11390 unsigned long task_size = TASK_SIZE;
11391+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11392
11393 if (test_thread_flag(TIF_32BIT))
11394 task_size = STACK_TOP32;
11395@@ -112,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11396 return addr;
11397 }
11398
11399+#ifdef CONFIG_PAX_RANDMMAP
11400+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11401+#endif
11402+
11403 if (addr) {
11404 addr = ALIGN(addr, HPAGE_SIZE);
11405 vma = find_vma(mm, addr);
11406- if (task_size - len >= addr &&
11407- (!vma || addr + len <= vma->vm_start))
11408+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11409 return addr;
11410 }
11411 if (mm->get_unmapped_area == arch_get_unmapped_area)
11412 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11413- pgoff, flags);
11414+ pgoff, flags, offset);
11415 else
11416 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11417- pgoff, flags);
11418+ pgoff, flags, offset);
11419 }
11420
11421 pte_t *huge_pte_alloc(struct mm_struct *mm,
11422diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11423index 5322e53..f820c5e 100644
11424--- a/arch/sparc/mm/init_64.c
11425+++ b/arch/sparc/mm/init_64.c
11426@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11427 int num_kernel_image_mappings;
11428
11429 #ifdef CONFIG_DEBUG_DCFLUSH
11430-atomic_t dcpage_flushes = ATOMIC_INIT(0);
11431+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11432 #ifdef CONFIG_SMP
11433-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11434+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11435 #endif
11436 #endif
11437
11438@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11439 {
11440 BUG_ON(tlb_type == hypervisor);
11441 #ifdef CONFIG_DEBUG_DCFLUSH
11442- atomic_inc(&dcpage_flushes);
11443+ atomic_inc_unchecked(&dcpage_flushes);
11444 #endif
11445
11446 #ifdef DCACHE_ALIASING_POSSIBLE
11447@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11448
11449 #ifdef CONFIG_DEBUG_DCFLUSH
11450 seq_printf(m, "DCPageFlushes\t: %d\n",
11451- atomic_read(&dcpage_flushes));
11452+ atomic_read_unchecked(&dcpage_flushes));
11453 #ifdef CONFIG_SMP
11454 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11455- atomic_read(&dcpage_flushes_xcall));
11456+ atomic_read_unchecked(&dcpage_flushes_xcall));
11457 #endif /* CONFIG_SMP */
11458 #endif /* CONFIG_DEBUG_DCFLUSH */
11459 }
11460diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
11461index b3692ce..e4517c9 100644
11462--- a/arch/tile/Kconfig
11463+++ b/arch/tile/Kconfig
11464@@ -184,6 +184,7 @@ source "kernel/Kconfig.hz"
11465
11466 config KEXEC
11467 bool "kexec system call"
11468+ depends on !GRKERNSEC_KMEM
11469 ---help---
11470 kexec is a system call that implements the ability to shutdown your
11471 current kernel, and to start another kernel. It is like a reboot
11472diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11473index ad220ee..2f537b3 100644
11474--- a/arch/tile/include/asm/atomic_64.h
11475+++ b/arch/tile/include/asm/atomic_64.h
11476@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11477
11478 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11479
11480+#define atomic64_read_unchecked(v) atomic64_read(v)
11481+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11482+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11483+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11484+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11485+#define atomic64_inc_unchecked(v) atomic64_inc(v)
11486+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11487+#define atomic64_dec_unchecked(v) atomic64_dec(v)
11488+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11489+
11490 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11491 #define smp_mb__before_atomic_dec() smp_mb()
11492 #define smp_mb__after_atomic_dec() smp_mb()
11493diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11494index 6160761..00cac88 100644
11495--- a/arch/tile/include/asm/cache.h
11496+++ b/arch/tile/include/asm/cache.h
11497@@ -15,11 +15,12 @@
11498 #ifndef _ASM_TILE_CACHE_H
11499 #define _ASM_TILE_CACHE_H
11500
11501+#include <linux/const.h>
11502 #include <arch/chip.h>
11503
11504 /* bytes per L1 data cache line */
11505 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11506-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11507+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11508
11509 /* bytes per L2 cache line */
11510 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11511diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11512index b6cde32..c0cb736 100644
11513--- a/arch/tile/include/asm/uaccess.h
11514+++ b/arch/tile/include/asm/uaccess.h
11515@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
11516 const void __user *from,
11517 unsigned long n)
11518 {
11519- int sz = __compiletime_object_size(to);
11520+ size_t sz = __compiletime_object_size(to);
11521
11522- if (likely(sz == -1 || sz >= n))
11523+ if (likely(sz == (size_t)-1 || sz >= n))
11524 n = _copy_from_user(to, from, n);
11525 else
11526 copy_from_user_overflow();
11527diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
11528index 0cb3bba..7338b2d 100644
11529--- a/arch/tile/mm/hugetlbpage.c
11530+++ b/arch/tile/mm/hugetlbpage.c
11531@@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
11532 info.high_limit = TASK_SIZE;
11533 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11534 info.align_offset = 0;
11535+ info.threadstack_offset = 0;
11536 return vm_unmapped_area(&info);
11537 }
11538
11539@@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
11540 info.high_limit = current->mm->mmap_base;
11541 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11542 info.align_offset = 0;
11543+ info.threadstack_offset = 0;
11544 addr = vm_unmapped_area(&info);
11545
11546 /*
11547diff --git a/arch/um/Makefile b/arch/um/Makefile
11548index 36e658a..71a5c5a 100644
11549--- a/arch/um/Makefile
11550+++ b/arch/um/Makefile
11551@@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
11552 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
11553 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
11554
11555+ifdef CONSTIFY_PLUGIN
11556+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11557+endif
11558+
11559 #This will adjust *FLAGS accordingly to the platform.
11560 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
11561
11562diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
11563index 19e1bdd..3665b77 100644
11564--- a/arch/um/include/asm/cache.h
11565+++ b/arch/um/include/asm/cache.h
11566@@ -1,6 +1,7 @@
11567 #ifndef __UM_CACHE_H
11568 #define __UM_CACHE_H
11569
11570+#include <linux/const.h>
11571
11572 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
11573 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11574@@ -12,6 +13,6 @@
11575 # define L1_CACHE_SHIFT 5
11576 #endif
11577
11578-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11579+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11580
11581 #endif
11582diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
11583index 2e0a6b1..a64d0f5 100644
11584--- a/arch/um/include/asm/kmap_types.h
11585+++ b/arch/um/include/asm/kmap_types.h
11586@@ -8,6 +8,6 @@
11587
11588 /* No more #include "asm/arch/kmap_types.h" ! */
11589
11590-#define KM_TYPE_NR 14
11591+#define KM_TYPE_NR 15
11592
11593 #endif
11594diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
11595index 5ff53d9..5850cdf 100644
11596--- a/arch/um/include/asm/page.h
11597+++ b/arch/um/include/asm/page.h
11598@@ -14,6 +14,9 @@
11599 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
11600 #define PAGE_MASK (~(PAGE_SIZE-1))
11601
11602+#define ktla_ktva(addr) (addr)
11603+#define ktva_ktla(addr) (addr)
11604+
11605 #ifndef __ASSEMBLY__
11606
11607 struct page;
11608diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
11609index 0032f92..cd151e0 100644
11610--- a/arch/um/include/asm/pgtable-3level.h
11611+++ b/arch/um/include/asm/pgtable-3level.h
11612@@ -58,6 +58,7 @@
11613 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
11614 #define pud_populate(mm, pud, pmd) \
11615 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
11616+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
11617
11618 #ifdef CONFIG_64BIT
11619 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
11620diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
11621index eecc414..48adb87 100644
11622--- a/arch/um/kernel/process.c
11623+++ b/arch/um/kernel/process.c
11624@@ -356,22 +356,6 @@ int singlestepping(void * t)
11625 return 2;
11626 }
11627
11628-/*
11629- * Only x86 and x86_64 have an arch_align_stack().
11630- * All other arches have "#define arch_align_stack(x) (x)"
11631- * in their asm/system.h
11632- * As this is included in UML from asm-um/system-generic.h,
11633- * we can use it to behave as the subarch does.
11634- */
11635-#ifndef arch_align_stack
11636-unsigned long arch_align_stack(unsigned long sp)
11637-{
11638- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
11639- sp -= get_random_int() % 8192;
11640- return sp & ~0xf;
11641-}
11642-#endif
11643-
11644 unsigned long get_wchan(struct task_struct *p)
11645 {
11646 unsigned long stack_page, sp, ip;
11647diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
11648index ad8f795..2c7eec6 100644
11649--- a/arch/unicore32/include/asm/cache.h
11650+++ b/arch/unicore32/include/asm/cache.h
11651@@ -12,8 +12,10 @@
11652 #ifndef __UNICORE_CACHE_H__
11653 #define __UNICORE_CACHE_H__
11654
11655-#define L1_CACHE_SHIFT (5)
11656-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11657+#include <linux/const.h>
11658+
11659+#define L1_CACHE_SHIFT 5
11660+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11661
11662 /*
11663 * Memory returned by kmalloc() may be used for DMA, so we must make
11664diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
11665index 0952ecd..75e0e8a 100644
11666--- a/arch/x86/Kconfig
11667+++ b/arch/x86/Kconfig
11668@@ -249,7 +249,7 @@ config X86_HT
11669
11670 config X86_32_LAZY_GS
11671 def_bool y
11672- depends on X86_32 && !CC_STACKPROTECTOR
11673+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
11674
11675 config ARCH_HWEIGHT_CFLAGS
11676 string
11677@@ -1104,6 +1104,7 @@ config MICROCODE_EARLY
11678
11679 config X86_MSR
11680 tristate "/dev/cpu/*/msr - Model-specific register support"
11681+ depends on !GRKERNSEC_KMEM
11682 ---help---
11683 This device gives privileged processes access to the x86
11684 Model-Specific Registers (MSRs). It is a character device with
11685@@ -1127,7 +1128,7 @@ choice
11686
11687 config NOHIGHMEM
11688 bool "off"
11689- depends on !X86_NUMAQ
11690+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11691 ---help---
11692 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
11693 However, the address space of 32-bit x86 processors is only 4
11694@@ -1164,7 +1165,7 @@ config NOHIGHMEM
11695
11696 config HIGHMEM4G
11697 bool "4GB"
11698- depends on !X86_NUMAQ
11699+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11700 ---help---
11701 Select this if you have a 32-bit processor and between 1 and 4
11702 gigabytes of physical RAM.
11703@@ -1217,7 +1218,7 @@ config PAGE_OFFSET
11704 hex
11705 default 0xB0000000 if VMSPLIT_3G_OPT
11706 default 0x80000000 if VMSPLIT_2G
11707- default 0x78000000 if VMSPLIT_2G_OPT
11708+ default 0x70000000 if VMSPLIT_2G_OPT
11709 default 0x40000000 if VMSPLIT_1G
11710 default 0xC0000000
11711 depends on X86_32
11712@@ -1619,6 +1620,7 @@ config SECCOMP
11713
11714 config CC_STACKPROTECTOR
11715 bool "Enable -fstack-protector buffer overflow detection"
11716+ depends on X86_64 || !PAX_MEMORY_UDEREF
11717 ---help---
11718 This option turns on the -fstack-protector GCC feature. This
11719 feature puts, at the beginning of functions, a canary value on
11720@@ -1637,6 +1639,7 @@ source kernel/Kconfig.hz
11721
11722 config KEXEC
11723 bool "kexec system call"
11724+ depends on !GRKERNSEC_KMEM
11725 ---help---
11726 kexec is a system call that implements the ability to shutdown your
11727 current kernel, and to start another kernel. It is like a reboot
11728@@ -1738,6 +1741,8 @@ config X86_NEED_RELOCS
11729 config PHYSICAL_ALIGN
11730 hex "Alignment value to which kernel should be aligned"
11731 default "0x1000000"
11732+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
11733+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
11734 range 0x2000 0x1000000 if X86_32
11735 range 0x200000 0x1000000 if X86_64
11736 ---help---
11737@@ -1817,9 +1822,10 @@ config DEBUG_HOTPLUG_CPU0
11738 If unsure, say N.
11739
11740 config COMPAT_VDSO
11741- def_bool y
11742+ def_bool n
11743 prompt "Compat VDSO support"
11744 depends on X86_32 || IA32_EMULATION
11745+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
11746 ---help---
11747 Map the 32-bit VDSO to the predictable old-style address too.
11748
11749diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
11750index c026cca..14657ae 100644
11751--- a/arch/x86/Kconfig.cpu
11752+++ b/arch/x86/Kconfig.cpu
11753@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
11754
11755 config X86_F00F_BUG
11756 def_bool y
11757- depends on M586MMX || M586TSC || M586 || M486
11758+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
11759
11760 config X86_INVD_BUG
11761 def_bool y
11762@@ -327,7 +327,7 @@ config X86_INVD_BUG
11763
11764 config X86_ALIGNMENT_16
11765 def_bool y
11766- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11767+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11768
11769 config X86_INTEL_USERCOPY
11770 def_bool y
11771@@ -373,7 +373,7 @@ config X86_CMPXCHG64
11772 # generates cmov.
11773 config X86_CMOV
11774 def_bool y
11775- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11776+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11777
11778 config X86_MINIMUM_CPU_FAMILY
11779 int
11780diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
11781index 0f3621e..282f24b 100644
11782--- a/arch/x86/Kconfig.debug
11783+++ b/arch/x86/Kconfig.debug
11784@@ -84,7 +84,7 @@ config X86_PTDUMP
11785 config DEBUG_RODATA
11786 bool "Write protect kernel read-only data structures"
11787 default y
11788- depends on DEBUG_KERNEL
11789+ depends on DEBUG_KERNEL && BROKEN
11790 ---help---
11791 Mark the kernel read-only data as write-protected in the pagetables,
11792 in order to catch accidental (and incorrect) writes to such const
11793@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
11794
11795 config DEBUG_SET_MODULE_RONX
11796 bool "Set loadable kernel module data as NX and text as RO"
11797- depends on MODULES
11798+ depends on MODULES && BROKEN
11799 ---help---
11800 This option helps catch unintended modifications to loadable
11801 kernel module's text and read-only data. It also prevents execution
11802diff --git a/arch/x86/Makefile b/arch/x86/Makefile
11803index 57d0215..b4373fb 100644
11804--- a/arch/x86/Makefile
11805+++ b/arch/x86/Makefile
11806@@ -49,14 +49,12 @@ ifeq ($(CONFIG_X86_32),y)
11807 # CPU-specific tuning. Anything which can be shared with UML should go here.
11808 include $(srctree)/arch/x86/Makefile_32.cpu
11809 KBUILD_CFLAGS += $(cflags-y)
11810-
11811- # temporary until string.h is fixed
11812- KBUILD_CFLAGS += -ffreestanding
11813 else
11814 BITS := 64
11815 UTS_MACHINE := x86_64
11816 CHECKFLAGS += -D__x86_64__ -m64
11817
11818+ biarch := $(call cc-option,-m64)
11819 KBUILD_AFLAGS += -m64
11820 KBUILD_CFLAGS += -m64
11821
11822@@ -89,6 +87,9 @@ else
11823 KBUILD_CFLAGS += -maccumulate-outgoing-args
11824 endif
11825
11826+# temporary until string.h is fixed
11827+KBUILD_CFLAGS += -ffreestanding
11828+
11829 ifdef CONFIG_CC_STACKPROTECTOR
11830 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
11831 ifeq ($(shell $(CONFIG_SHELL) $(cc_has_sp) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y)
11832@@ -247,3 +248,12 @@ define archhelp
11833 echo ' FDINITRD=file initrd for the booted kernel'
11834 echo ' kvmconfig - Enable additional options for guest kernel support'
11835 endef
11836+
11837+define OLD_LD
11838+
11839+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
11840+*** Please upgrade your binutils to 2.18 or newer
11841+endef
11842+
11843+archprepare:
11844+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
11845diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
11846index d9c1195..a26ca0d 100644
11847--- a/arch/x86/boot/Makefile
11848+++ b/arch/x86/boot/Makefile
11849@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ \
11850 $(call cc-option, -fno-unit-at-a-time)) \
11851 $(call cc-option, -fno-stack-protector) \
11852 $(call cc-option, -mpreferred-stack-boundary=2)
11853+ifdef CONSTIFY_PLUGIN
11854+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11855+endif
11856 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11857 GCOV_PROFILE := n
11858
11859diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
11860index 878e4b9..20537ab 100644
11861--- a/arch/x86/boot/bitops.h
11862+++ b/arch/x86/boot/bitops.h
11863@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11864 u8 v;
11865 const u32 *p = (const u32 *)addr;
11866
11867- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11868+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11869 return v;
11870 }
11871
11872@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11873
11874 static inline void set_bit(int nr, void *addr)
11875 {
11876- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11877+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11878 }
11879
11880 #endif /* BOOT_BITOPS_H */
11881diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
11882index ef72bae..353a184 100644
11883--- a/arch/x86/boot/boot.h
11884+++ b/arch/x86/boot/boot.h
11885@@ -85,7 +85,7 @@ static inline void io_delay(void)
11886 static inline u16 ds(void)
11887 {
11888 u16 seg;
11889- asm("movw %%ds,%0" : "=rm" (seg));
11890+ asm volatile("movw %%ds,%0" : "=rm" (seg));
11891 return seg;
11892 }
11893
11894@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
11895 static inline int memcmp(const void *s1, const void *s2, size_t len)
11896 {
11897 u8 diff;
11898- asm("repe; cmpsb; setnz %0"
11899+ asm volatile("repe; cmpsb; setnz %0"
11900 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
11901 return diff;
11902 }
11903diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
11904index c8a6792..2402765 100644
11905--- a/arch/x86/boot/compressed/Makefile
11906+++ b/arch/x86/boot/compressed/Makefile
11907@@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
11908 KBUILD_CFLAGS += -mno-mmx -mno-sse
11909 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
11910 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
11911+ifdef CONSTIFY_PLUGIN
11912+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11913+endif
11914
11915 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11916 GCOV_PROFILE := n
11917diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
11918index a53440e..c3dbf1e 100644
11919--- a/arch/x86/boot/compressed/efi_stub_32.S
11920+++ b/arch/x86/boot/compressed/efi_stub_32.S
11921@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
11922 * parameter 2, ..., param n. To make things easy, we save the return
11923 * address of efi_call_phys in a global variable.
11924 */
11925- popl %ecx
11926- movl %ecx, saved_return_addr(%edx)
11927- /* get the function pointer into ECX*/
11928- popl %ecx
11929- movl %ecx, efi_rt_function_ptr(%edx)
11930+ popl saved_return_addr(%edx)
11931+ popl efi_rt_function_ptr(%edx)
11932
11933 /*
11934 * 3. Call the physical function.
11935 */
11936- call *%ecx
11937+ call *efi_rt_function_ptr(%edx)
11938
11939 /*
11940 * 4. Balance the stack. And because EAX contain the return value,
11941@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
11942 1: popl %edx
11943 subl $1b, %edx
11944
11945- movl efi_rt_function_ptr(%edx), %ecx
11946- pushl %ecx
11947+ pushl efi_rt_function_ptr(%edx)
11948
11949 /*
11950 * 10. Push the saved return address onto the stack and return.
11951 */
11952- movl saved_return_addr(%edx), %ecx
11953- pushl %ecx
11954- ret
11955+ jmpl *saved_return_addr(%edx)
11956 ENDPROC(efi_call_phys)
11957 .previous
11958
11959diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
11960index 5d6f689..9d06730 100644
11961--- a/arch/x86/boot/compressed/head_32.S
11962+++ b/arch/x86/boot/compressed/head_32.S
11963@@ -118,7 +118,7 @@ preferred_addr:
11964 notl %eax
11965 andl %eax, %ebx
11966 #else
11967- movl $LOAD_PHYSICAL_ADDR, %ebx
11968+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11969 #endif
11970
11971 /* Target address to relocate to for decompression */
11972diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
11973index c337422..2c5be72 100644
11974--- a/arch/x86/boot/compressed/head_64.S
11975+++ b/arch/x86/boot/compressed/head_64.S
11976@@ -95,7 +95,7 @@ ENTRY(startup_32)
11977 notl %eax
11978 andl %eax, %ebx
11979 #else
11980- movl $LOAD_PHYSICAL_ADDR, %ebx
11981+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11982 #endif
11983
11984 /* Target address to relocate to for decompression */
11985@@ -270,7 +270,7 @@ preferred_addr:
11986 notq %rax
11987 andq %rax, %rbp
11988 #else
11989- movq $LOAD_PHYSICAL_ADDR, %rbp
11990+ movq $____LOAD_PHYSICAL_ADDR, %rbp
11991 #endif
11992
11993 /* Target address to relocate to for decompression */
11994@@ -362,8 +362,8 @@ gdt:
11995 .long gdt
11996 .word 0
11997 .quad 0x0000000000000000 /* NULL descriptor */
11998- .quad 0x00af9a000000ffff /* __KERNEL_CS */
11999- .quad 0x00cf92000000ffff /* __KERNEL_DS */
12000+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
12001+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
12002 .quad 0x0080890000000000 /* TS descriptor */
12003 .quad 0x0000000000000000 /* TS continued */
12004 gdt_end:
12005diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12006index 434f077..b6b4b38 100644
12007--- a/arch/x86/boot/compressed/misc.c
12008+++ b/arch/x86/boot/compressed/misc.c
12009@@ -283,7 +283,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12010 * Calculate the delta between where vmlinux was linked to load
12011 * and where it was actually loaded.
12012 */
12013- delta = min_addr - LOAD_PHYSICAL_ADDR;
12014+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12015 if (!delta) {
12016 debug_putstr("No relocation needed... ");
12017 return;
12018@@ -380,7 +380,7 @@ static void parse_elf(void *output)
12019 case PT_LOAD:
12020 #ifdef CONFIG_RELOCATABLE
12021 dest = output;
12022- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12023+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12024 #else
12025 dest = (void *)(phdr->p_paddr);
12026 #endif
12027@@ -432,7 +432,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
12028 error("Destination address too large");
12029 #endif
12030 #ifndef CONFIG_RELOCATABLE
12031- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12032+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12033 error("Wrong destination address");
12034 #endif
12035
12036diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12037index 4d3ff03..e4972ff 100644
12038--- a/arch/x86/boot/cpucheck.c
12039+++ b/arch/x86/boot/cpucheck.c
12040@@ -74,7 +74,7 @@ static int has_fpu(void)
12041 u16 fcw = -1, fsw = -1;
12042 u32 cr0;
12043
12044- asm("movl %%cr0,%0" : "=r" (cr0));
12045+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
12046 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
12047 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
12048 asm volatile("movl %0,%%cr0" : : "r" (cr0));
12049@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
12050 {
12051 u32 f0, f1;
12052
12053- asm("pushfl ; "
12054+ asm volatile("pushfl ; "
12055 "pushfl ; "
12056 "popl %0 ; "
12057 "movl %0,%1 ; "
12058@@ -115,7 +115,7 @@ static void get_flags(void)
12059 set_bit(X86_FEATURE_FPU, cpu.flags);
12060
12061 if (has_eflag(X86_EFLAGS_ID)) {
12062- asm("cpuid"
12063+ asm volatile("cpuid"
12064 : "=a" (max_intel_level),
12065 "=b" (cpu_vendor[0]),
12066 "=d" (cpu_vendor[1]),
12067@@ -124,7 +124,7 @@ static void get_flags(void)
12068
12069 if (max_intel_level >= 0x00000001 &&
12070 max_intel_level <= 0x0000ffff) {
12071- asm("cpuid"
12072+ asm volatile("cpuid"
12073 : "=a" (tfms),
12074 "=c" (cpu.flags[4]),
12075 "=d" (cpu.flags[0])
12076@@ -136,7 +136,7 @@ static void get_flags(void)
12077 cpu.model += ((tfms >> 16) & 0xf) << 4;
12078 }
12079
12080- asm("cpuid"
12081+ asm volatile("cpuid"
12082 : "=a" (max_amd_level)
12083 : "a" (0x80000000)
12084 : "ebx", "ecx", "edx");
12085@@ -144,7 +144,7 @@ static void get_flags(void)
12086 if (max_amd_level >= 0x80000001 &&
12087 max_amd_level <= 0x8000ffff) {
12088 u32 eax = 0x80000001;
12089- asm("cpuid"
12090+ asm volatile("cpuid"
12091 : "+a" (eax),
12092 "=c" (cpu.flags[6]),
12093 "=d" (cpu.flags[1])
12094@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12095 u32 ecx = MSR_K7_HWCR;
12096 u32 eax, edx;
12097
12098- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12099+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12100 eax &= ~(1 << 15);
12101- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12102+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12103
12104 get_flags(); /* Make sure it really did something */
12105 err = check_flags();
12106@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12107 u32 ecx = MSR_VIA_FCR;
12108 u32 eax, edx;
12109
12110- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12111+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12112 eax |= (1<<1)|(1<<7);
12113- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12114+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12115
12116 set_bit(X86_FEATURE_CX8, cpu.flags);
12117 err = check_flags();
12118@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12119 u32 eax, edx;
12120 u32 level = 1;
12121
12122- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12123- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12124- asm("cpuid"
12125+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12126+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12127+ asm volatile("cpuid"
12128 : "+a" (level), "=d" (cpu.flags[0])
12129 : : "ecx", "ebx");
12130- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12131+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12132
12133 err = check_flags();
12134 }
12135diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12136index 9ec06a1..2c25e79 100644
12137--- a/arch/x86/boot/header.S
12138+++ b/arch/x86/boot/header.S
12139@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12140 # single linked list of
12141 # struct setup_data
12142
12143-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12144+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12145
12146 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12147+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12148+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12149+#else
12150 #define VO_INIT_SIZE (VO__end - VO__text)
12151+#endif
12152 #if ZO_INIT_SIZE > VO_INIT_SIZE
12153 #define INIT_SIZE ZO_INIT_SIZE
12154 #else
12155diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12156index db75d07..8e6d0af 100644
12157--- a/arch/x86/boot/memory.c
12158+++ b/arch/x86/boot/memory.c
12159@@ -19,7 +19,7 @@
12160
12161 static int detect_memory_e820(void)
12162 {
12163- int count = 0;
12164+ unsigned int count = 0;
12165 struct biosregs ireg, oreg;
12166 struct e820entry *desc = boot_params.e820_map;
12167 static struct e820entry buf; /* static so it is zeroed */
12168diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12169index 11e8c6e..fdbb1ed 100644
12170--- a/arch/x86/boot/video-vesa.c
12171+++ b/arch/x86/boot/video-vesa.c
12172@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12173
12174 boot_params.screen_info.vesapm_seg = oreg.es;
12175 boot_params.screen_info.vesapm_off = oreg.di;
12176+ boot_params.screen_info.vesapm_size = oreg.cx;
12177 }
12178
12179 /*
12180diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12181index 43eda28..5ab5fdb 100644
12182--- a/arch/x86/boot/video.c
12183+++ b/arch/x86/boot/video.c
12184@@ -96,7 +96,7 @@ static void store_mode_params(void)
12185 static unsigned int get_entry(void)
12186 {
12187 char entry_buf[4];
12188- int i, len = 0;
12189+ unsigned int i, len = 0;
12190 int key;
12191 unsigned int v;
12192
12193diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12194index 9105655..41779c1 100644
12195--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12196+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12197@@ -8,6 +8,8 @@
12198 * including this sentence is retained in full.
12199 */
12200
12201+#include <asm/alternative-asm.h>
12202+
12203 .extern crypto_ft_tab
12204 .extern crypto_it_tab
12205 .extern crypto_fl_tab
12206@@ -70,6 +72,8 @@
12207 je B192; \
12208 leaq 32(r9),r9;
12209
12210+#define ret pax_force_retaddr; ret
12211+
12212 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12213 movq r1,r2; \
12214 movq r3,r4; \
12215diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12216index 477e9d7..c92c7d8 100644
12217--- a/arch/x86/crypto/aesni-intel_asm.S
12218+++ b/arch/x86/crypto/aesni-intel_asm.S
12219@@ -31,6 +31,7 @@
12220
12221 #include <linux/linkage.h>
12222 #include <asm/inst.h>
12223+#include <asm/alternative-asm.h>
12224
12225 #ifdef __x86_64__
12226 .data
12227@@ -205,7 +206,7 @@ enc: .octa 0x2
12228 * num_initial_blocks = b mod 4
12229 * encrypt the initial num_initial_blocks blocks and apply ghash on
12230 * the ciphertext
12231-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12232+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12233 * are clobbered
12234 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12235 */
12236@@ -214,8 +215,8 @@ enc: .octa 0x2
12237 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12238 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12239 mov arg7, %r10 # %r10 = AAD
12240- mov arg8, %r12 # %r12 = aadLen
12241- mov %r12, %r11
12242+ mov arg8, %r15 # %r15 = aadLen
12243+ mov %r15, %r11
12244 pxor %xmm\i, %xmm\i
12245 _get_AAD_loop\num_initial_blocks\operation:
12246 movd (%r10), \TMP1
12247@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12248 psrldq $4, %xmm\i
12249 pxor \TMP1, %xmm\i
12250 add $4, %r10
12251- sub $4, %r12
12252+ sub $4, %r15
12253 jne _get_AAD_loop\num_initial_blocks\operation
12254 cmp $16, %r11
12255 je _get_AAD_loop2_done\num_initial_blocks\operation
12256- mov $16, %r12
12257+ mov $16, %r15
12258 _get_AAD_loop2\num_initial_blocks\operation:
12259 psrldq $4, %xmm\i
12260- sub $4, %r12
12261- cmp %r11, %r12
12262+ sub $4, %r15
12263+ cmp %r11, %r15
12264 jne _get_AAD_loop2\num_initial_blocks\operation
12265 _get_AAD_loop2_done\num_initial_blocks\operation:
12266 movdqa SHUF_MASK(%rip), %xmm14
12267@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12268 * num_initial_blocks = b mod 4
12269 * encrypt the initial num_initial_blocks blocks and apply ghash on
12270 * the ciphertext
12271-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12272+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12273 * are clobbered
12274 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12275 */
12276@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12277 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12278 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12279 mov arg7, %r10 # %r10 = AAD
12280- mov arg8, %r12 # %r12 = aadLen
12281- mov %r12, %r11
12282+ mov arg8, %r15 # %r15 = aadLen
12283+ mov %r15, %r11
12284 pxor %xmm\i, %xmm\i
12285 _get_AAD_loop\num_initial_blocks\operation:
12286 movd (%r10), \TMP1
12287@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12288 psrldq $4, %xmm\i
12289 pxor \TMP1, %xmm\i
12290 add $4, %r10
12291- sub $4, %r12
12292+ sub $4, %r15
12293 jne _get_AAD_loop\num_initial_blocks\operation
12294 cmp $16, %r11
12295 je _get_AAD_loop2_done\num_initial_blocks\operation
12296- mov $16, %r12
12297+ mov $16, %r15
12298 _get_AAD_loop2\num_initial_blocks\operation:
12299 psrldq $4, %xmm\i
12300- sub $4, %r12
12301- cmp %r11, %r12
12302+ sub $4, %r15
12303+ cmp %r11, %r15
12304 jne _get_AAD_loop2\num_initial_blocks\operation
12305 _get_AAD_loop2_done\num_initial_blocks\operation:
12306 movdqa SHUF_MASK(%rip), %xmm14
12307@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12308 *
12309 *****************************************************************************/
12310 ENTRY(aesni_gcm_dec)
12311- push %r12
12312+ push %r15
12313 push %r13
12314 push %r14
12315 mov %rsp, %r14
12316@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12317 */
12318 sub $VARIABLE_OFFSET, %rsp
12319 and $~63, %rsp # align rsp to 64 bytes
12320- mov %arg6, %r12
12321- movdqu (%r12), %xmm13 # %xmm13 = HashKey
12322+ mov %arg6, %r15
12323+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
12324 movdqa SHUF_MASK(%rip), %xmm2
12325 PSHUFB_XMM %xmm2, %xmm13
12326
12327@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12328 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12329 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12330 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12331- mov %r13, %r12
12332- and $(3<<4), %r12
12333+ mov %r13, %r15
12334+ and $(3<<4), %r15
12335 jz _initial_num_blocks_is_0_decrypt
12336- cmp $(2<<4), %r12
12337+ cmp $(2<<4), %r15
12338 jb _initial_num_blocks_is_1_decrypt
12339 je _initial_num_blocks_is_2_decrypt
12340 _initial_num_blocks_is_3_decrypt:
12341@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12342 sub $16, %r11
12343 add %r13, %r11
12344 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12345- lea SHIFT_MASK+16(%rip), %r12
12346- sub %r13, %r12
12347+ lea SHIFT_MASK+16(%rip), %r15
12348+ sub %r13, %r15
12349 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12350 # (%r13 is the number of bytes in plaintext mod 16)
12351- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12352+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12353 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12354
12355 movdqa %xmm1, %xmm2
12356 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12357- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12358+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12359 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12360 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12361 pand %xmm1, %xmm2
12362@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12363 sub $1, %r13
12364 jne _less_than_8_bytes_left_decrypt
12365 _multiple_of_16_bytes_decrypt:
12366- mov arg8, %r12 # %r13 = aadLen (number of bytes)
12367- shl $3, %r12 # convert into number of bits
12368- movd %r12d, %xmm15 # len(A) in %xmm15
12369+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
12370+ shl $3, %r15 # convert into number of bits
12371+ movd %r15d, %xmm15 # len(A) in %xmm15
12372 shl $3, %arg4 # len(C) in bits (*128)
12373 MOVQ_R64_XMM %arg4, %xmm1
12374 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12375@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12376 mov %r14, %rsp
12377 pop %r14
12378 pop %r13
12379- pop %r12
12380+ pop %r15
12381+ pax_force_retaddr
12382 ret
12383 ENDPROC(aesni_gcm_dec)
12384
12385@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12386 * poly = x^128 + x^127 + x^126 + x^121 + 1
12387 ***************************************************************************/
12388 ENTRY(aesni_gcm_enc)
12389- push %r12
12390+ push %r15
12391 push %r13
12392 push %r14
12393 mov %rsp, %r14
12394@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12395 #
12396 sub $VARIABLE_OFFSET, %rsp
12397 and $~63, %rsp
12398- mov %arg6, %r12
12399- movdqu (%r12), %xmm13
12400+ mov %arg6, %r15
12401+ movdqu (%r15), %xmm13
12402 movdqa SHUF_MASK(%rip), %xmm2
12403 PSHUFB_XMM %xmm2, %xmm13
12404
12405@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12406 movdqa %xmm13, HashKey(%rsp)
12407 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12408 and $-16, %r13
12409- mov %r13, %r12
12410+ mov %r13, %r15
12411
12412 # Encrypt first few blocks
12413
12414- and $(3<<4), %r12
12415+ and $(3<<4), %r15
12416 jz _initial_num_blocks_is_0_encrypt
12417- cmp $(2<<4), %r12
12418+ cmp $(2<<4), %r15
12419 jb _initial_num_blocks_is_1_encrypt
12420 je _initial_num_blocks_is_2_encrypt
12421 _initial_num_blocks_is_3_encrypt:
12422@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
12423 sub $16, %r11
12424 add %r13, %r11
12425 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
12426- lea SHIFT_MASK+16(%rip), %r12
12427- sub %r13, %r12
12428+ lea SHIFT_MASK+16(%rip), %r15
12429+ sub %r13, %r15
12430 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
12431 # (%r13 is the number of bytes in plaintext mod 16)
12432- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12433+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12434 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
12435 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
12436- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12437+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12438 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
12439 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
12440 movdqa SHUF_MASK(%rip), %xmm10
12441@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
12442 sub $1, %r13
12443 jne _less_than_8_bytes_left_encrypt
12444 _multiple_of_16_bytes_encrypt:
12445- mov arg8, %r12 # %r12 = addLen (number of bytes)
12446- shl $3, %r12
12447- movd %r12d, %xmm15 # len(A) in %xmm15
12448+ mov arg8, %r15 # %r15 = addLen (number of bytes)
12449+ shl $3, %r15
12450+ movd %r15d, %xmm15 # len(A) in %xmm15
12451 shl $3, %arg4 # len(C) in bits (*128)
12452 MOVQ_R64_XMM %arg4, %xmm1
12453 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12454@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
12455 mov %r14, %rsp
12456 pop %r14
12457 pop %r13
12458- pop %r12
12459+ pop %r15
12460+ pax_force_retaddr
12461 ret
12462 ENDPROC(aesni_gcm_enc)
12463
12464@@ -1722,6 +1725,7 @@ _key_expansion_256a:
12465 pxor %xmm1, %xmm0
12466 movaps %xmm0, (TKEYP)
12467 add $0x10, TKEYP
12468+ pax_force_retaddr
12469 ret
12470 ENDPROC(_key_expansion_128)
12471 ENDPROC(_key_expansion_256a)
12472@@ -1748,6 +1752,7 @@ _key_expansion_192a:
12473 shufps $0b01001110, %xmm2, %xmm1
12474 movaps %xmm1, 0x10(TKEYP)
12475 add $0x20, TKEYP
12476+ pax_force_retaddr
12477 ret
12478 ENDPROC(_key_expansion_192a)
12479
12480@@ -1768,6 +1773,7 @@ _key_expansion_192b:
12481
12482 movaps %xmm0, (TKEYP)
12483 add $0x10, TKEYP
12484+ pax_force_retaddr
12485 ret
12486 ENDPROC(_key_expansion_192b)
12487
12488@@ -1781,6 +1787,7 @@ _key_expansion_256b:
12489 pxor %xmm1, %xmm2
12490 movaps %xmm2, (TKEYP)
12491 add $0x10, TKEYP
12492+ pax_force_retaddr
12493 ret
12494 ENDPROC(_key_expansion_256b)
12495
12496@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12497 #ifndef __x86_64__
12498 popl KEYP
12499 #endif
12500+ pax_force_retaddr
12501 ret
12502 ENDPROC(aesni_set_key)
12503
12504@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12505 popl KLEN
12506 popl KEYP
12507 #endif
12508+ pax_force_retaddr
12509 ret
12510 ENDPROC(aesni_enc)
12511
12512@@ -1974,6 +1983,7 @@ _aesni_enc1:
12513 AESENC KEY STATE
12514 movaps 0x70(TKEYP), KEY
12515 AESENCLAST KEY STATE
12516+ pax_force_retaddr
12517 ret
12518 ENDPROC(_aesni_enc1)
12519
12520@@ -2083,6 +2093,7 @@ _aesni_enc4:
12521 AESENCLAST KEY STATE2
12522 AESENCLAST KEY STATE3
12523 AESENCLAST KEY STATE4
12524+ pax_force_retaddr
12525 ret
12526 ENDPROC(_aesni_enc4)
12527
12528@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12529 popl KLEN
12530 popl KEYP
12531 #endif
12532+ pax_force_retaddr
12533 ret
12534 ENDPROC(aesni_dec)
12535
12536@@ -2164,6 +2176,7 @@ _aesni_dec1:
12537 AESDEC KEY STATE
12538 movaps 0x70(TKEYP), KEY
12539 AESDECLAST KEY STATE
12540+ pax_force_retaddr
12541 ret
12542 ENDPROC(_aesni_dec1)
12543
12544@@ -2273,6 +2286,7 @@ _aesni_dec4:
12545 AESDECLAST KEY STATE2
12546 AESDECLAST KEY STATE3
12547 AESDECLAST KEY STATE4
12548+ pax_force_retaddr
12549 ret
12550 ENDPROC(_aesni_dec4)
12551
12552@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12553 popl KEYP
12554 popl LEN
12555 #endif
12556+ pax_force_retaddr
12557 ret
12558 ENDPROC(aesni_ecb_enc)
12559
12560@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12561 popl KEYP
12562 popl LEN
12563 #endif
12564+ pax_force_retaddr
12565 ret
12566 ENDPROC(aesni_ecb_dec)
12567
12568@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
12569 popl LEN
12570 popl IVP
12571 #endif
12572+ pax_force_retaddr
12573 ret
12574 ENDPROC(aesni_cbc_enc)
12575
12576@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
12577 popl LEN
12578 popl IVP
12579 #endif
12580+ pax_force_retaddr
12581 ret
12582 ENDPROC(aesni_cbc_dec)
12583
12584@@ -2550,6 +2568,7 @@ _aesni_inc_init:
12585 mov $1, TCTR_LOW
12586 MOVQ_R64_XMM TCTR_LOW INC
12587 MOVQ_R64_XMM CTR TCTR_LOW
12588+ pax_force_retaddr
12589 ret
12590 ENDPROC(_aesni_inc_init)
12591
12592@@ -2579,6 +2598,7 @@ _aesni_inc:
12593 .Linc_low:
12594 movaps CTR, IV
12595 PSHUFB_XMM BSWAP_MASK IV
12596+ pax_force_retaddr
12597 ret
12598 ENDPROC(_aesni_inc)
12599
12600@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
12601 .Lctr_enc_ret:
12602 movups IV, (IVP)
12603 .Lctr_enc_just_ret:
12604+ pax_force_retaddr
12605 ret
12606 ENDPROC(aesni_ctr_enc)
12607
12608@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
12609 pxor INC, STATE4
12610 movdqu STATE4, 0x70(OUTP)
12611
12612+ pax_force_retaddr
12613 ret
12614 ENDPROC(aesni_xts_crypt8)
12615
12616diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12617index 246c670..466e2d6 100644
12618--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
12619+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12620@@ -21,6 +21,7 @@
12621 */
12622
12623 #include <linux/linkage.h>
12624+#include <asm/alternative-asm.h>
12625
12626 .file "blowfish-x86_64-asm.S"
12627 .text
12628@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
12629 jnz .L__enc_xor;
12630
12631 write_block();
12632+ pax_force_retaddr
12633 ret;
12634 .L__enc_xor:
12635 xor_block();
12636+ pax_force_retaddr
12637 ret;
12638 ENDPROC(__blowfish_enc_blk)
12639
12640@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
12641
12642 movq %r11, %rbp;
12643
12644+ pax_force_retaddr
12645 ret;
12646 ENDPROC(blowfish_dec_blk)
12647
12648@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
12649
12650 popq %rbx;
12651 popq %rbp;
12652+ pax_force_retaddr
12653 ret;
12654
12655 .L__enc_xor4:
12656@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
12657
12658 popq %rbx;
12659 popq %rbp;
12660+ pax_force_retaddr
12661 ret;
12662 ENDPROC(__blowfish_enc_blk_4way)
12663
12664@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
12665 popq %rbx;
12666 popq %rbp;
12667
12668+ pax_force_retaddr
12669 ret;
12670 ENDPROC(blowfish_dec_blk_4way)
12671diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12672index ce71f92..1dce7ec 100644
12673--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12674+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12675@@ -16,6 +16,7 @@
12676 */
12677
12678 #include <linux/linkage.h>
12679+#include <asm/alternative-asm.h>
12680
12681 #define CAMELLIA_TABLE_BYTE_LEN 272
12682
12683@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12684 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
12685 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
12686 %rcx, (%r9));
12687+ pax_force_retaddr
12688 ret;
12689 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12690
12691@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12692 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
12693 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
12694 %rax, (%r9));
12695+ pax_force_retaddr
12696 ret;
12697 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12698
12699@@ -780,6 +783,7 @@ __camellia_enc_blk16:
12700 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12701 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
12702
12703+ pax_force_retaddr
12704 ret;
12705
12706 .align 8
12707@@ -865,6 +869,7 @@ __camellia_dec_blk16:
12708 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12709 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
12710
12711+ pax_force_retaddr
12712 ret;
12713
12714 .align 8
12715@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
12716 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12717 %xmm8, %rsi);
12718
12719+ pax_force_retaddr
12720 ret;
12721 ENDPROC(camellia_ecb_enc_16way)
12722
12723@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
12724 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12725 %xmm8, %rsi);
12726
12727+ pax_force_retaddr
12728 ret;
12729 ENDPROC(camellia_ecb_dec_16way)
12730
12731@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
12732 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12733 %xmm8, %rsi);
12734
12735+ pax_force_retaddr
12736 ret;
12737 ENDPROC(camellia_cbc_dec_16way)
12738
12739@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
12740 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12741 %xmm8, %rsi);
12742
12743+ pax_force_retaddr
12744 ret;
12745 ENDPROC(camellia_ctr_16way)
12746
12747@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
12748 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12749 %xmm8, %rsi);
12750
12751+ pax_force_retaddr
12752 ret;
12753 ENDPROC(camellia_xts_crypt_16way)
12754
12755diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12756index 0e0b886..5a3123c 100644
12757--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12758+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12759@@ -11,6 +11,7 @@
12760 */
12761
12762 #include <linux/linkage.h>
12763+#include <asm/alternative-asm.h>
12764
12765 #define CAMELLIA_TABLE_BYTE_LEN 272
12766
12767@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12768 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
12769 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
12770 %rcx, (%r9));
12771+ pax_force_retaddr
12772 ret;
12773 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12774
12775@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12776 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
12777 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
12778 %rax, (%r9));
12779+ pax_force_retaddr
12780 ret;
12781 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12782
12783@@ -820,6 +823,7 @@ __camellia_enc_blk32:
12784 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12785 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
12786
12787+ pax_force_retaddr
12788 ret;
12789
12790 .align 8
12791@@ -905,6 +909,7 @@ __camellia_dec_blk32:
12792 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12793 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
12794
12795+ pax_force_retaddr
12796 ret;
12797
12798 .align 8
12799@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
12800
12801 vzeroupper;
12802
12803+ pax_force_retaddr
12804 ret;
12805 ENDPROC(camellia_ecb_enc_32way)
12806
12807@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
12808
12809 vzeroupper;
12810
12811+ pax_force_retaddr
12812 ret;
12813 ENDPROC(camellia_ecb_dec_32way)
12814
12815@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
12816
12817 vzeroupper;
12818
12819+ pax_force_retaddr
12820 ret;
12821 ENDPROC(camellia_cbc_dec_32way)
12822
12823@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
12824
12825 vzeroupper;
12826
12827+ pax_force_retaddr
12828 ret;
12829 ENDPROC(camellia_ctr_32way)
12830
12831@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
12832
12833 vzeroupper;
12834
12835+ pax_force_retaddr
12836 ret;
12837 ENDPROC(camellia_xts_crypt_32way)
12838
12839diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
12840index 310319c..db3d7b5 100644
12841--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
12842+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
12843@@ -21,6 +21,7 @@
12844 */
12845
12846 #include <linux/linkage.h>
12847+#include <asm/alternative-asm.h>
12848
12849 .file "camellia-x86_64-asm_64.S"
12850 .text
12851@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
12852 enc_outunpack(mov, RT1);
12853
12854 movq RRBP, %rbp;
12855+ pax_force_retaddr
12856 ret;
12857
12858 .L__enc_xor:
12859 enc_outunpack(xor, RT1);
12860
12861 movq RRBP, %rbp;
12862+ pax_force_retaddr
12863 ret;
12864 ENDPROC(__camellia_enc_blk)
12865
12866@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
12867 dec_outunpack();
12868
12869 movq RRBP, %rbp;
12870+ pax_force_retaddr
12871 ret;
12872 ENDPROC(camellia_dec_blk)
12873
12874@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
12875
12876 movq RRBP, %rbp;
12877 popq %rbx;
12878+ pax_force_retaddr
12879 ret;
12880
12881 .L__enc2_xor:
12882@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
12883
12884 movq RRBP, %rbp;
12885 popq %rbx;
12886+ pax_force_retaddr
12887 ret;
12888 ENDPROC(__camellia_enc_blk_2way)
12889
12890@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
12891
12892 movq RRBP, %rbp;
12893 movq RXOR, %rbx;
12894+ pax_force_retaddr
12895 ret;
12896 ENDPROC(camellia_dec_blk_2way)
12897diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12898index c35fd5d..2d8c7db 100644
12899--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12900+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12901@@ -24,6 +24,7 @@
12902 */
12903
12904 #include <linux/linkage.h>
12905+#include <asm/alternative-asm.h>
12906
12907 .file "cast5-avx-x86_64-asm_64.S"
12908
12909@@ -281,6 +282,7 @@ __cast5_enc_blk16:
12910 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12911 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12912
12913+ pax_force_retaddr
12914 ret;
12915 ENDPROC(__cast5_enc_blk16)
12916
12917@@ -352,6 +354,7 @@ __cast5_dec_blk16:
12918 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12919 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12920
12921+ pax_force_retaddr
12922 ret;
12923
12924 .L__skip_dec:
12925@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
12926 vmovdqu RR4, (6*4*4)(%r11);
12927 vmovdqu RL4, (7*4*4)(%r11);
12928
12929+ pax_force_retaddr
12930 ret;
12931 ENDPROC(cast5_ecb_enc_16way)
12932
12933@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
12934 vmovdqu RR4, (6*4*4)(%r11);
12935 vmovdqu RL4, (7*4*4)(%r11);
12936
12937+ pax_force_retaddr
12938 ret;
12939 ENDPROC(cast5_ecb_dec_16way)
12940
12941@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
12942 * %rdx: src
12943 */
12944
12945- pushq %r12;
12946+ pushq %r14;
12947
12948 movq %rsi, %r11;
12949- movq %rdx, %r12;
12950+ movq %rdx, %r14;
12951
12952 vmovdqu (0*16)(%rdx), RL1;
12953 vmovdqu (1*16)(%rdx), RR1;
12954@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
12955 call __cast5_dec_blk16;
12956
12957 /* xor with src */
12958- vmovq (%r12), RX;
12959+ vmovq (%r14), RX;
12960 vpshufd $0x4f, RX, RX;
12961 vpxor RX, RR1, RR1;
12962- vpxor 0*16+8(%r12), RL1, RL1;
12963- vpxor 1*16+8(%r12), RR2, RR2;
12964- vpxor 2*16+8(%r12), RL2, RL2;
12965- vpxor 3*16+8(%r12), RR3, RR3;
12966- vpxor 4*16+8(%r12), RL3, RL3;
12967- vpxor 5*16+8(%r12), RR4, RR4;
12968- vpxor 6*16+8(%r12), RL4, RL4;
12969+ vpxor 0*16+8(%r14), RL1, RL1;
12970+ vpxor 1*16+8(%r14), RR2, RR2;
12971+ vpxor 2*16+8(%r14), RL2, RL2;
12972+ vpxor 3*16+8(%r14), RR3, RR3;
12973+ vpxor 4*16+8(%r14), RL3, RL3;
12974+ vpxor 5*16+8(%r14), RR4, RR4;
12975+ vpxor 6*16+8(%r14), RL4, RL4;
12976
12977 vmovdqu RR1, (0*16)(%r11);
12978 vmovdqu RL1, (1*16)(%r11);
12979@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
12980 vmovdqu RR4, (6*16)(%r11);
12981 vmovdqu RL4, (7*16)(%r11);
12982
12983- popq %r12;
12984+ popq %r14;
12985
12986+ pax_force_retaddr
12987 ret;
12988 ENDPROC(cast5_cbc_dec_16way)
12989
12990@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
12991 * %rcx: iv (big endian, 64bit)
12992 */
12993
12994- pushq %r12;
12995+ pushq %r14;
12996
12997 movq %rsi, %r11;
12998- movq %rdx, %r12;
12999+ movq %rdx, %r14;
13000
13001 vpcmpeqd RTMP, RTMP, RTMP;
13002 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13003@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13004 call __cast5_enc_blk16;
13005
13006 /* dst = src ^ iv */
13007- vpxor (0*16)(%r12), RR1, RR1;
13008- vpxor (1*16)(%r12), RL1, RL1;
13009- vpxor (2*16)(%r12), RR2, RR2;
13010- vpxor (3*16)(%r12), RL2, RL2;
13011- vpxor (4*16)(%r12), RR3, RR3;
13012- vpxor (5*16)(%r12), RL3, RL3;
13013- vpxor (6*16)(%r12), RR4, RR4;
13014- vpxor (7*16)(%r12), RL4, RL4;
13015+ vpxor (0*16)(%r14), RR1, RR1;
13016+ vpxor (1*16)(%r14), RL1, RL1;
13017+ vpxor (2*16)(%r14), RR2, RR2;
13018+ vpxor (3*16)(%r14), RL2, RL2;
13019+ vpxor (4*16)(%r14), RR3, RR3;
13020+ vpxor (5*16)(%r14), RL3, RL3;
13021+ vpxor (6*16)(%r14), RR4, RR4;
13022+ vpxor (7*16)(%r14), RL4, RL4;
13023 vmovdqu RR1, (0*16)(%r11);
13024 vmovdqu RL1, (1*16)(%r11);
13025 vmovdqu RR2, (2*16)(%r11);
13026@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13027 vmovdqu RR4, (6*16)(%r11);
13028 vmovdqu RL4, (7*16)(%r11);
13029
13030- popq %r12;
13031+ popq %r14;
13032
13033+ pax_force_retaddr
13034 ret;
13035 ENDPROC(cast5_ctr_16way)
13036diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13037index e3531f8..e123f35 100644
13038--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13039+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13040@@ -24,6 +24,7 @@
13041 */
13042
13043 #include <linux/linkage.h>
13044+#include <asm/alternative-asm.h>
13045 #include "glue_helper-asm-avx.S"
13046
13047 .file "cast6-avx-x86_64-asm_64.S"
13048@@ -295,6 +296,7 @@ __cast6_enc_blk8:
13049 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13050 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13051
13052+ pax_force_retaddr
13053 ret;
13054 ENDPROC(__cast6_enc_blk8)
13055
13056@@ -340,6 +342,7 @@ __cast6_dec_blk8:
13057 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13058 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13059
13060+ pax_force_retaddr
13061 ret;
13062 ENDPROC(__cast6_dec_blk8)
13063
13064@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13065
13066 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13067
13068+ pax_force_retaddr
13069 ret;
13070 ENDPROC(cast6_ecb_enc_8way)
13071
13072@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13073
13074 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13075
13076+ pax_force_retaddr
13077 ret;
13078 ENDPROC(cast6_ecb_dec_8way)
13079
13080@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13081 * %rdx: src
13082 */
13083
13084- pushq %r12;
13085+ pushq %r14;
13086
13087 movq %rsi, %r11;
13088- movq %rdx, %r12;
13089+ movq %rdx, %r14;
13090
13091 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13092
13093 call __cast6_dec_blk8;
13094
13095- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13096+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13097
13098- popq %r12;
13099+ popq %r14;
13100
13101+ pax_force_retaddr
13102 ret;
13103 ENDPROC(cast6_cbc_dec_8way)
13104
13105@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13106 * %rcx: iv (little endian, 128bit)
13107 */
13108
13109- pushq %r12;
13110+ pushq %r14;
13111
13112 movq %rsi, %r11;
13113- movq %rdx, %r12;
13114+ movq %rdx, %r14;
13115
13116 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13117 RD2, RX, RKR, RKM);
13118
13119 call __cast6_enc_blk8;
13120
13121- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13122+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13123
13124- popq %r12;
13125+ popq %r14;
13126
13127+ pax_force_retaddr
13128 ret;
13129 ENDPROC(cast6_ctr_8way)
13130
13131@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13132 /* dst <= regs xor IVs(in dst) */
13133 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13134
13135+ pax_force_retaddr
13136 ret;
13137 ENDPROC(cast6_xts_enc_8way)
13138
13139@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13140 /* dst <= regs xor IVs(in dst) */
13141 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13142
13143+ pax_force_retaddr
13144 ret;
13145 ENDPROC(cast6_xts_dec_8way)
13146diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13147index dbc4339..de6e120 100644
13148--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13149+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13150@@ -45,6 +45,7 @@
13151
13152 #include <asm/inst.h>
13153 #include <linux/linkage.h>
13154+#include <asm/alternative-asm.h>
13155
13156 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13157
13158@@ -312,6 +313,7 @@ do_return:
13159 popq %rsi
13160 popq %rdi
13161 popq %rbx
13162+ pax_force_retaddr
13163 ret
13164
13165 ################################################################
13166diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13167index 586f41a..d02851e 100644
13168--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13169+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13170@@ -18,6 +18,7 @@
13171
13172 #include <linux/linkage.h>
13173 #include <asm/inst.h>
13174+#include <asm/alternative-asm.h>
13175
13176 .data
13177
13178@@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
13179 psrlq $1, T2
13180 pxor T2, T1
13181 pxor T1, DATA
13182+ pax_force_retaddr
13183 ret
13184 ENDPROC(__clmul_gf128mul_ble)
13185
13186@@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
13187 call __clmul_gf128mul_ble
13188 PSHUFB_XMM BSWAP DATA
13189 movups DATA, (%rdi)
13190+ pax_force_retaddr
13191 ret
13192 ENDPROC(clmul_ghash_mul)
13193
13194@@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
13195 PSHUFB_XMM BSWAP DATA
13196 movups DATA, (%rdi)
13197 .Lupdate_just_ret:
13198+ pax_force_retaddr
13199 ret
13200 ENDPROC(clmul_ghash_update)
13201
13202@@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
13203 pand .Lpoly, %xmm1
13204 pxor %xmm1, %xmm0
13205 movups %xmm0, (%rdi)
13206+ pax_force_retaddr
13207 ret
13208 ENDPROC(clmul_ghash_setkey)
13209diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13210index 9279e0b..c4b3d2c 100644
13211--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13212+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13213@@ -1,4 +1,5 @@
13214 #include <linux/linkage.h>
13215+#include <asm/alternative-asm.h>
13216
13217 # enter salsa20_encrypt_bytes
13218 ENTRY(salsa20_encrypt_bytes)
13219@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13220 add %r11,%rsp
13221 mov %rdi,%rax
13222 mov %rsi,%rdx
13223+ pax_force_retaddr
13224 ret
13225 # bytesatleast65:
13226 ._bytesatleast65:
13227@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13228 add %r11,%rsp
13229 mov %rdi,%rax
13230 mov %rsi,%rdx
13231+ pax_force_retaddr
13232 ret
13233 ENDPROC(salsa20_keysetup)
13234
13235@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13236 add %r11,%rsp
13237 mov %rdi,%rax
13238 mov %rsi,%rdx
13239+ pax_force_retaddr
13240 ret
13241 ENDPROC(salsa20_ivsetup)
13242diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13243index 2f202f4..d9164d6 100644
13244--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13245+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13246@@ -24,6 +24,7 @@
13247 */
13248
13249 #include <linux/linkage.h>
13250+#include <asm/alternative-asm.h>
13251 #include "glue_helper-asm-avx.S"
13252
13253 .file "serpent-avx-x86_64-asm_64.S"
13254@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13255 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13256 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13257
13258+ pax_force_retaddr
13259 ret;
13260 ENDPROC(__serpent_enc_blk8_avx)
13261
13262@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13263 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13264 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13265
13266+ pax_force_retaddr
13267 ret;
13268 ENDPROC(__serpent_dec_blk8_avx)
13269
13270@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13271
13272 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13273
13274+ pax_force_retaddr
13275 ret;
13276 ENDPROC(serpent_ecb_enc_8way_avx)
13277
13278@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13279
13280 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13281
13282+ pax_force_retaddr
13283 ret;
13284 ENDPROC(serpent_ecb_dec_8way_avx)
13285
13286@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13287
13288 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13289
13290+ pax_force_retaddr
13291 ret;
13292 ENDPROC(serpent_cbc_dec_8way_avx)
13293
13294@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13295
13296 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13297
13298+ pax_force_retaddr
13299 ret;
13300 ENDPROC(serpent_ctr_8way_avx)
13301
13302@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13303 /* dst <= regs xor IVs(in dst) */
13304 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13305
13306+ pax_force_retaddr
13307 ret;
13308 ENDPROC(serpent_xts_enc_8way_avx)
13309
13310@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13311 /* dst <= regs xor IVs(in dst) */
13312 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13313
13314+ pax_force_retaddr
13315 ret;
13316 ENDPROC(serpent_xts_dec_8way_avx)
13317diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13318index b222085..abd483c 100644
13319--- a/arch/x86/crypto/serpent-avx2-asm_64.S
13320+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13321@@ -15,6 +15,7 @@
13322 */
13323
13324 #include <linux/linkage.h>
13325+#include <asm/alternative-asm.h>
13326 #include "glue_helper-asm-avx2.S"
13327
13328 .file "serpent-avx2-asm_64.S"
13329@@ -610,6 +611,7 @@ __serpent_enc_blk16:
13330 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13331 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13332
13333+ pax_force_retaddr
13334 ret;
13335 ENDPROC(__serpent_enc_blk16)
13336
13337@@ -664,6 +666,7 @@ __serpent_dec_blk16:
13338 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13339 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13340
13341+ pax_force_retaddr
13342 ret;
13343 ENDPROC(__serpent_dec_blk16)
13344
13345@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13346
13347 vzeroupper;
13348
13349+ pax_force_retaddr
13350 ret;
13351 ENDPROC(serpent_ecb_enc_16way)
13352
13353@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13354
13355 vzeroupper;
13356
13357+ pax_force_retaddr
13358 ret;
13359 ENDPROC(serpent_ecb_dec_16way)
13360
13361@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13362
13363 vzeroupper;
13364
13365+ pax_force_retaddr
13366 ret;
13367 ENDPROC(serpent_cbc_dec_16way)
13368
13369@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13370
13371 vzeroupper;
13372
13373+ pax_force_retaddr
13374 ret;
13375 ENDPROC(serpent_ctr_16way)
13376
13377@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13378
13379 vzeroupper;
13380
13381+ pax_force_retaddr
13382 ret;
13383 ENDPROC(serpent_xts_enc_16way)
13384
13385@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13386
13387 vzeroupper;
13388
13389+ pax_force_retaddr
13390 ret;
13391 ENDPROC(serpent_xts_dec_16way)
13392diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13393index acc066c..1559cc4 100644
13394--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13395+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13396@@ -25,6 +25,7 @@
13397 */
13398
13399 #include <linux/linkage.h>
13400+#include <asm/alternative-asm.h>
13401
13402 .file "serpent-sse2-x86_64-asm_64.S"
13403 .text
13404@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13405 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13406 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13407
13408+ pax_force_retaddr
13409 ret;
13410
13411 .L__enc_xor8:
13412 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13413 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13414
13415+ pax_force_retaddr
13416 ret;
13417 ENDPROC(__serpent_enc_blk_8way)
13418
13419@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13420 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13421 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13422
13423+ pax_force_retaddr
13424 ret;
13425 ENDPROC(serpent_dec_blk_8way)
13426diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13427index a410950..9dfe7ad 100644
13428--- a/arch/x86/crypto/sha1_ssse3_asm.S
13429+++ b/arch/x86/crypto/sha1_ssse3_asm.S
13430@@ -29,6 +29,7 @@
13431 */
13432
13433 #include <linux/linkage.h>
13434+#include <asm/alternative-asm.h>
13435
13436 #define CTX %rdi // arg1
13437 #define BUF %rsi // arg2
13438@@ -75,9 +76,9 @@
13439
13440 push %rbx
13441 push %rbp
13442- push %r12
13443+ push %r14
13444
13445- mov %rsp, %r12
13446+ mov %rsp, %r14
13447 sub $64, %rsp # allocate workspace
13448 and $~15, %rsp # align stack
13449
13450@@ -99,11 +100,12 @@
13451 xor %rax, %rax
13452 rep stosq
13453
13454- mov %r12, %rsp # deallocate workspace
13455+ mov %r14, %rsp # deallocate workspace
13456
13457- pop %r12
13458+ pop %r14
13459 pop %rbp
13460 pop %rbx
13461+ pax_force_retaddr
13462 ret
13463
13464 ENDPROC(\name)
13465diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13466index 642f156..51a513c 100644
13467--- a/arch/x86/crypto/sha256-avx-asm.S
13468+++ b/arch/x86/crypto/sha256-avx-asm.S
13469@@ -49,6 +49,7 @@
13470
13471 #ifdef CONFIG_AS_AVX
13472 #include <linux/linkage.h>
13473+#include <asm/alternative-asm.h>
13474
13475 ## assume buffers not aligned
13476 #define VMOVDQ vmovdqu
13477@@ -460,6 +461,7 @@ done_hash:
13478 popq %r13
13479 popq %rbp
13480 popq %rbx
13481+ pax_force_retaddr
13482 ret
13483 ENDPROC(sha256_transform_avx)
13484
13485diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
13486index 9e86944..3795e6a 100644
13487--- a/arch/x86/crypto/sha256-avx2-asm.S
13488+++ b/arch/x86/crypto/sha256-avx2-asm.S
13489@@ -50,6 +50,7 @@
13490
13491 #ifdef CONFIG_AS_AVX2
13492 #include <linux/linkage.h>
13493+#include <asm/alternative-asm.h>
13494
13495 ## assume buffers not aligned
13496 #define VMOVDQ vmovdqu
13497@@ -720,6 +721,7 @@ done_hash:
13498 popq %r12
13499 popq %rbp
13500 popq %rbx
13501+ pax_force_retaddr
13502 ret
13503 ENDPROC(sha256_transform_rorx)
13504
13505diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13506index f833b74..8c62a9e 100644
13507--- a/arch/x86/crypto/sha256-ssse3-asm.S
13508+++ b/arch/x86/crypto/sha256-ssse3-asm.S
13509@@ -47,6 +47,7 @@
13510 ########################################################################
13511
13512 #include <linux/linkage.h>
13513+#include <asm/alternative-asm.h>
13514
13515 ## assume buffers not aligned
13516 #define MOVDQ movdqu
13517@@ -471,6 +472,7 @@ done_hash:
13518 popq %rbp
13519 popq %rbx
13520
13521+ pax_force_retaddr
13522 ret
13523 ENDPROC(sha256_transform_ssse3)
13524
13525diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
13526index 974dde9..a823ff9 100644
13527--- a/arch/x86/crypto/sha512-avx-asm.S
13528+++ b/arch/x86/crypto/sha512-avx-asm.S
13529@@ -49,6 +49,7 @@
13530
13531 #ifdef CONFIG_AS_AVX
13532 #include <linux/linkage.h>
13533+#include <asm/alternative-asm.h>
13534
13535 .text
13536
13537@@ -364,6 +365,7 @@ updateblock:
13538 mov frame_RSPSAVE(%rsp), %rsp
13539
13540 nowork:
13541+ pax_force_retaddr
13542 ret
13543 ENDPROC(sha512_transform_avx)
13544
13545diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
13546index 568b961..ed20c37 100644
13547--- a/arch/x86/crypto/sha512-avx2-asm.S
13548+++ b/arch/x86/crypto/sha512-avx2-asm.S
13549@@ -51,6 +51,7 @@
13550
13551 #ifdef CONFIG_AS_AVX2
13552 #include <linux/linkage.h>
13553+#include <asm/alternative-asm.h>
13554
13555 .text
13556
13557@@ -678,6 +679,7 @@ done_hash:
13558
13559 # Restore Stack Pointer
13560 mov frame_RSPSAVE(%rsp), %rsp
13561+ pax_force_retaddr
13562 ret
13563 ENDPROC(sha512_transform_rorx)
13564
13565diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13566index fb56855..6edd768 100644
13567--- a/arch/x86/crypto/sha512-ssse3-asm.S
13568+++ b/arch/x86/crypto/sha512-ssse3-asm.S
13569@@ -48,6 +48,7 @@
13570 ########################################################################
13571
13572 #include <linux/linkage.h>
13573+#include <asm/alternative-asm.h>
13574
13575 .text
13576
13577@@ -363,6 +364,7 @@ updateblock:
13578 mov frame_RSPSAVE(%rsp), %rsp
13579
13580 nowork:
13581+ pax_force_retaddr
13582 ret
13583 ENDPROC(sha512_transform_ssse3)
13584
13585diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13586index 0505813..b067311 100644
13587--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13588+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13589@@ -24,6 +24,7 @@
13590 */
13591
13592 #include <linux/linkage.h>
13593+#include <asm/alternative-asm.h>
13594 #include "glue_helper-asm-avx.S"
13595
13596 .file "twofish-avx-x86_64-asm_64.S"
13597@@ -284,6 +285,7 @@ __twofish_enc_blk8:
13598 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
13599 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
13600
13601+ pax_force_retaddr
13602 ret;
13603 ENDPROC(__twofish_enc_blk8)
13604
13605@@ -324,6 +326,7 @@ __twofish_dec_blk8:
13606 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
13607 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
13608
13609+ pax_force_retaddr
13610 ret;
13611 ENDPROC(__twofish_dec_blk8)
13612
13613@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
13614
13615 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13616
13617+ pax_force_retaddr
13618 ret;
13619 ENDPROC(twofish_ecb_enc_8way)
13620
13621@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
13622
13623 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13624
13625+ pax_force_retaddr
13626 ret;
13627 ENDPROC(twofish_ecb_dec_8way)
13628
13629@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
13630 * %rdx: src
13631 */
13632
13633- pushq %r12;
13634+ pushq %r14;
13635
13636 movq %rsi, %r11;
13637- movq %rdx, %r12;
13638+ movq %rdx, %r14;
13639
13640 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13641
13642 call __twofish_dec_blk8;
13643
13644- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13645+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13646
13647- popq %r12;
13648+ popq %r14;
13649
13650+ pax_force_retaddr
13651 ret;
13652 ENDPROC(twofish_cbc_dec_8way)
13653
13654@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
13655 * %rcx: iv (little endian, 128bit)
13656 */
13657
13658- pushq %r12;
13659+ pushq %r14;
13660
13661 movq %rsi, %r11;
13662- movq %rdx, %r12;
13663+ movq %rdx, %r14;
13664
13665 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13666 RD2, RX0, RX1, RY0);
13667
13668 call __twofish_enc_blk8;
13669
13670- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13671+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13672
13673- popq %r12;
13674+ popq %r14;
13675
13676+ pax_force_retaddr
13677 ret;
13678 ENDPROC(twofish_ctr_8way)
13679
13680@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
13681 /* dst <= regs xor IVs(in dst) */
13682 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13683
13684+ pax_force_retaddr
13685 ret;
13686 ENDPROC(twofish_xts_enc_8way)
13687
13688@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
13689 /* dst <= regs xor IVs(in dst) */
13690 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13691
13692+ pax_force_retaddr
13693 ret;
13694 ENDPROC(twofish_xts_dec_8way)
13695diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13696index 1c3b7ce..02f578d 100644
13697--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13698+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13699@@ -21,6 +21,7 @@
13700 */
13701
13702 #include <linux/linkage.h>
13703+#include <asm/alternative-asm.h>
13704
13705 .file "twofish-x86_64-asm-3way.S"
13706 .text
13707@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
13708 popq %r13;
13709 popq %r14;
13710 popq %r15;
13711+ pax_force_retaddr
13712 ret;
13713
13714 .L__enc_xor3:
13715@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
13716 popq %r13;
13717 popq %r14;
13718 popq %r15;
13719+ pax_force_retaddr
13720 ret;
13721 ENDPROC(__twofish_enc_blk_3way)
13722
13723@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
13724 popq %r13;
13725 popq %r14;
13726 popq %r15;
13727+ pax_force_retaddr
13728 ret;
13729 ENDPROC(twofish_dec_blk_3way)
13730diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
13731index a039d21..524b8b2 100644
13732--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
13733+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
13734@@ -22,6 +22,7 @@
13735
13736 #include <linux/linkage.h>
13737 #include <asm/asm-offsets.h>
13738+#include <asm/alternative-asm.h>
13739
13740 #define a_offset 0
13741 #define b_offset 4
13742@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
13743
13744 popq R1
13745 movq $1,%rax
13746+ pax_force_retaddr
13747 ret
13748 ENDPROC(twofish_enc_blk)
13749
13750@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
13751
13752 popq R1
13753 movq $1,%rax
13754+ pax_force_retaddr
13755 ret
13756 ENDPROC(twofish_dec_blk)
13757diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
13758index d21ff89..6da8e6e 100644
13759--- a/arch/x86/ia32/ia32_aout.c
13760+++ b/arch/x86/ia32/ia32_aout.c
13761@@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
13762 unsigned long dump_start, dump_size;
13763 struct user32 dump;
13764
13765+ memset(&dump, 0, sizeof(dump));
13766+
13767 fs = get_fs();
13768 set_fs(KERNEL_DS);
13769 has_dumped = 1;
13770diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
13771index 2206757..85cbcfa 100644
13772--- a/arch/x86/ia32/ia32_signal.c
13773+++ b/arch/x86/ia32/ia32_signal.c
13774@@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
13775 if (__get_user(set.sig[0], &frame->sc.oldmask)
13776 || (_COMPAT_NSIG_WORDS > 1
13777 && __copy_from_user((((char *) &set.sig) + 4),
13778- &frame->extramask,
13779+ frame->extramask,
13780 sizeof(frame->extramask))))
13781 goto badframe;
13782
13783@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
13784 sp -= frame_size;
13785 /* Align the stack pointer according to the i386 ABI,
13786 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
13787- sp = ((sp + 4) & -16ul) - 4;
13788+ sp = ((sp - 12) & -16ul) - 4;
13789 return (void __user *) sp;
13790 }
13791
13792@@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13793 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13794 sigreturn);
13795 else
13796- restorer = &frame->retcode;
13797+ restorer = frame->retcode;
13798 }
13799
13800 put_user_try {
13801@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13802 * These are actually not used anymore, but left because some
13803 * gdb versions depend on them as a marker.
13804 */
13805- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13806+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13807 } put_user_catch(err);
13808
13809 if (err)
13810@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13811 0xb8,
13812 __NR_ia32_rt_sigreturn,
13813 0x80cd,
13814- 0,
13815+ 0
13816 };
13817
13818 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
13819@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13820
13821 if (ksig->ka.sa.sa_flags & SA_RESTORER)
13822 restorer = ksig->ka.sa.sa_restorer;
13823+ else if (current->mm->context.vdso)
13824+ /* Return stub is in 32bit vsyscall page */
13825+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
13826 else
13827- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13828- rt_sigreturn);
13829+ restorer = frame->retcode;
13830 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
13831
13832 /*
13833 * Not actually used anymore, but left because some gdb
13834 * versions need it.
13835 */
13836- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13837+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13838 } put_user_catch(err);
13839
13840 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
13841diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
13842index 4299eb0..c0687a7 100644
13843--- a/arch/x86/ia32/ia32entry.S
13844+++ b/arch/x86/ia32/ia32entry.S
13845@@ -15,8 +15,10 @@
13846 #include <asm/irqflags.h>
13847 #include <asm/asm.h>
13848 #include <asm/smap.h>
13849+#include <asm/pgtable.h>
13850 #include <linux/linkage.h>
13851 #include <linux/err.h>
13852+#include <asm/alternative-asm.h>
13853
13854 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13855 #include <linux/elf-em.h>
13856@@ -62,12 +64,12 @@
13857 */
13858 .macro LOAD_ARGS32 offset, _r9=0
13859 .if \_r9
13860- movl \offset+16(%rsp),%r9d
13861+ movl \offset+R9(%rsp),%r9d
13862 .endif
13863- movl \offset+40(%rsp),%ecx
13864- movl \offset+48(%rsp),%edx
13865- movl \offset+56(%rsp),%esi
13866- movl \offset+64(%rsp),%edi
13867+ movl \offset+RCX(%rsp),%ecx
13868+ movl \offset+RDX(%rsp),%edx
13869+ movl \offset+RSI(%rsp),%esi
13870+ movl \offset+RDI(%rsp),%edi
13871 movl %eax,%eax /* zero extension */
13872 .endm
13873
13874@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
13875 ENDPROC(native_irq_enable_sysexit)
13876 #endif
13877
13878+ .macro pax_enter_kernel_user
13879+ pax_set_fptr_mask
13880+#ifdef CONFIG_PAX_MEMORY_UDEREF
13881+ call pax_enter_kernel_user
13882+#endif
13883+ .endm
13884+
13885+ .macro pax_exit_kernel_user
13886+#ifdef CONFIG_PAX_MEMORY_UDEREF
13887+ call pax_exit_kernel_user
13888+#endif
13889+#ifdef CONFIG_PAX_RANDKSTACK
13890+ pushq %rax
13891+ pushq %r11
13892+ call pax_randomize_kstack
13893+ popq %r11
13894+ popq %rax
13895+#endif
13896+ .endm
13897+
13898+ .macro pax_erase_kstack
13899+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13900+ call pax_erase_kstack
13901+#endif
13902+ .endm
13903+
13904 /*
13905 * 32bit SYSENTER instruction entry.
13906 *
13907@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
13908 CFI_REGISTER rsp,rbp
13909 SWAPGS_UNSAFE_STACK
13910 movq PER_CPU_VAR(kernel_stack), %rsp
13911- addq $(KERNEL_STACK_OFFSET),%rsp
13912- /*
13913- * No need to follow this irqs on/off section: the syscall
13914- * disabled irqs, here we enable it straight after entry:
13915- */
13916- ENABLE_INTERRUPTS(CLBR_NONE)
13917 movl %ebp,%ebp /* zero extension */
13918 pushq_cfi $__USER32_DS
13919 /*CFI_REL_OFFSET ss,0*/
13920@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
13921 CFI_REL_OFFSET rsp,0
13922 pushfq_cfi
13923 /*CFI_REL_OFFSET rflags,0*/
13924- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
13925- CFI_REGISTER rip,r10
13926+ orl $X86_EFLAGS_IF,(%rsp)
13927+ GET_THREAD_INFO(%r11)
13928+ movl TI_sysenter_return(%r11), %r11d
13929+ CFI_REGISTER rip,r11
13930 pushq_cfi $__USER32_CS
13931 /*CFI_REL_OFFSET cs,0*/
13932 movl %eax, %eax
13933- pushq_cfi %r10
13934+ pushq_cfi %r11
13935 CFI_REL_OFFSET rip,0
13936 pushq_cfi %rax
13937 cld
13938 SAVE_ARGS 0,1,0
13939+ pax_enter_kernel_user
13940+
13941+#ifdef CONFIG_PAX_RANDKSTACK
13942+ pax_erase_kstack
13943+#endif
13944+
13945+ /*
13946+ * No need to follow this irqs on/off section: the syscall
13947+ * disabled irqs, here we enable it straight after entry:
13948+ */
13949+ ENABLE_INTERRUPTS(CLBR_NONE)
13950 /* no need to do an access_ok check here because rbp has been
13951 32bit zero extended */
13952+
13953+#ifdef CONFIG_PAX_MEMORY_UDEREF
13954+ addq pax_user_shadow_base,%rbp
13955+ ASM_PAX_OPEN_USERLAND
13956+#endif
13957+
13958 ASM_STAC
13959 1: movl (%rbp),%ebp
13960 _ASM_EXTABLE(1b,ia32_badarg)
13961 ASM_CLAC
13962- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13963- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13964+
13965+#ifdef CONFIG_PAX_MEMORY_UDEREF
13966+ ASM_PAX_CLOSE_USERLAND
13967+#endif
13968+
13969+ GET_THREAD_INFO(%r11)
13970+ orl $TS_COMPAT,TI_status(%r11)
13971+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13972 CFI_REMEMBER_STATE
13973 jnz sysenter_tracesys
13974 cmpq $(IA32_NR_syscalls-1),%rax
13975@@ -162,15 +209,18 @@ sysenter_do_call:
13976 sysenter_dispatch:
13977 call *ia32_sys_call_table(,%rax,8)
13978 movq %rax,RAX-ARGOFFSET(%rsp)
13979+ GET_THREAD_INFO(%r11)
13980 DISABLE_INTERRUPTS(CLBR_NONE)
13981 TRACE_IRQS_OFF
13982- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13983+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13984 jnz sysexit_audit
13985 sysexit_from_sys_call:
13986- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13987+ pax_exit_kernel_user
13988+ pax_erase_kstack
13989+ andl $~TS_COMPAT,TI_status(%r11)
13990 /* clear IF, that popfq doesn't enable interrupts early */
13991- andl $~0x200,EFLAGS-R11(%rsp)
13992- movl RIP-R11(%rsp),%edx /* User %eip */
13993+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
13994+ movl RIP(%rsp),%edx /* User %eip */
13995 CFI_REGISTER rip,rdx
13996 RESTORE_ARGS 0,24,0,0,0,0
13997 xorq %r8,%r8
13998@@ -193,6 +243,9 @@ sysexit_from_sys_call:
13999 movl %eax,%esi /* 2nd arg: syscall number */
14000 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14001 call __audit_syscall_entry
14002+
14003+ pax_erase_kstack
14004+
14005 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14006 cmpq $(IA32_NR_syscalls-1),%rax
14007 ja ia32_badsys
14008@@ -204,7 +257,7 @@ sysexit_from_sys_call:
14009 .endm
14010
14011 .macro auditsys_exit exit
14012- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14013+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14014 jnz ia32_ret_from_sys_call
14015 TRACE_IRQS_ON
14016 ENABLE_INTERRUPTS(CLBR_NONE)
14017@@ -215,11 +268,12 @@ sysexit_from_sys_call:
14018 1: setbe %al /* 1 if error, 0 if not */
14019 movzbl %al,%edi /* zero-extend that into %edi */
14020 call __audit_syscall_exit
14021+ GET_THREAD_INFO(%r11)
14022 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14023 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14024 DISABLE_INTERRUPTS(CLBR_NONE)
14025 TRACE_IRQS_OFF
14026- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14027+ testl %edi,TI_flags(%r11)
14028 jz \exit
14029 CLEAR_RREGS -ARGOFFSET
14030 jmp int_with_check
14031@@ -237,7 +291,7 @@ sysexit_audit:
14032
14033 sysenter_tracesys:
14034 #ifdef CONFIG_AUDITSYSCALL
14035- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14036+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14037 jz sysenter_auditsys
14038 #endif
14039 SAVE_REST
14040@@ -249,6 +303,9 @@ sysenter_tracesys:
14041 RESTORE_REST
14042 cmpq $(IA32_NR_syscalls-1),%rax
14043 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14044+
14045+ pax_erase_kstack
14046+
14047 jmp sysenter_do_call
14048 CFI_ENDPROC
14049 ENDPROC(ia32_sysenter_target)
14050@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14051 ENTRY(ia32_cstar_target)
14052 CFI_STARTPROC32 simple
14053 CFI_SIGNAL_FRAME
14054- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14055+ CFI_DEF_CFA rsp,0
14056 CFI_REGISTER rip,rcx
14057 /*CFI_REGISTER rflags,r11*/
14058 SWAPGS_UNSAFE_STACK
14059 movl %esp,%r8d
14060 CFI_REGISTER rsp,r8
14061 movq PER_CPU_VAR(kernel_stack),%rsp
14062+ SAVE_ARGS 8*6,0,0
14063+ pax_enter_kernel_user
14064+
14065+#ifdef CONFIG_PAX_RANDKSTACK
14066+ pax_erase_kstack
14067+#endif
14068+
14069 /*
14070 * No need to follow this irqs on/off section: the syscall
14071 * disabled irqs and here we enable it straight after entry:
14072 */
14073 ENABLE_INTERRUPTS(CLBR_NONE)
14074- SAVE_ARGS 8,0,0
14075 movl %eax,%eax /* zero extension */
14076 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14077 movq %rcx,RIP-ARGOFFSET(%rsp)
14078@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14079 /* no need to do an access_ok check here because r8 has been
14080 32bit zero extended */
14081 /* hardware stack frame is complete now */
14082+
14083+#ifdef CONFIG_PAX_MEMORY_UDEREF
14084+ ASM_PAX_OPEN_USERLAND
14085+ movq pax_user_shadow_base,%r8
14086+ addq RSP-ARGOFFSET(%rsp),%r8
14087+#endif
14088+
14089 ASM_STAC
14090 1: movl (%r8),%r9d
14091 _ASM_EXTABLE(1b,ia32_badarg)
14092 ASM_CLAC
14093- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14094- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14095+
14096+#ifdef CONFIG_PAX_MEMORY_UDEREF
14097+ ASM_PAX_CLOSE_USERLAND
14098+#endif
14099+
14100+ GET_THREAD_INFO(%r11)
14101+ orl $TS_COMPAT,TI_status(%r11)
14102+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14103 CFI_REMEMBER_STATE
14104 jnz cstar_tracesys
14105 cmpq $IA32_NR_syscalls-1,%rax
14106@@ -319,13 +395,16 @@ cstar_do_call:
14107 cstar_dispatch:
14108 call *ia32_sys_call_table(,%rax,8)
14109 movq %rax,RAX-ARGOFFSET(%rsp)
14110+ GET_THREAD_INFO(%r11)
14111 DISABLE_INTERRUPTS(CLBR_NONE)
14112 TRACE_IRQS_OFF
14113- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14114+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14115 jnz sysretl_audit
14116 sysretl_from_sys_call:
14117- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14118- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14119+ pax_exit_kernel_user
14120+ pax_erase_kstack
14121+ andl $~TS_COMPAT,TI_status(%r11)
14122+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14123 movl RIP-ARGOFFSET(%rsp),%ecx
14124 CFI_REGISTER rip,rcx
14125 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14126@@ -352,7 +431,7 @@ sysretl_audit:
14127
14128 cstar_tracesys:
14129 #ifdef CONFIG_AUDITSYSCALL
14130- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14131+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14132 jz cstar_auditsys
14133 #endif
14134 xchgl %r9d,%ebp
14135@@ -366,11 +445,19 @@ cstar_tracesys:
14136 xchgl %ebp,%r9d
14137 cmpq $(IA32_NR_syscalls-1),%rax
14138 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14139+
14140+ pax_erase_kstack
14141+
14142 jmp cstar_do_call
14143 END(ia32_cstar_target)
14144
14145 ia32_badarg:
14146 ASM_CLAC
14147+
14148+#ifdef CONFIG_PAX_MEMORY_UDEREF
14149+ ASM_PAX_CLOSE_USERLAND
14150+#endif
14151+
14152 movq $-EFAULT,%rax
14153 jmp ia32_sysret
14154 CFI_ENDPROC
14155@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14156 CFI_REL_OFFSET rip,RIP-RIP
14157 PARAVIRT_ADJUST_EXCEPTION_FRAME
14158 SWAPGS
14159- /*
14160- * No need to follow this irqs on/off section: the syscall
14161- * disabled irqs and here we enable it straight after entry:
14162- */
14163- ENABLE_INTERRUPTS(CLBR_NONE)
14164 movl %eax,%eax
14165 pushq_cfi %rax
14166 cld
14167 /* note the registers are not zero extended to the sf.
14168 this could be a problem. */
14169 SAVE_ARGS 0,1,0
14170- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14171- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14172+ pax_enter_kernel_user
14173+
14174+#ifdef CONFIG_PAX_RANDKSTACK
14175+ pax_erase_kstack
14176+#endif
14177+
14178+ /*
14179+ * No need to follow this irqs on/off section: the syscall
14180+ * disabled irqs and here we enable it straight after entry:
14181+ */
14182+ ENABLE_INTERRUPTS(CLBR_NONE)
14183+ GET_THREAD_INFO(%r11)
14184+ orl $TS_COMPAT,TI_status(%r11)
14185+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14186 jnz ia32_tracesys
14187 cmpq $(IA32_NR_syscalls-1),%rax
14188 ja ia32_badsys
14189@@ -442,6 +536,9 @@ ia32_tracesys:
14190 RESTORE_REST
14191 cmpq $(IA32_NR_syscalls-1),%rax
14192 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14193+
14194+ pax_erase_kstack
14195+
14196 jmp ia32_do_call
14197 END(ia32_syscall)
14198
14199diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14200index 8e0ceec..af13504 100644
14201--- a/arch/x86/ia32/sys_ia32.c
14202+++ b/arch/x86/ia32/sys_ia32.c
14203@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14204 */
14205 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14206 {
14207- typeof(ubuf->st_uid) uid = 0;
14208- typeof(ubuf->st_gid) gid = 0;
14209+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
14210+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
14211 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14212 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14213 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14214diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14215index 372231c..51b537d 100644
14216--- a/arch/x86/include/asm/alternative-asm.h
14217+++ b/arch/x86/include/asm/alternative-asm.h
14218@@ -18,6 +18,45 @@
14219 .endm
14220 #endif
14221
14222+#ifdef KERNEXEC_PLUGIN
14223+ .macro pax_force_retaddr_bts rip=0
14224+ btsq $63,\rip(%rsp)
14225+ .endm
14226+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14227+ .macro pax_force_retaddr rip=0, reload=0
14228+ btsq $63,\rip(%rsp)
14229+ .endm
14230+ .macro pax_force_fptr ptr
14231+ btsq $63,\ptr
14232+ .endm
14233+ .macro pax_set_fptr_mask
14234+ .endm
14235+#endif
14236+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14237+ .macro pax_force_retaddr rip=0, reload=0
14238+ .if \reload
14239+ pax_set_fptr_mask
14240+ .endif
14241+ orq %r12,\rip(%rsp)
14242+ .endm
14243+ .macro pax_force_fptr ptr
14244+ orq %r12,\ptr
14245+ .endm
14246+ .macro pax_set_fptr_mask
14247+ movabs $0x8000000000000000,%r12
14248+ .endm
14249+#endif
14250+#else
14251+ .macro pax_force_retaddr rip=0, reload=0
14252+ .endm
14253+ .macro pax_force_fptr ptr
14254+ .endm
14255+ .macro pax_force_retaddr_bts rip=0
14256+ .endm
14257+ .macro pax_set_fptr_mask
14258+ .endm
14259+#endif
14260+
14261 .macro altinstruction_entry orig alt feature orig_len alt_len
14262 .long \orig - .
14263 .long \alt - .
14264diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14265index 0a3f9c9..c9d081d 100644
14266--- a/arch/x86/include/asm/alternative.h
14267+++ b/arch/x86/include/asm/alternative.h
14268@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14269 ".pushsection .discard,\"aw\",@progbits\n" \
14270 DISCARD_ENTRY(1) \
14271 ".popsection\n" \
14272- ".pushsection .altinstr_replacement, \"ax\"\n" \
14273+ ".pushsection .altinstr_replacement, \"a\"\n" \
14274 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14275 ".popsection"
14276
14277@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14278 DISCARD_ENTRY(1) \
14279 DISCARD_ENTRY(2) \
14280 ".popsection\n" \
14281- ".pushsection .altinstr_replacement, \"ax\"\n" \
14282+ ".pushsection .altinstr_replacement, \"a\"\n" \
14283 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14284 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14285 ".popsection"
14286diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14287index 1d2091a..f5074c1 100644
14288--- a/arch/x86/include/asm/apic.h
14289+++ b/arch/x86/include/asm/apic.h
14290@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14291
14292 #ifdef CONFIG_X86_LOCAL_APIC
14293
14294-extern unsigned int apic_verbosity;
14295+extern int apic_verbosity;
14296 extern int local_apic_timer_c2_ok;
14297
14298 extern int disable_apic;
14299diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14300index 20370c6..a2eb9b0 100644
14301--- a/arch/x86/include/asm/apm.h
14302+++ b/arch/x86/include/asm/apm.h
14303@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14304 __asm__ __volatile__(APM_DO_ZERO_SEGS
14305 "pushl %%edi\n\t"
14306 "pushl %%ebp\n\t"
14307- "lcall *%%cs:apm_bios_entry\n\t"
14308+ "lcall *%%ss:apm_bios_entry\n\t"
14309 "setc %%al\n\t"
14310 "popl %%ebp\n\t"
14311 "popl %%edi\n\t"
14312@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14313 __asm__ __volatile__(APM_DO_ZERO_SEGS
14314 "pushl %%edi\n\t"
14315 "pushl %%ebp\n\t"
14316- "lcall *%%cs:apm_bios_entry\n\t"
14317+ "lcall *%%ss:apm_bios_entry\n\t"
14318 "setc %%bl\n\t"
14319 "popl %%ebp\n\t"
14320 "popl %%edi\n\t"
14321diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14322index b17f4f4..9620151 100644
14323--- a/arch/x86/include/asm/atomic.h
14324+++ b/arch/x86/include/asm/atomic.h
14325@@ -23,7 +23,18 @@
14326 */
14327 static inline int atomic_read(const atomic_t *v)
14328 {
14329- return (*(volatile int *)&(v)->counter);
14330+ return (*(volatile const int *)&(v)->counter);
14331+}
14332+
14333+/**
14334+ * atomic_read_unchecked - read atomic variable
14335+ * @v: pointer of type atomic_unchecked_t
14336+ *
14337+ * Atomically reads the value of @v.
14338+ */
14339+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14340+{
14341+ return (*(volatile const int *)&(v)->counter);
14342 }
14343
14344 /**
14345@@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14346 }
14347
14348 /**
14349+ * atomic_set_unchecked - set atomic variable
14350+ * @v: pointer of type atomic_unchecked_t
14351+ * @i: required value
14352+ *
14353+ * Atomically sets the value of @v to @i.
14354+ */
14355+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14356+{
14357+ v->counter = i;
14358+}
14359+
14360+/**
14361 * atomic_add - add integer to atomic variable
14362 * @i: integer value to add
14363 * @v: pointer of type atomic_t
14364@@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14365 */
14366 static inline void atomic_add(int i, atomic_t *v)
14367 {
14368- asm volatile(LOCK_PREFIX "addl %1,%0"
14369+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14370+
14371+#ifdef CONFIG_PAX_REFCOUNT
14372+ "jno 0f\n"
14373+ LOCK_PREFIX "subl %1,%0\n"
14374+ "int $4\n0:\n"
14375+ _ASM_EXTABLE(0b, 0b)
14376+#endif
14377+
14378+ : "+m" (v->counter)
14379+ : "ir" (i));
14380+}
14381+
14382+/**
14383+ * atomic_add_unchecked - add integer to atomic variable
14384+ * @i: integer value to add
14385+ * @v: pointer of type atomic_unchecked_t
14386+ *
14387+ * Atomically adds @i to @v.
14388+ */
14389+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14390+{
14391+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14392 : "+m" (v->counter)
14393 : "ir" (i));
14394 }
14395@@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14396 */
14397 static inline void atomic_sub(int i, atomic_t *v)
14398 {
14399- asm volatile(LOCK_PREFIX "subl %1,%0"
14400+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14401+
14402+#ifdef CONFIG_PAX_REFCOUNT
14403+ "jno 0f\n"
14404+ LOCK_PREFIX "addl %1,%0\n"
14405+ "int $4\n0:\n"
14406+ _ASM_EXTABLE(0b, 0b)
14407+#endif
14408+
14409+ : "+m" (v->counter)
14410+ : "ir" (i));
14411+}
14412+
14413+/**
14414+ * atomic_sub_unchecked - subtract integer from atomic variable
14415+ * @i: integer value to subtract
14416+ * @v: pointer of type atomic_unchecked_t
14417+ *
14418+ * Atomically subtracts @i from @v.
14419+ */
14420+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14421+{
14422+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14423 : "+m" (v->counter)
14424 : "ir" (i));
14425 }
14426@@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
14427 */
14428 static inline int atomic_sub_and_test(int i, atomic_t *v)
14429 {
14430- GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
14431+ GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
14432 }
14433
14434 /**
14435@@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14436 */
14437 static inline void atomic_inc(atomic_t *v)
14438 {
14439- asm volatile(LOCK_PREFIX "incl %0"
14440+ asm volatile(LOCK_PREFIX "incl %0\n"
14441+
14442+#ifdef CONFIG_PAX_REFCOUNT
14443+ "jno 0f\n"
14444+ LOCK_PREFIX "decl %0\n"
14445+ "int $4\n0:\n"
14446+ _ASM_EXTABLE(0b, 0b)
14447+#endif
14448+
14449+ : "+m" (v->counter));
14450+}
14451+
14452+/**
14453+ * atomic_inc_unchecked - increment atomic variable
14454+ * @v: pointer of type atomic_unchecked_t
14455+ *
14456+ * Atomically increments @v by 1.
14457+ */
14458+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
14459+{
14460+ asm volatile(LOCK_PREFIX "incl %0\n"
14461 : "+m" (v->counter));
14462 }
14463
14464@@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
14465 */
14466 static inline void atomic_dec(atomic_t *v)
14467 {
14468- asm volatile(LOCK_PREFIX "decl %0"
14469+ asm volatile(LOCK_PREFIX "decl %0\n"
14470+
14471+#ifdef CONFIG_PAX_REFCOUNT
14472+ "jno 0f\n"
14473+ LOCK_PREFIX "incl %0\n"
14474+ "int $4\n0:\n"
14475+ _ASM_EXTABLE(0b, 0b)
14476+#endif
14477+
14478+ : "+m" (v->counter));
14479+}
14480+
14481+/**
14482+ * atomic_dec_unchecked - decrement atomic variable
14483+ * @v: pointer of type atomic_unchecked_t
14484+ *
14485+ * Atomically decrements @v by 1.
14486+ */
14487+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
14488+{
14489+ asm volatile(LOCK_PREFIX "decl %0\n"
14490 : "+m" (v->counter));
14491 }
14492
14493@@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
14494 */
14495 static inline int atomic_dec_and_test(atomic_t *v)
14496 {
14497- GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
14498+ GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
14499 }
14500
14501 /**
14502@@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
14503 */
14504 static inline int atomic_inc_and_test(atomic_t *v)
14505 {
14506- GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
14507+ GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
14508+}
14509+
14510+/**
14511+ * atomic_inc_and_test_unchecked - increment and test
14512+ * @v: pointer of type atomic_unchecked_t
14513+ *
14514+ * Atomically increments @v by 1
14515+ * and returns true if the result is zero, or false for all
14516+ * other cases.
14517+ */
14518+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
14519+{
14520+ GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
14521 }
14522
14523 /**
14524@@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
14525 */
14526 static inline int atomic_add_negative(int i, atomic_t *v)
14527 {
14528- GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
14529+ GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
14530 }
14531
14532 /**
14533@@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14534 */
14535 static inline int atomic_add_return(int i, atomic_t *v)
14536 {
14537+ return i + xadd_check_overflow(&v->counter, i);
14538+}
14539+
14540+/**
14541+ * atomic_add_return_unchecked - add integer and return
14542+ * @i: integer value to add
14543+ * @v: pointer of type atomic_unchecked_t
14544+ *
14545+ * Atomically adds @i to @v and returns @i + @v
14546+ */
14547+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
14548+{
14549 return i + xadd(&v->counter, i);
14550 }
14551
14552@@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
14553 }
14554
14555 #define atomic_inc_return(v) (atomic_add_return(1, v))
14556+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
14557+{
14558+ return atomic_add_return_unchecked(1, v);
14559+}
14560 #define atomic_dec_return(v) (atomic_sub_return(1, v))
14561
14562-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14563+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
14564+{
14565+ return cmpxchg(&v->counter, old, new);
14566+}
14567+
14568+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
14569 {
14570 return cmpxchg(&v->counter, old, new);
14571 }
14572@@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
14573 return xchg(&v->counter, new);
14574 }
14575
14576+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
14577+{
14578+ return xchg(&v->counter, new);
14579+}
14580+
14581 /**
14582 * __atomic_add_unless - add unless the number is already a given value
14583 * @v: pointer of type atomic_t
14584@@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
14585 * Atomically adds @a to @v, so long as @v was not already @u.
14586 * Returns the old value of @v.
14587 */
14588-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14589+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
14590 {
14591- int c, old;
14592+ int c, old, new;
14593 c = atomic_read(v);
14594 for (;;) {
14595- if (unlikely(c == (u)))
14596+ if (unlikely(c == u))
14597 break;
14598- old = atomic_cmpxchg((v), c, c + (a));
14599+
14600+ asm volatile("addl %2,%0\n"
14601+
14602+#ifdef CONFIG_PAX_REFCOUNT
14603+ "jno 0f\n"
14604+ "subl %2,%0\n"
14605+ "int $4\n0:\n"
14606+ _ASM_EXTABLE(0b, 0b)
14607+#endif
14608+
14609+ : "=r" (new)
14610+ : "0" (c), "ir" (a));
14611+
14612+ old = atomic_cmpxchg(v, c, new);
14613 if (likely(old == c))
14614 break;
14615 c = old;
14616@@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14617 }
14618
14619 /**
14620+ * atomic_inc_not_zero_hint - increment if not null
14621+ * @v: pointer of type atomic_t
14622+ * @hint: probable value of the atomic before the increment
14623+ *
14624+ * This version of atomic_inc_not_zero() gives a hint of probable
14625+ * value of the atomic. This helps processor to not read the memory
14626+ * before doing the atomic read/modify/write cycle, lowering
14627+ * number of bus transactions on some arches.
14628+ *
14629+ * Returns: 0 if increment was not done, 1 otherwise.
14630+ */
14631+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
14632+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
14633+{
14634+ int val, c = hint, new;
14635+
14636+ /* sanity test, should be removed by compiler if hint is a constant */
14637+ if (!hint)
14638+ return __atomic_add_unless(v, 1, 0);
14639+
14640+ do {
14641+ asm volatile("incl %0\n"
14642+
14643+#ifdef CONFIG_PAX_REFCOUNT
14644+ "jno 0f\n"
14645+ "decl %0\n"
14646+ "int $4\n0:\n"
14647+ _ASM_EXTABLE(0b, 0b)
14648+#endif
14649+
14650+ : "=r" (new)
14651+ : "0" (c));
14652+
14653+ val = atomic_cmpxchg(v, c, new);
14654+ if (val == c)
14655+ return 1;
14656+ c = val;
14657+ } while (c);
14658+
14659+ return 0;
14660+}
14661+
14662+/**
14663 * atomic_inc_short - increment of a short integer
14664 * @v: pointer to type int
14665 *
14666@@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
14667 #endif
14668
14669 /* These are x86-specific, used by some header files */
14670-#define atomic_clear_mask(mask, addr) \
14671- asm volatile(LOCK_PREFIX "andl %0,%1" \
14672- : : "r" (~(mask)), "m" (*(addr)) : "memory")
14673+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
14674+{
14675+ asm volatile(LOCK_PREFIX "andl %1,%0"
14676+ : "+m" (v->counter)
14677+ : "r" (~(mask))
14678+ : "memory");
14679+}
14680
14681-#define atomic_set_mask(mask, addr) \
14682- asm volatile(LOCK_PREFIX "orl %0,%1" \
14683- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
14684- : "memory")
14685+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14686+{
14687+ asm volatile(LOCK_PREFIX "andl %1,%0"
14688+ : "+m" (v->counter)
14689+ : "r" (~(mask))
14690+ : "memory");
14691+}
14692+
14693+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
14694+{
14695+ asm volatile(LOCK_PREFIX "orl %1,%0"
14696+ : "+m" (v->counter)
14697+ : "r" (mask)
14698+ : "memory");
14699+}
14700+
14701+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14702+{
14703+ asm volatile(LOCK_PREFIX "orl %1,%0"
14704+ : "+m" (v->counter)
14705+ : "r" (mask)
14706+ : "memory");
14707+}
14708
14709 /* Atomic operations are already serializing on x86 */
14710 #define smp_mb__before_atomic_dec() barrier()
14711diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
14712index b154de7..bf18a5a 100644
14713--- a/arch/x86/include/asm/atomic64_32.h
14714+++ b/arch/x86/include/asm/atomic64_32.h
14715@@ -12,6 +12,14 @@ typedef struct {
14716 u64 __aligned(8) counter;
14717 } atomic64_t;
14718
14719+#ifdef CONFIG_PAX_REFCOUNT
14720+typedef struct {
14721+ u64 __aligned(8) counter;
14722+} atomic64_unchecked_t;
14723+#else
14724+typedef atomic64_t atomic64_unchecked_t;
14725+#endif
14726+
14727 #define ATOMIC64_INIT(val) { (val) }
14728
14729 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
14730@@ -37,21 +45,31 @@ typedef struct {
14731 ATOMIC64_DECL_ONE(sym##_386)
14732
14733 ATOMIC64_DECL_ONE(add_386);
14734+ATOMIC64_DECL_ONE(add_unchecked_386);
14735 ATOMIC64_DECL_ONE(sub_386);
14736+ATOMIC64_DECL_ONE(sub_unchecked_386);
14737 ATOMIC64_DECL_ONE(inc_386);
14738+ATOMIC64_DECL_ONE(inc_unchecked_386);
14739 ATOMIC64_DECL_ONE(dec_386);
14740+ATOMIC64_DECL_ONE(dec_unchecked_386);
14741 #endif
14742
14743 #define alternative_atomic64(f, out, in...) \
14744 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
14745
14746 ATOMIC64_DECL(read);
14747+ATOMIC64_DECL(read_unchecked);
14748 ATOMIC64_DECL(set);
14749+ATOMIC64_DECL(set_unchecked);
14750 ATOMIC64_DECL(xchg);
14751 ATOMIC64_DECL(add_return);
14752+ATOMIC64_DECL(add_return_unchecked);
14753 ATOMIC64_DECL(sub_return);
14754+ATOMIC64_DECL(sub_return_unchecked);
14755 ATOMIC64_DECL(inc_return);
14756+ATOMIC64_DECL(inc_return_unchecked);
14757 ATOMIC64_DECL(dec_return);
14758+ATOMIC64_DECL(dec_return_unchecked);
14759 ATOMIC64_DECL(dec_if_positive);
14760 ATOMIC64_DECL(inc_not_zero);
14761 ATOMIC64_DECL(add_unless);
14762@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
14763 }
14764
14765 /**
14766+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
14767+ * @p: pointer to type atomic64_unchecked_t
14768+ * @o: expected value
14769+ * @n: new value
14770+ *
14771+ * Atomically sets @v to @n if it was equal to @o and returns
14772+ * the old value.
14773+ */
14774+
14775+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
14776+{
14777+ return cmpxchg64(&v->counter, o, n);
14778+}
14779+
14780+/**
14781 * atomic64_xchg - xchg atomic64 variable
14782 * @v: pointer to type atomic64_t
14783 * @n: value to assign
14784@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
14785 }
14786
14787 /**
14788+ * atomic64_set_unchecked - set atomic64 variable
14789+ * @v: pointer to type atomic64_unchecked_t
14790+ * @n: value to assign
14791+ *
14792+ * Atomically sets the value of @v to @n.
14793+ */
14794+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
14795+{
14796+ unsigned high = (unsigned)(i >> 32);
14797+ unsigned low = (unsigned)i;
14798+ alternative_atomic64(set, /* no output */,
14799+ "S" (v), "b" (low), "c" (high)
14800+ : "eax", "edx", "memory");
14801+}
14802+
14803+/**
14804 * atomic64_read - read atomic64 variable
14805 * @v: pointer to type atomic64_t
14806 *
14807@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
14808 }
14809
14810 /**
14811+ * atomic64_read_unchecked - read atomic64 variable
14812+ * @v: pointer to type atomic64_unchecked_t
14813+ *
14814+ * Atomically reads the value of @v and returns it.
14815+ */
14816+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
14817+{
14818+ long long r;
14819+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
14820+ return r;
14821+ }
14822+
14823+/**
14824 * atomic64_add_return - add and return
14825 * @i: integer value to add
14826 * @v: pointer to type atomic64_t
14827@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
14828 return i;
14829 }
14830
14831+/**
14832+ * atomic64_add_return_unchecked - add and return
14833+ * @i: integer value to add
14834+ * @v: pointer to type atomic64_unchecked_t
14835+ *
14836+ * Atomically adds @i to @v and returns @i + *@v
14837+ */
14838+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
14839+{
14840+ alternative_atomic64(add_return_unchecked,
14841+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14842+ ASM_NO_INPUT_CLOBBER("memory"));
14843+ return i;
14844+}
14845+
14846 /*
14847 * Other variants with different arithmetic operators:
14848 */
14849@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
14850 return a;
14851 }
14852
14853+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14854+{
14855+ long long a;
14856+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
14857+ "S" (v) : "memory", "ecx");
14858+ return a;
14859+}
14860+
14861 static inline long long atomic64_dec_return(atomic64_t *v)
14862 {
14863 long long a;
14864@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
14865 }
14866
14867 /**
14868+ * atomic64_add_unchecked - add integer to atomic64 variable
14869+ * @i: integer value to add
14870+ * @v: pointer to type atomic64_unchecked_t
14871+ *
14872+ * Atomically adds @i to @v.
14873+ */
14874+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
14875+{
14876+ __alternative_atomic64(add_unchecked, add_return_unchecked,
14877+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14878+ ASM_NO_INPUT_CLOBBER("memory"));
14879+ return i;
14880+}
14881+
14882+/**
14883 * atomic64_sub - subtract the atomic64 variable
14884 * @i: integer value to subtract
14885 * @v: pointer to type atomic64_t
14886diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
14887index 46e9052..ae45136 100644
14888--- a/arch/x86/include/asm/atomic64_64.h
14889+++ b/arch/x86/include/asm/atomic64_64.h
14890@@ -18,7 +18,19 @@
14891 */
14892 static inline long atomic64_read(const atomic64_t *v)
14893 {
14894- return (*(volatile long *)&(v)->counter);
14895+ return (*(volatile const long *)&(v)->counter);
14896+}
14897+
14898+/**
14899+ * atomic64_read_unchecked - read atomic64 variable
14900+ * @v: pointer of type atomic64_unchecked_t
14901+ *
14902+ * Atomically reads the value of @v.
14903+ * Doesn't imply a read memory barrier.
14904+ */
14905+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
14906+{
14907+ return (*(volatile const long *)&(v)->counter);
14908 }
14909
14910 /**
14911@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
14912 }
14913
14914 /**
14915+ * atomic64_set_unchecked - set atomic64 variable
14916+ * @v: pointer to type atomic64_unchecked_t
14917+ * @i: required value
14918+ *
14919+ * Atomically sets the value of @v to @i.
14920+ */
14921+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
14922+{
14923+ v->counter = i;
14924+}
14925+
14926+/**
14927 * atomic64_add - add integer to atomic64 variable
14928 * @i: integer value to add
14929 * @v: pointer to type atomic64_t
14930@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
14931 */
14932 static inline void atomic64_add(long i, atomic64_t *v)
14933 {
14934+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
14935+
14936+#ifdef CONFIG_PAX_REFCOUNT
14937+ "jno 0f\n"
14938+ LOCK_PREFIX "subq %1,%0\n"
14939+ "int $4\n0:\n"
14940+ _ASM_EXTABLE(0b, 0b)
14941+#endif
14942+
14943+ : "=m" (v->counter)
14944+ : "er" (i), "m" (v->counter));
14945+}
14946+
14947+/**
14948+ * atomic64_add_unchecked - add integer to atomic64 variable
14949+ * @i: integer value to add
14950+ * @v: pointer to type atomic64_unchecked_t
14951+ *
14952+ * Atomically adds @i to @v.
14953+ */
14954+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
14955+{
14956 asm volatile(LOCK_PREFIX "addq %1,%0"
14957 : "=m" (v->counter)
14958 : "er" (i), "m" (v->counter));
14959@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
14960 */
14961 static inline void atomic64_sub(long i, atomic64_t *v)
14962 {
14963- asm volatile(LOCK_PREFIX "subq %1,%0"
14964+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14965+
14966+#ifdef CONFIG_PAX_REFCOUNT
14967+ "jno 0f\n"
14968+ LOCK_PREFIX "addq %1,%0\n"
14969+ "int $4\n0:\n"
14970+ _ASM_EXTABLE(0b, 0b)
14971+#endif
14972+
14973+ : "=m" (v->counter)
14974+ : "er" (i), "m" (v->counter));
14975+}
14976+
14977+/**
14978+ * atomic64_sub_unchecked - subtract the atomic64 variable
14979+ * @i: integer value to subtract
14980+ * @v: pointer to type atomic64_unchecked_t
14981+ *
14982+ * Atomically subtracts @i from @v.
14983+ */
14984+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
14985+{
14986+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14987 : "=m" (v->counter)
14988 : "er" (i), "m" (v->counter));
14989 }
14990@@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
14991 */
14992 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14993 {
14994- GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
14995+ GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
14996 }
14997
14998 /**
14999@@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15000 */
15001 static inline void atomic64_inc(atomic64_t *v)
15002 {
15003+ asm volatile(LOCK_PREFIX "incq %0\n"
15004+
15005+#ifdef CONFIG_PAX_REFCOUNT
15006+ "jno 0f\n"
15007+ LOCK_PREFIX "decq %0\n"
15008+ "int $4\n0:\n"
15009+ _ASM_EXTABLE(0b, 0b)
15010+#endif
15011+
15012+ : "=m" (v->counter)
15013+ : "m" (v->counter));
15014+}
15015+
15016+/**
15017+ * atomic64_inc_unchecked - increment atomic64 variable
15018+ * @v: pointer to type atomic64_unchecked_t
15019+ *
15020+ * Atomically increments @v by 1.
15021+ */
15022+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15023+{
15024 asm volatile(LOCK_PREFIX "incq %0"
15025 : "=m" (v->counter)
15026 : "m" (v->counter));
15027@@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15028 */
15029 static inline void atomic64_dec(atomic64_t *v)
15030 {
15031- asm volatile(LOCK_PREFIX "decq %0"
15032+ asm volatile(LOCK_PREFIX "decq %0\n"
15033+
15034+#ifdef CONFIG_PAX_REFCOUNT
15035+ "jno 0f\n"
15036+ LOCK_PREFIX "incq %0\n"
15037+ "int $4\n0:\n"
15038+ _ASM_EXTABLE(0b, 0b)
15039+#endif
15040+
15041+ : "=m" (v->counter)
15042+ : "m" (v->counter));
15043+}
15044+
15045+/**
15046+ * atomic64_dec_unchecked - decrement atomic64 variable
15047+ * @v: pointer to type atomic64_t
15048+ *
15049+ * Atomically decrements @v by 1.
15050+ */
15051+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15052+{
15053+ asm volatile(LOCK_PREFIX "decq %0\n"
15054 : "=m" (v->counter)
15055 : "m" (v->counter));
15056 }
15057@@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15058 */
15059 static inline int atomic64_dec_and_test(atomic64_t *v)
15060 {
15061- GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15062+ GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15063 }
15064
15065 /**
15066@@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15067 */
15068 static inline int atomic64_inc_and_test(atomic64_t *v)
15069 {
15070- GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15071+ GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15072 }
15073
15074 /**
15075@@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15076 */
15077 static inline int atomic64_add_negative(long i, atomic64_t *v)
15078 {
15079- GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15080+ GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15081 }
15082
15083 /**
15084@@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15085 */
15086 static inline long atomic64_add_return(long i, atomic64_t *v)
15087 {
15088+ return i + xadd_check_overflow(&v->counter, i);
15089+}
15090+
15091+/**
15092+ * atomic64_add_return_unchecked - add and return
15093+ * @i: integer value to add
15094+ * @v: pointer to type atomic64_unchecked_t
15095+ *
15096+ * Atomically adds @i to @v and returns @i + @v
15097+ */
15098+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15099+{
15100 return i + xadd(&v->counter, i);
15101 }
15102
15103@@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15104 }
15105
15106 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15107+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15108+{
15109+ return atomic64_add_return_unchecked(1, v);
15110+}
15111 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15112
15113 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15114@@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15115 return cmpxchg(&v->counter, old, new);
15116 }
15117
15118+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15119+{
15120+ return cmpxchg(&v->counter, old, new);
15121+}
15122+
15123 static inline long atomic64_xchg(atomic64_t *v, long new)
15124 {
15125 return xchg(&v->counter, new);
15126@@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15127 */
15128 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15129 {
15130- long c, old;
15131+ long c, old, new;
15132 c = atomic64_read(v);
15133 for (;;) {
15134- if (unlikely(c == (u)))
15135+ if (unlikely(c == u))
15136 break;
15137- old = atomic64_cmpxchg((v), c, c + (a));
15138+
15139+ asm volatile("add %2,%0\n"
15140+
15141+#ifdef CONFIG_PAX_REFCOUNT
15142+ "jno 0f\n"
15143+ "sub %2,%0\n"
15144+ "int $4\n0:\n"
15145+ _ASM_EXTABLE(0b, 0b)
15146+#endif
15147+
15148+ : "=r" (new)
15149+ : "0" (c), "ir" (a));
15150+
15151+ old = atomic64_cmpxchg(v, c, new);
15152 if (likely(old == c))
15153 break;
15154 c = old;
15155 }
15156- return c != (u);
15157+ return c != u;
15158 }
15159
15160 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15161diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15162index 9fc1af7..fc71228 100644
15163--- a/arch/x86/include/asm/bitops.h
15164+++ b/arch/x86/include/asm/bitops.h
15165@@ -49,7 +49,7 @@
15166 * a mask operation on a byte.
15167 */
15168 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15169-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15170+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15171 #define CONST_MASK(nr) (1 << ((nr) & 7))
15172
15173 /**
15174@@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15175 */
15176 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15177 {
15178- GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15179+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15180 }
15181
15182 /**
15183@@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15184 */
15185 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15186 {
15187- GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15188+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15189 }
15190
15191 /**
15192@@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15193 */
15194 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15195 {
15196- GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15197+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15198 }
15199
15200 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15201@@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15202 *
15203 * Undefined if no bit exists, so code should check against 0 first.
15204 */
15205-static inline unsigned long __ffs(unsigned long word)
15206+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15207 {
15208 asm("rep; bsf %1,%0"
15209 : "=r" (word)
15210@@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15211 *
15212 * Undefined if no zero exists, so code should check against ~0UL first.
15213 */
15214-static inline unsigned long ffz(unsigned long word)
15215+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15216 {
15217 asm("rep; bsf %1,%0"
15218 : "=r" (word)
15219@@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15220 *
15221 * Undefined if no set bit exists, so code should check against 0 first.
15222 */
15223-static inline unsigned long __fls(unsigned long word)
15224+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15225 {
15226 asm("bsr %1,%0"
15227 : "=r" (word)
15228@@ -436,7 +436,7 @@ static inline int ffs(int x)
15229 * set bit if value is nonzero. The last (most significant) bit is
15230 * at position 32.
15231 */
15232-static inline int fls(int x)
15233+static inline int __intentional_overflow(-1) fls(int x)
15234 {
15235 int r;
15236
15237@@ -478,7 +478,7 @@ static inline int fls(int x)
15238 * at position 64.
15239 */
15240 #ifdef CONFIG_X86_64
15241-static __always_inline int fls64(__u64 x)
15242+static __always_inline long fls64(__u64 x)
15243 {
15244 int bitpos = -1;
15245 /*
15246diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15247index 4fa687a..60f2d39 100644
15248--- a/arch/x86/include/asm/boot.h
15249+++ b/arch/x86/include/asm/boot.h
15250@@ -6,10 +6,15 @@
15251 #include <uapi/asm/boot.h>
15252
15253 /* Physical address where kernel should be loaded. */
15254-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15255+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15256 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15257 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15258
15259+#ifndef __ASSEMBLY__
15260+extern unsigned char __LOAD_PHYSICAL_ADDR[];
15261+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15262+#endif
15263+
15264 /* Minimum kernel alignment, as a power of two */
15265 #ifdef CONFIG_X86_64
15266 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15267diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15268index 48f99f1..d78ebf9 100644
15269--- a/arch/x86/include/asm/cache.h
15270+++ b/arch/x86/include/asm/cache.h
15271@@ -5,12 +5,13 @@
15272
15273 /* L1 cache line size */
15274 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15275-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15276+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15277
15278 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15279+#define __read_only __attribute__((__section__(".data..read_only")))
15280
15281 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15282-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15283+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15284
15285 #ifdef CONFIG_X86_VSMP
15286 #ifdef CONFIG_SMP
15287diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15288index 9863ee3..4a1f8e1 100644
15289--- a/arch/x86/include/asm/cacheflush.h
15290+++ b/arch/x86/include/asm/cacheflush.h
15291@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15292 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15293
15294 if (pg_flags == _PGMT_DEFAULT)
15295- return -1;
15296+ return ~0UL;
15297 else if (pg_flags == _PGMT_WC)
15298 return _PAGE_CACHE_WC;
15299 else if (pg_flags == _PGMT_UC_MINUS)
15300diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15301index cb4c73b..c473c29 100644
15302--- a/arch/x86/include/asm/calling.h
15303+++ b/arch/x86/include/asm/calling.h
15304@@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15305 #define RSP 152
15306 #define SS 160
15307
15308-#define ARGOFFSET R11
15309-#define SWFRAME ORIG_RAX
15310+#define ARGOFFSET R15
15311
15312 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15313- subq $9*8+\addskip, %rsp
15314- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15315- movq_cfi rdi, 8*8
15316- movq_cfi rsi, 7*8
15317- movq_cfi rdx, 6*8
15318+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15319+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15320+ movq_cfi rdi, RDI
15321+ movq_cfi rsi, RSI
15322+ movq_cfi rdx, RDX
15323
15324 .if \save_rcx
15325- movq_cfi rcx, 5*8
15326+ movq_cfi rcx, RCX
15327 .endif
15328
15329- movq_cfi rax, 4*8
15330+ movq_cfi rax, RAX
15331
15332 .if \save_r891011
15333- movq_cfi r8, 3*8
15334- movq_cfi r9, 2*8
15335- movq_cfi r10, 1*8
15336- movq_cfi r11, 0*8
15337+ movq_cfi r8, R8
15338+ movq_cfi r9, R9
15339+ movq_cfi r10, R10
15340+ movq_cfi r11, R11
15341 .endif
15342
15343+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15344+ movq_cfi r12, R12
15345+#endif
15346+
15347 .endm
15348
15349-#define ARG_SKIP (9*8)
15350+#define ARG_SKIP ORIG_RAX
15351
15352 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15353 rstor_r8910=1, rstor_rdx=1
15354+
15355+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15356+ movq_cfi_restore R12, r12
15357+#endif
15358+
15359 .if \rstor_r11
15360- movq_cfi_restore 0*8, r11
15361+ movq_cfi_restore R11, r11
15362 .endif
15363
15364 .if \rstor_r8910
15365- movq_cfi_restore 1*8, r10
15366- movq_cfi_restore 2*8, r9
15367- movq_cfi_restore 3*8, r8
15368+ movq_cfi_restore R10, r10
15369+ movq_cfi_restore R9, r9
15370+ movq_cfi_restore R8, r8
15371 .endif
15372
15373 .if \rstor_rax
15374- movq_cfi_restore 4*8, rax
15375+ movq_cfi_restore RAX, rax
15376 .endif
15377
15378 .if \rstor_rcx
15379- movq_cfi_restore 5*8, rcx
15380+ movq_cfi_restore RCX, rcx
15381 .endif
15382
15383 .if \rstor_rdx
15384- movq_cfi_restore 6*8, rdx
15385+ movq_cfi_restore RDX, rdx
15386 .endif
15387
15388- movq_cfi_restore 7*8, rsi
15389- movq_cfi_restore 8*8, rdi
15390+ movq_cfi_restore RSI, rsi
15391+ movq_cfi_restore RDI, rdi
15392
15393- .if ARG_SKIP+\addskip > 0
15394- addq $ARG_SKIP+\addskip, %rsp
15395- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15396+ .if ORIG_RAX+\addskip > 0
15397+ addq $ORIG_RAX+\addskip, %rsp
15398+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15399 .endif
15400 .endm
15401
15402- .macro LOAD_ARGS offset, skiprax=0
15403- movq \offset(%rsp), %r11
15404- movq \offset+8(%rsp), %r10
15405- movq \offset+16(%rsp), %r9
15406- movq \offset+24(%rsp), %r8
15407- movq \offset+40(%rsp), %rcx
15408- movq \offset+48(%rsp), %rdx
15409- movq \offset+56(%rsp), %rsi
15410- movq \offset+64(%rsp), %rdi
15411+ .macro LOAD_ARGS skiprax=0
15412+ movq R11(%rsp), %r11
15413+ movq R10(%rsp), %r10
15414+ movq R9(%rsp), %r9
15415+ movq R8(%rsp), %r8
15416+ movq RCX(%rsp), %rcx
15417+ movq RDX(%rsp), %rdx
15418+ movq RSI(%rsp), %rsi
15419+ movq RDI(%rsp), %rdi
15420 .if \skiprax
15421 .else
15422- movq \offset+72(%rsp), %rax
15423+ movq RAX(%rsp), %rax
15424 .endif
15425 .endm
15426
15427-#define REST_SKIP (6*8)
15428-
15429 .macro SAVE_REST
15430- subq $REST_SKIP, %rsp
15431- CFI_ADJUST_CFA_OFFSET REST_SKIP
15432- movq_cfi rbx, 5*8
15433- movq_cfi rbp, 4*8
15434- movq_cfi r12, 3*8
15435- movq_cfi r13, 2*8
15436- movq_cfi r14, 1*8
15437- movq_cfi r15, 0*8
15438+ movq_cfi rbx, RBX
15439+ movq_cfi rbp, RBP
15440+
15441+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15442+ movq_cfi r12, R12
15443+#endif
15444+
15445+ movq_cfi r13, R13
15446+ movq_cfi r14, R14
15447+ movq_cfi r15, R15
15448 .endm
15449
15450 .macro RESTORE_REST
15451- movq_cfi_restore 0*8, r15
15452- movq_cfi_restore 1*8, r14
15453- movq_cfi_restore 2*8, r13
15454- movq_cfi_restore 3*8, r12
15455- movq_cfi_restore 4*8, rbp
15456- movq_cfi_restore 5*8, rbx
15457- addq $REST_SKIP, %rsp
15458- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
15459+ movq_cfi_restore R15, r15
15460+ movq_cfi_restore R14, r14
15461+ movq_cfi_restore R13, r13
15462+
15463+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15464+ movq_cfi_restore R12, r12
15465+#endif
15466+
15467+ movq_cfi_restore RBP, rbp
15468+ movq_cfi_restore RBX, rbx
15469 .endm
15470
15471 .macro SAVE_ALL
15472diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
15473index f50de69..2b0a458 100644
15474--- a/arch/x86/include/asm/checksum_32.h
15475+++ b/arch/x86/include/asm/checksum_32.h
15476@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
15477 int len, __wsum sum,
15478 int *src_err_ptr, int *dst_err_ptr);
15479
15480+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
15481+ int len, __wsum sum,
15482+ int *src_err_ptr, int *dst_err_ptr);
15483+
15484+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
15485+ int len, __wsum sum,
15486+ int *src_err_ptr, int *dst_err_ptr);
15487+
15488 /*
15489 * Note: when you get a NULL pointer exception here this means someone
15490 * passed in an incorrect kernel address to one of these functions.
15491@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
15492
15493 might_sleep();
15494 stac();
15495- ret = csum_partial_copy_generic((__force void *)src, dst,
15496+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
15497 len, sum, err_ptr, NULL);
15498 clac();
15499
15500@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
15501 might_sleep();
15502 if (access_ok(VERIFY_WRITE, dst, len)) {
15503 stac();
15504- ret = csum_partial_copy_generic(src, (__force void *)dst,
15505+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
15506 len, sum, NULL, err_ptr);
15507 clac();
15508 return ret;
15509diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
15510index d47786a..ce1b05d 100644
15511--- a/arch/x86/include/asm/cmpxchg.h
15512+++ b/arch/x86/include/asm/cmpxchg.h
15513@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
15514 __compiletime_error("Bad argument size for cmpxchg");
15515 extern void __xadd_wrong_size(void)
15516 __compiletime_error("Bad argument size for xadd");
15517+extern void __xadd_check_overflow_wrong_size(void)
15518+ __compiletime_error("Bad argument size for xadd_check_overflow");
15519 extern void __add_wrong_size(void)
15520 __compiletime_error("Bad argument size for add");
15521+extern void __add_check_overflow_wrong_size(void)
15522+ __compiletime_error("Bad argument size for add_check_overflow");
15523
15524 /*
15525 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
15526@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
15527 __ret; \
15528 })
15529
15530+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
15531+ ({ \
15532+ __typeof__ (*(ptr)) __ret = (arg); \
15533+ switch (sizeof(*(ptr))) { \
15534+ case __X86_CASE_L: \
15535+ asm volatile (lock #op "l %0, %1\n" \
15536+ "jno 0f\n" \
15537+ "mov %0,%1\n" \
15538+ "int $4\n0:\n" \
15539+ _ASM_EXTABLE(0b, 0b) \
15540+ : "+r" (__ret), "+m" (*(ptr)) \
15541+ : : "memory", "cc"); \
15542+ break; \
15543+ case __X86_CASE_Q: \
15544+ asm volatile (lock #op "q %q0, %1\n" \
15545+ "jno 0f\n" \
15546+ "mov %0,%1\n" \
15547+ "int $4\n0:\n" \
15548+ _ASM_EXTABLE(0b, 0b) \
15549+ : "+r" (__ret), "+m" (*(ptr)) \
15550+ : : "memory", "cc"); \
15551+ break; \
15552+ default: \
15553+ __ ## op ## _check_overflow_wrong_size(); \
15554+ } \
15555+ __ret; \
15556+ })
15557+
15558 /*
15559 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
15560 * Since this is generally used to protect other memory information, we
15561@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
15562 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
15563 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
15564
15565+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
15566+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
15567+
15568 #define __add(ptr, inc, lock) \
15569 ({ \
15570 __typeof__ (*(ptr)) __ret = (inc); \
15571diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
15572index 59c6c40..5e0b22c 100644
15573--- a/arch/x86/include/asm/compat.h
15574+++ b/arch/x86/include/asm/compat.h
15575@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
15576 typedef u32 compat_uint_t;
15577 typedef u32 compat_ulong_t;
15578 typedef u64 __attribute__((aligned(4))) compat_u64;
15579-typedef u32 compat_uptr_t;
15580+typedef u32 __user compat_uptr_t;
15581
15582 struct compat_timespec {
15583 compat_time_t tv_sec;
15584diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
15585index 89270b4..f0abf8e 100644
15586--- a/arch/x86/include/asm/cpufeature.h
15587+++ b/arch/x86/include/asm/cpufeature.h
15588@@ -203,7 +203,7 @@
15589 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
15590 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
15591 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
15592-
15593+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
15594
15595 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
15596 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
15597@@ -211,7 +211,7 @@
15598 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
15599 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
15600 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
15601-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
15602+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
15603 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
15604 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
15605 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
15606@@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
15607 #undef cpu_has_centaur_mcr
15608 #define cpu_has_centaur_mcr 0
15609
15610+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
15611 #endif /* CONFIG_X86_64 */
15612
15613 #if __GNUC__ >= 4
15614@@ -405,7 +406,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
15615
15616 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
15617 t_warn:
15618- warn_pre_alternatives();
15619+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
15620+ warn_pre_alternatives();
15621 return false;
15622 #endif
15623
15624@@ -425,7 +427,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
15625 ".section .discard,\"aw\",@progbits\n"
15626 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
15627 ".previous\n"
15628- ".section .altinstr_replacement,\"ax\"\n"
15629+ ".section .altinstr_replacement,\"a\"\n"
15630 "3: movb $1,%0\n"
15631 "4:\n"
15632 ".previous\n"
15633@@ -462,7 +464,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15634 " .byte 2b - 1b\n" /* src len */
15635 " .byte 4f - 3f\n" /* repl len */
15636 ".previous\n"
15637- ".section .altinstr_replacement,\"ax\"\n"
15638+ ".section .altinstr_replacement,\"a\"\n"
15639 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
15640 "4:\n"
15641 ".previous\n"
15642@@ -495,7 +497,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15643 ".section .discard,\"aw\",@progbits\n"
15644 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
15645 ".previous\n"
15646- ".section .altinstr_replacement,\"ax\"\n"
15647+ ".section .altinstr_replacement,\"a\"\n"
15648 "3: movb $0,%0\n"
15649 "4:\n"
15650 ".previous\n"
15651@@ -509,7 +511,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15652 ".section .discard,\"aw\",@progbits\n"
15653 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
15654 ".previous\n"
15655- ".section .altinstr_replacement,\"ax\"\n"
15656+ ".section .altinstr_replacement,\"a\"\n"
15657 "5: movb $1,%0\n"
15658 "6:\n"
15659 ".previous\n"
15660diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
15661index 50d033a..37deb26 100644
15662--- a/arch/x86/include/asm/desc.h
15663+++ b/arch/x86/include/asm/desc.h
15664@@ -4,6 +4,7 @@
15665 #include <asm/desc_defs.h>
15666 #include <asm/ldt.h>
15667 #include <asm/mmu.h>
15668+#include <asm/pgtable.h>
15669
15670 #include <linux/smp.h>
15671 #include <linux/percpu.h>
15672@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
15673
15674 desc->type = (info->read_exec_only ^ 1) << 1;
15675 desc->type |= info->contents << 2;
15676+ desc->type |= info->seg_not_present ^ 1;
15677
15678 desc->s = 1;
15679 desc->dpl = 0x3;
15680@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
15681 }
15682
15683 extern struct desc_ptr idt_descr;
15684-extern gate_desc idt_table[];
15685-extern struct desc_ptr debug_idt_descr;
15686-extern gate_desc debug_idt_table[];
15687-
15688-struct gdt_page {
15689- struct desc_struct gdt[GDT_ENTRIES];
15690-} __attribute__((aligned(PAGE_SIZE)));
15691-
15692-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
15693+extern gate_desc idt_table[IDT_ENTRIES];
15694+extern const struct desc_ptr debug_idt_descr;
15695+extern gate_desc debug_idt_table[IDT_ENTRIES];
15696
15697+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
15698 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
15699 {
15700- return per_cpu(gdt_page, cpu).gdt;
15701+ return cpu_gdt_table[cpu];
15702 }
15703
15704 #ifdef CONFIG_X86_64
15705@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
15706 unsigned long base, unsigned dpl, unsigned flags,
15707 unsigned short seg)
15708 {
15709- gate->a = (seg << 16) | (base & 0xffff);
15710- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
15711+ gate->gate.offset_low = base;
15712+ gate->gate.seg = seg;
15713+ gate->gate.reserved = 0;
15714+ gate->gate.type = type;
15715+ gate->gate.s = 0;
15716+ gate->gate.dpl = dpl;
15717+ gate->gate.p = 1;
15718+ gate->gate.offset_high = base >> 16;
15719 }
15720
15721 #endif
15722@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
15723
15724 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
15725 {
15726+ pax_open_kernel();
15727 memcpy(&idt[entry], gate, sizeof(*gate));
15728+ pax_close_kernel();
15729 }
15730
15731 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
15732 {
15733+ pax_open_kernel();
15734 memcpy(&ldt[entry], desc, 8);
15735+ pax_close_kernel();
15736 }
15737
15738 static inline void
15739@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
15740 default: size = sizeof(*gdt); break;
15741 }
15742
15743+ pax_open_kernel();
15744 memcpy(&gdt[entry], desc, size);
15745+ pax_close_kernel();
15746 }
15747
15748 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
15749@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
15750
15751 static inline void native_load_tr_desc(void)
15752 {
15753+ pax_open_kernel();
15754 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
15755+ pax_close_kernel();
15756 }
15757
15758 static inline void native_load_gdt(const struct desc_ptr *dtr)
15759@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
15760 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
15761 unsigned int i;
15762
15763+ pax_open_kernel();
15764 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
15765 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
15766+ pax_close_kernel();
15767 }
15768
15769 #define _LDT_empty(info) \
15770@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
15771 preempt_enable();
15772 }
15773
15774-static inline unsigned long get_desc_base(const struct desc_struct *desc)
15775+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
15776 {
15777 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
15778 }
15779@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
15780 }
15781
15782 #ifdef CONFIG_X86_64
15783-static inline void set_nmi_gate(int gate, void *addr)
15784+static inline void set_nmi_gate(int gate, const void *addr)
15785 {
15786 gate_desc s;
15787
15788@@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
15789 #endif
15790
15791 #ifdef CONFIG_TRACING
15792-extern struct desc_ptr trace_idt_descr;
15793-extern gate_desc trace_idt_table[];
15794+extern const struct desc_ptr trace_idt_descr;
15795+extern gate_desc trace_idt_table[IDT_ENTRIES];
15796 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15797 {
15798 write_idt_entry(trace_idt_table, entry, gate);
15799 }
15800
15801-static inline void _trace_set_gate(int gate, unsigned type, void *addr,
15802+static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
15803 unsigned dpl, unsigned ist, unsigned seg)
15804 {
15805 gate_desc s;
15806@@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15807 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
15808 #endif
15809
15810-static inline void _set_gate(int gate, unsigned type, void *addr,
15811+static inline void _set_gate(int gate, unsigned type, const void *addr,
15812 unsigned dpl, unsigned ist, unsigned seg)
15813 {
15814 gate_desc s;
15815@@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
15816 #define set_intr_gate(n, addr) \
15817 do { \
15818 BUG_ON((unsigned)n > 0xFF); \
15819- _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
15820+ _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
15821 __KERNEL_CS); \
15822- _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
15823+ _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
15824 0, 0, __KERNEL_CS); \
15825 } while (0)
15826
15827@@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
15828 /*
15829 * This routine sets up an interrupt gate at directory privilege level 3.
15830 */
15831-static inline void set_system_intr_gate(unsigned int n, void *addr)
15832+static inline void set_system_intr_gate(unsigned int n, const void *addr)
15833 {
15834 BUG_ON((unsigned)n > 0xFF);
15835 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
15836 }
15837
15838-static inline void set_system_trap_gate(unsigned int n, void *addr)
15839+static inline void set_system_trap_gate(unsigned int n, const void *addr)
15840 {
15841 BUG_ON((unsigned)n > 0xFF);
15842 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
15843 }
15844
15845-static inline void set_trap_gate(unsigned int n, void *addr)
15846+static inline void set_trap_gate(unsigned int n, const void *addr)
15847 {
15848 BUG_ON((unsigned)n > 0xFF);
15849 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
15850@@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
15851 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
15852 {
15853 BUG_ON((unsigned)n > 0xFF);
15854- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
15855+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
15856 }
15857
15858-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
15859+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
15860 {
15861 BUG_ON((unsigned)n > 0xFF);
15862 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
15863 }
15864
15865-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
15866+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
15867 {
15868 BUG_ON((unsigned)n > 0xFF);
15869 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
15870@@ -503,4 +516,17 @@ static inline void load_current_idt(void)
15871 else
15872 load_idt((const struct desc_ptr *)&idt_descr);
15873 }
15874+
15875+#ifdef CONFIG_X86_32
15876+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
15877+{
15878+ struct desc_struct d;
15879+
15880+ if (likely(limit))
15881+ limit = (limit - 1UL) >> PAGE_SHIFT;
15882+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
15883+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
15884+}
15885+#endif
15886+
15887 #endif /* _ASM_X86_DESC_H */
15888diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
15889index 278441f..b95a174 100644
15890--- a/arch/x86/include/asm/desc_defs.h
15891+++ b/arch/x86/include/asm/desc_defs.h
15892@@ -31,6 +31,12 @@ struct desc_struct {
15893 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
15894 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
15895 };
15896+ struct {
15897+ u16 offset_low;
15898+ u16 seg;
15899+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
15900+ unsigned offset_high: 16;
15901+ } gate;
15902 };
15903 } __attribute__((packed));
15904
15905diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
15906index ced283a..ffe04cc 100644
15907--- a/arch/x86/include/asm/div64.h
15908+++ b/arch/x86/include/asm/div64.h
15909@@ -39,7 +39,7 @@
15910 __mod; \
15911 })
15912
15913-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15914+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15915 {
15916 union {
15917 u64 v64;
15918diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
15919index 9c999c1..3860cb8 100644
15920--- a/arch/x86/include/asm/elf.h
15921+++ b/arch/x86/include/asm/elf.h
15922@@ -243,7 +243,25 @@ extern int force_personality32;
15923 the loader. We need to make sure that it is out of the way of the program
15924 that it will "exec", and that there is sufficient room for the brk. */
15925
15926+#ifdef CONFIG_PAX_SEGMEXEC
15927+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
15928+#else
15929 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
15930+#endif
15931+
15932+#ifdef CONFIG_PAX_ASLR
15933+#ifdef CONFIG_X86_32
15934+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
15935+
15936+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15937+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15938+#else
15939+#define PAX_ELF_ET_DYN_BASE 0x400000UL
15940+
15941+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15942+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15943+#endif
15944+#endif
15945
15946 /* This yields a mask that user programs can use to figure out what
15947 instruction set this CPU supports. This could be done in user space,
15948@@ -296,16 +314,12 @@ do { \
15949
15950 #define ARCH_DLINFO \
15951 do { \
15952- if (vdso_enabled) \
15953- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15954- (unsigned long)current->mm->context.vdso); \
15955+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15956 } while (0)
15957
15958 #define ARCH_DLINFO_X32 \
15959 do { \
15960- if (vdso_enabled) \
15961- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15962- (unsigned long)current->mm->context.vdso); \
15963+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15964 } while (0)
15965
15966 #define AT_SYSINFO 32
15967@@ -320,7 +334,7 @@ else \
15968
15969 #endif /* !CONFIG_X86_32 */
15970
15971-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
15972+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
15973
15974 #define VDSO_ENTRY \
15975 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
15976@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
15977 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
15978 #define compat_arch_setup_additional_pages syscall32_setup_pages
15979
15980-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
15981-#define arch_randomize_brk arch_randomize_brk
15982-
15983 /*
15984 * True on X86_32 or when emulating IA32 on X86_64
15985 */
15986diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
15987index 77a99ac..39ff7f5 100644
15988--- a/arch/x86/include/asm/emergency-restart.h
15989+++ b/arch/x86/include/asm/emergency-restart.h
15990@@ -1,6 +1,6 @@
15991 #ifndef _ASM_X86_EMERGENCY_RESTART_H
15992 #define _ASM_X86_EMERGENCY_RESTART_H
15993
15994-extern void machine_emergency_restart(void);
15995+extern void machine_emergency_restart(void) __noreturn;
15996
15997 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
15998diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
15999index d3d7469..677ef72 100644
16000--- a/arch/x86/include/asm/floppy.h
16001+++ b/arch/x86/include/asm/floppy.h
16002@@ -229,18 +229,18 @@ static struct fd_routine_l {
16003 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16004 } fd_routine[] = {
16005 {
16006- request_dma,
16007- free_dma,
16008- get_dma_residue,
16009- dma_mem_alloc,
16010- hard_dma_setup
16011+ ._request_dma = request_dma,
16012+ ._free_dma = free_dma,
16013+ ._get_dma_residue = get_dma_residue,
16014+ ._dma_mem_alloc = dma_mem_alloc,
16015+ ._dma_setup = hard_dma_setup
16016 },
16017 {
16018- vdma_request_dma,
16019- vdma_nop,
16020- vdma_get_dma_residue,
16021- vdma_mem_alloc,
16022- vdma_dma_setup
16023+ ._request_dma = vdma_request_dma,
16024+ ._free_dma = vdma_nop,
16025+ ._get_dma_residue = vdma_get_dma_residue,
16026+ ._dma_mem_alloc = vdma_mem_alloc,
16027+ ._dma_setup = vdma_dma_setup
16028 }
16029 };
16030
16031diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16032index cea1c76..6c0d79b 100644
16033--- a/arch/x86/include/asm/fpu-internal.h
16034+++ b/arch/x86/include/asm/fpu-internal.h
16035@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16036 #define user_insn(insn, output, input...) \
16037 ({ \
16038 int err; \
16039+ pax_open_userland(); \
16040 asm volatile(ASM_STAC "\n" \
16041- "1:" #insn "\n\t" \
16042+ "1:" \
16043+ __copyuser_seg \
16044+ #insn "\n\t" \
16045 "2: " ASM_CLAC "\n" \
16046 ".section .fixup,\"ax\"\n" \
16047 "3: movl $-1,%[err]\n" \
16048@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16049 _ASM_EXTABLE(1b, 3b) \
16050 : [err] "=r" (err), output \
16051 : "0"(0), input); \
16052+ pax_close_userland(); \
16053 err; \
16054 })
16055
16056@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16057 "fnclex\n\t"
16058 "emms\n\t"
16059 "fildl %P[addr]" /* set F?P to defined value */
16060- : : [addr] "m" (tsk->thread.fpu.has_fpu));
16061+ : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16062 }
16063
16064 return fpu_restore_checking(&tsk->thread.fpu);
16065diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16066index be27ba1..04a8801 100644
16067--- a/arch/x86/include/asm/futex.h
16068+++ b/arch/x86/include/asm/futex.h
16069@@ -12,6 +12,7 @@
16070 #include <asm/smap.h>
16071
16072 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16073+ typecheck(u32 __user *, uaddr); \
16074 asm volatile("\t" ASM_STAC "\n" \
16075 "1:\t" insn "\n" \
16076 "2:\t" ASM_CLAC "\n" \
16077@@ -20,15 +21,16 @@
16078 "\tjmp\t2b\n" \
16079 "\t.previous\n" \
16080 _ASM_EXTABLE(1b, 3b) \
16081- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16082+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16083 : "i" (-EFAULT), "0" (oparg), "1" (0))
16084
16085 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16086+ typecheck(u32 __user *, uaddr); \
16087 asm volatile("\t" ASM_STAC "\n" \
16088 "1:\tmovl %2, %0\n" \
16089 "\tmovl\t%0, %3\n" \
16090 "\t" insn "\n" \
16091- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16092+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16093 "\tjnz\t1b\n" \
16094 "3:\t" ASM_CLAC "\n" \
16095 "\t.section .fixup,\"ax\"\n" \
16096@@ -38,7 +40,7 @@
16097 _ASM_EXTABLE(1b, 4b) \
16098 _ASM_EXTABLE(2b, 4b) \
16099 : "=&a" (oldval), "=&r" (ret), \
16100- "+m" (*uaddr), "=&r" (tem) \
16101+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16102 : "r" (oparg), "i" (-EFAULT), "1" (0))
16103
16104 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16105@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16106
16107 pagefault_disable();
16108
16109+ pax_open_userland();
16110 switch (op) {
16111 case FUTEX_OP_SET:
16112- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16113+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16114 break;
16115 case FUTEX_OP_ADD:
16116- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16117+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16118 uaddr, oparg);
16119 break;
16120 case FUTEX_OP_OR:
16121@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16122 default:
16123 ret = -ENOSYS;
16124 }
16125+ pax_close_userland();
16126
16127 pagefault_enable();
16128
16129@@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
16130 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
16131 return -EFAULT;
16132
16133+ pax_open_userland();
16134 asm volatile("\t" ASM_STAC "\n"
16135- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
16136+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
16137 "2:\t" ASM_CLAC "\n"
16138 "\t.section .fixup, \"ax\"\n"
16139 "3:\tmov %3, %0\n"
16140 "\tjmp 2b\n"
16141 "\t.previous\n"
16142 _ASM_EXTABLE(1b, 3b)
16143- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
16144+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
16145 : "i" (-EFAULT), "r" (newval), "1" (oldval)
16146 : "memory"
16147 );
16148+ pax_close_userland();
16149
16150 *uval = oldval;
16151 return ret;
16152diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16153index cba45d9..86344ba 100644
16154--- a/arch/x86/include/asm/hw_irq.h
16155+++ b/arch/x86/include/asm/hw_irq.h
16156@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16157 extern void enable_IO_APIC(void);
16158
16159 /* Statistics */
16160-extern atomic_t irq_err_count;
16161-extern atomic_t irq_mis_count;
16162+extern atomic_unchecked_t irq_err_count;
16163+extern atomic_unchecked_t irq_mis_count;
16164
16165 /* EISA */
16166 extern void eisa_set_level_irq(unsigned int irq);
16167diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16168index a203659..9889f1c 100644
16169--- a/arch/x86/include/asm/i8259.h
16170+++ b/arch/x86/include/asm/i8259.h
16171@@ -62,7 +62,7 @@ struct legacy_pic {
16172 void (*init)(int auto_eoi);
16173 int (*irq_pending)(unsigned int irq);
16174 void (*make_irq)(unsigned int irq);
16175-};
16176+} __do_const;
16177
16178 extern struct legacy_pic *legacy_pic;
16179 extern struct legacy_pic null_legacy_pic;
16180diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16181index 34f69cb..6d95446 100644
16182--- a/arch/x86/include/asm/io.h
16183+++ b/arch/x86/include/asm/io.h
16184@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16185 "m" (*(volatile type __force *)addr) barrier); }
16186
16187 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16188-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16189-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16190+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16191+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16192
16193 build_mmio_read(__readb, "b", unsigned char, "=q", )
16194-build_mmio_read(__readw, "w", unsigned short, "=r", )
16195-build_mmio_read(__readl, "l", unsigned int, "=r", )
16196+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16197+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16198
16199 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16200 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16201@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16202 return ioremap_nocache(offset, size);
16203 }
16204
16205-extern void iounmap(volatile void __iomem *addr);
16206+extern void iounmap(const volatile void __iomem *addr);
16207
16208 extern void set_iounmap_nonlazy(void);
16209
16210@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
16211
16212 #include <linux/vmalloc.h>
16213
16214+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16215+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16216+{
16217+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16218+}
16219+
16220+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16221+{
16222+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16223+}
16224+
16225 /*
16226 * Convert a virtual cached pointer to an uncached pointer
16227 */
16228diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16229index bba3cf8..06bc8da 100644
16230--- a/arch/x86/include/asm/irqflags.h
16231+++ b/arch/x86/include/asm/irqflags.h
16232@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16233 sti; \
16234 sysexit
16235
16236+#define GET_CR0_INTO_RDI mov %cr0, %rdi
16237+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16238+#define GET_CR3_INTO_RDI mov %cr3, %rdi
16239+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16240+
16241 #else
16242 #define INTERRUPT_RETURN iret
16243 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16244diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16245index 9454c16..e4100e3 100644
16246--- a/arch/x86/include/asm/kprobes.h
16247+++ b/arch/x86/include/asm/kprobes.h
16248@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16249 #define RELATIVEJUMP_SIZE 5
16250 #define RELATIVECALL_OPCODE 0xe8
16251 #define RELATIVE_ADDR_SIZE 4
16252-#define MAX_STACK_SIZE 64
16253-#define MIN_STACK_SIZE(ADDR) \
16254- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16255- THREAD_SIZE - (unsigned long)(ADDR))) \
16256- ? (MAX_STACK_SIZE) \
16257- : (((unsigned long)current_thread_info()) + \
16258- THREAD_SIZE - (unsigned long)(ADDR)))
16259+#define MAX_STACK_SIZE 64UL
16260+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16261
16262 #define flush_insn_slot(p) do { } while (0)
16263
16264diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16265index 4ad6560..75c7bdd 100644
16266--- a/arch/x86/include/asm/local.h
16267+++ b/arch/x86/include/asm/local.h
16268@@ -10,33 +10,97 @@ typedef struct {
16269 atomic_long_t a;
16270 } local_t;
16271
16272+typedef struct {
16273+ atomic_long_unchecked_t a;
16274+} local_unchecked_t;
16275+
16276 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16277
16278 #define local_read(l) atomic_long_read(&(l)->a)
16279+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16280 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16281+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16282
16283 static inline void local_inc(local_t *l)
16284 {
16285- asm volatile(_ASM_INC "%0"
16286+ asm volatile(_ASM_INC "%0\n"
16287+
16288+#ifdef CONFIG_PAX_REFCOUNT
16289+ "jno 0f\n"
16290+ _ASM_DEC "%0\n"
16291+ "int $4\n0:\n"
16292+ _ASM_EXTABLE(0b, 0b)
16293+#endif
16294+
16295+ : "+m" (l->a.counter));
16296+}
16297+
16298+static inline void local_inc_unchecked(local_unchecked_t *l)
16299+{
16300+ asm volatile(_ASM_INC "%0\n"
16301 : "+m" (l->a.counter));
16302 }
16303
16304 static inline void local_dec(local_t *l)
16305 {
16306- asm volatile(_ASM_DEC "%0"
16307+ asm volatile(_ASM_DEC "%0\n"
16308+
16309+#ifdef CONFIG_PAX_REFCOUNT
16310+ "jno 0f\n"
16311+ _ASM_INC "%0\n"
16312+ "int $4\n0:\n"
16313+ _ASM_EXTABLE(0b, 0b)
16314+#endif
16315+
16316+ : "+m" (l->a.counter));
16317+}
16318+
16319+static inline void local_dec_unchecked(local_unchecked_t *l)
16320+{
16321+ asm volatile(_ASM_DEC "%0\n"
16322 : "+m" (l->a.counter));
16323 }
16324
16325 static inline void local_add(long i, local_t *l)
16326 {
16327- asm volatile(_ASM_ADD "%1,%0"
16328+ asm volatile(_ASM_ADD "%1,%0\n"
16329+
16330+#ifdef CONFIG_PAX_REFCOUNT
16331+ "jno 0f\n"
16332+ _ASM_SUB "%1,%0\n"
16333+ "int $4\n0:\n"
16334+ _ASM_EXTABLE(0b, 0b)
16335+#endif
16336+
16337+ : "+m" (l->a.counter)
16338+ : "ir" (i));
16339+}
16340+
16341+static inline void local_add_unchecked(long i, local_unchecked_t *l)
16342+{
16343+ asm volatile(_ASM_ADD "%1,%0\n"
16344 : "+m" (l->a.counter)
16345 : "ir" (i));
16346 }
16347
16348 static inline void local_sub(long i, local_t *l)
16349 {
16350- asm volatile(_ASM_SUB "%1,%0"
16351+ asm volatile(_ASM_SUB "%1,%0\n"
16352+
16353+#ifdef CONFIG_PAX_REFCOUNT
16354+ "jno 0f\n"
16355+ _ASM_ADD "%1,%0\n"
16356+ "int $4\n0:\n"
16357+ _ASM_EXTABLE(0b, 0b)
16358+#endif
16359+
16360+ : "+m" (l->a.counter)
16361+ : "ir" (i));
16362+}
16363+
16364+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16365+{
16366+ asm volatile(_ASM_SUB "%1,%0\n"
16367 : "+m" (l->a.counter)
16368 : "ir" (i));
16369 }
16370@@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16371 */
16372 static inline int local_sub_and_test(long i, local_t *l)
16373 {
16374- GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16375+ GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16376 }
16377
16378 /**
16379@@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16380 */
16381 static inline int local_dec_and_test(local_t *l)
16382 {
16383- GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16384+ GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16385 }
16386
16387 /**
16388@@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
16389 */
16390 static inline int local_inc_and_test(local_t *l)
16391 {
16392- GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
16393+ GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
16394 }
16395
16396 /**
16397@@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
16398 */
16399 static inline int local_add_negative(long i, local_t *l)
16400 {
16401- GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
16402+ GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
16403 }
16404
16405 /**
16406@@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
16407 static inline long local_add_return(long i, local_t *l)
16408 {
16409 long __i = i;
16410+ asm volatile(_ASM_XADD "%0, %1\n"
16411+
16412+#ifdef CONFIG_PAX_REFCOUNT
16413+ "jno 0f\n"
16414+ _ASM_MOV "%0,%1\n"
16415+ "int $4\n0:\n"
16416+ _ASM_EXTABLE(0b, 0b)
16417+#endif
16418+
16419+ : "+r" (i), "+m" (l->a.counter)
16420+ : : "memory");
16421+ return i + __i;
16422+}
16423+
16424+/**
16425+ * local_add_return_unchecked - add and return
16426+ * @i: integer value to add
16427+ * @l: pointer to type local_unchecked_t
16428+ *
16429+ * Atomically adds @i to @l and returns @i + @l
16430+ */
16431+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
16432+{
16433+ long __i = i;
16434 asm volatile(_ASM_XADD "%0, %1;"
16435 : "+r" (i), "+m" (l->a.counter)
16436 : : "memory");
16437@@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
16438
16439 #define local_cmpxchg(l, o, n) \
16440 (cmpxchg_local(&((l)->a.counter), (o), (n)))
16441+#define local_cmpxchg_unchecked(l, o, n) \
16442+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
16443 /* Always has a lock prefix */
16444 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
16445
16446diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
16447new file mode 100644
16448index 0000000..2bfd3ba
16449--- /dev/null
16450+++ b/arch/x86/include/asm/mman.h
16451@@ -0,0 +1,15 @@
16452+#ifndef _X86_MMAN_H
16453+#define _X86_MMAN_H
16454+
16455+#include <uapi/asm/mman.h>
16456+
16457+#ifdef __KERNEL__
16458+#ifndef __ASSEMBLY__
16459+#ifdef CONFIG_X86_32
16460+#define arch_mmap_check i386_mmap_check
16461+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
16462+#endif
16463+#endif
16464+#endif
16465+
16466+#endif /* X86_MMAN_H */
16467diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
16468index 5f55e69..e20bfb1 100644
16469--- a/arch/x86/include/asm/mmu.h
16470+++ b/arch/x86/include/asm/mmu.h
16471@@ -9,7 +9,7 @@
16472 * we put the segment information here.
16473 */
16474 typedef struct {
16475- void *ldt;
16476+ struct desc_struct *ldt;
16477 int size;
16478
16479 #ifdef CONFIG_X86_64
16480@@ -18,7 +18,19 @@ typedef struct {
16481 #endif
16482
16483 struct mutex lock;
16484- void *vdso;
16485+ unsigned long vdso;
16486+
16487+#ifdef CONFIG_X86_32
16488+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16489+ unsigned long user_cs_base;
16490+ unsigned long user_cs_limit;
16491+
16492+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16493+ cpumask_t cpu_user_cs_mask;
16494+#endif
16495+
16496+#endif
16497+#endif
16498 } mm_context_t;
16499
16500 #ifdef CONFIG_SMP
16501diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
16502index be12c53..4d24039 100644
16503--- a/arch/x86/include/asm/mmu_context.h
16504+++ b/arch/x86/include/asm/mmu_context.h
16505@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
16506
16507 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
16508 {
16509+
16510+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16511+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
16512+ unsigned int i;
16513+ pgd_t *pgd;
16514+
16515+ pax_open_kernel();
16516+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
16517+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
16518+ set_pgd_batched(pgd+i, native_make_pgd(0));
16519+ pax_close_kernel();
16520+ }
16521+#endif
16522+
16523 #ifdef CONFIG_SMP
16524 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
16525 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
16526@@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16527 struct task_struct *tsk)
16528 {
16529 unsigned cpu = smp_processor_id();
16530+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16531+ int tlbstate = TLBSTATE_OK;
16532+#endif
16533
16534 if (likely(prev != next)) {
16535 #ifdef CONFIG_SMP
16536+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16537+ tlbstate = this_cpu_read(cpu_tlbstate.state);
16538+#endif
16539 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16540 this_cpu_write(cpu_tlbstate.active_mm, next);
16541 #endif
16542 cpumask_set_cpu(cpu, mm_cpumask(next));
16543
16544 /* Re-load page tables */
16545+#ifdef CONFIG_PAX_PER_CPU_PGD
16546+ pax_open_kernel();
16547+
16548+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16549+ if (static_cpu_has(X86_FEATURE_PCID))
16550+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16551+ else
16552+#endif
16553+
16554+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16555+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16556+ pax_close_kernel();
16557+ 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));
16558+
16559+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16560+ if (static_cpu_has(X86_FEATURE_PCID)) {
16561+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
16562+ u64 descriptor[2];
16563+ descriptor[0] = PCID_USER;
16564+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16565+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
16566+ descriptor[0] = PCID_KERNEL;
16567+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16568+ }
16569+ } else {
16570+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16571+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16572+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16573+ else
16574+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16575+ }
16576+ } else
16577+#endif
16578+
16579+ load_cr3(get_cpu_pgd(cpu, kernel));
16580+#else
16581 load_cr3(next->pgd);
16582+#endif
16583
16584 /* Stop flush ipis for the previous mm */
16585 cpumask_clear_cpu(cpu, mm_cpumask(prev));
16586@@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16587 /* Load the LDT, if the LDT is different: */
16588 if (unlikely(prev->context.ldt != next->context.ldt))
16589 load_LDT_nolock(&next->context);
16590+
16591+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16592+ if (!(__supported_pte_mask & _PAGE_NX)) {
16593+ smp_mb__before_clear_bit();
16594+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
16595+ smp_mb__after_clear_bit();
16596+ cpu_set(cpu, next->context.cpu_user_cs_mask);
16597+ }
16598+#endif
16599+
16600+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16601+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
16602+ prev->context.user_cs_limit != next->context.user_cs_limit))
16603+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16604+#ifdef CONFIG_SMP
16605+ else if (unlikely(tlbstate != TLBSTATE_OK))
16606+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16607+#endif
16608+#endif
16609+
16610 }
16611+ else {
16612+
16613+#ifdef CONFIG_PAX_PER_CPU_PGD
16614+ pax_open_kernel();
16615+
16616+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16617+ if (static_cpu_has(X86_FEATURE_PCID))
16618+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16619+ else
16620+#endif
16621+
16622+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16623+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16624+ pax_close_kernel();
16625+ 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));
16626+
16627+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16628+ if (static_cpu_has(X86_FEATURE_PCID)) {
16629+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
16630+ u64 descriptor[2];
16631+ descriptor[0] = PCID_USER;
16632+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16633+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
16634+ descriptor[0] = PCID_KERNEL;
16635+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16636+ }
16637+ } else {
16638+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16639+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16640+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16641+ else
16642+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16643+ }
16644+ } else
16645+#endif
16646+
16647+ load_cr3(get_cpu_pgd(cpu, kernel));
16648+#endif
16649+
16650 #ifdef CONFIG_SMP
16651- else {
16652 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16653 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
16654
16655@@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16656 * tlb flush IPI delivery. We must reload CR3
16657 * to make sure to use no freed page tables.
16658 */
16659+
16660+#ifndef CONFIG_PAX_PER_CPU_PGD
16661 load_cr3(next->pgd);
16662+#endif
16663+
16664 load_LDT_nolock(&next->context);
16665+
16666+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
16667+ if (!(__supported_pte_mask & _PAGE_NX))
16668+ cpu_set(cpu, next->context.cpu_user_cs_mask);
16669+#endif
16670+
16671+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16672+#ifdef CONFIG_PAX_PAGEEXEC
16673+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
16674+#endif
16675+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16676+#endif
16677+
16678 }
16679+#endif
16680 }
16681-#endif
16682 }
16683
16684 #define activate_mm(prev, next) \
16685diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
16686index e3b7819..b257c64 100644
16687--- a/arch/x86/include/asm/module.h
16688+++ b/arch/x86/include/asm/module.h
16689@@ -5,6 +5,7 @@
16690
16691 #ifdef CONFIG_X86_64
16692 /* X86_64 does not define MODULE_PROC_FAMILY */
16693+#define MODULE_PROC_FAMILY ""
16694 #elif defined CONFIG_M486
16695 #define MODULE_PROC_FAMILY "486 "
16696 #elif defined CONFIG_M586
16697@@ -57,8 +58,20 @@
16698 #error unknown processor family
16699 #endif
16700
16701-#ifdef CONFIG_X86_32
16702-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
16703+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
16704+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
16705+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
16706+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
16707+#else
16708+#define MODULE_PAX_KERNEXEC ""
16709 #endif
16710
16711+#ifdef CONFIG_PAX_MEMORY_UDEREF
16712+#define MODULE_PAX_UDEREF "UDEREF "
16713+#else
16714+#define MODULE_PAX_UDEREF ""
16715+#endif
16716+
16717+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
16718+
16719 #endif /* _ASM_X86_MODULE_H */
16720diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
16721index 86f9301..b365cda 100644
16722--- a/arch/x86/include/asm/nmi.h
16723+++ b/arch/x86/include/asm/nmi.h
16724@@ -40,11 +40,11 @@ struct nmiaction {
16725 nmi_handler_t handler;
16726 unsigned long flags;
16727 const char *name;
16728-};
16729+} __do_const;
16730
16731 #define register_nmi_handler(t, fn, fg, n, init...) \
16732 ({ \
16733- static struct nmiaction init fn##_na = { \
16734+ static const struct nmiaction init fn##_na = { \
16735 .handler = (fn), \
16736 .name = (n), \
16737 .flags = (fg), \
16738@@ -52,7 +52,7 @@ struct nmiaction {
16739 __register_nmi_handler((t), &fn##_na); \
16740 })
16741
16742-int __register_nmi_handler(unsigned int, struct nmiaction *);
16743+int __register_nmi_handler(unsigned int, const struct nmiaction *);
16744
16745 void unregister_nmi_handler(unsigned int, const char *);
16746
16747diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
16748index c878924..21f4889 100644
16749--- a/arch/x86/include/asm/page.h
16750+++ b/arch/x86/include/asm/page.h
16751@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
16752 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
16753
16754 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
16755+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
16756
16757 #define __boot_va(x) __va(x)
16758 #define __boot_pa(x) __pa(x)
16759diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
16760index 0f1ddee..e2fc3d1 100644
16761--- a/arch/x86/include/asm/page_64.h
16762+++ b/arch/x86/include/asm/page_64.h
16763@@ -7,9 +7,9 @@
16764
16765 /* duplicated to the one in bootmem.h */
16766 extern unsigned long max_pfn;
16767-extern unsigned long phys_base;
16768+extern const unsigned long phys_base;
16769
16770-static inline unsigned long __phys_addr_nodebug(unsigned long x)
16771+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
16772 {
16773 unsigned long y = x - __START_KERNEL_map;
16774
16775diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
16776index 401f350..dee5d13 100644
16777--- a/arch/x86/include/asm/paravirt.h
16778+++ b/arch/x86/include/asm/paravirt.h
16779@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
16780 return (pmd_t) { ret };
16781 }
16782
16783-static inline pmdval_t pmd_val(pmd_t pmd)
16784+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
16785 {
16786 pmdval_t ret;
16787
16788@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
16789 val);
16790 }
16791
16792+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16793+{
16794+ pgdval_t val = native_pgd_val(pgd);
16795+
16796+ if (sizeof(pgdval_t) > sizeof(long))
16797+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
16798+ val, (u64)val >> 32);
16799+ else
16800+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
16801+ val);
16802+}
16803+
16804 static inline void pgd_clear(pgd_t *pgdp)
16805 {
16806 set_pgd(pgdp, __pgd(0));
16807@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
16808 pv_mmu_ops.set_fixmap(idx, phys, flags);
16809 }
16810
16811+#ifdef CONFIG_PAX_KERNEXEC
16812+static inline unsigned long pax_open_kernel(void)
16813+{
16814+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
16815+}
16816+
16817+static inline unsigned long pax_close_kernel(void)
16818+{
16819+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
16820+}
16821+#else
16822+static inline unsigned long pax_open_kernel(void) { return 0; }
16823+static inline unsigned long pax_close_kernel(void) { return 0; }
16824+#endif
16825+
16826 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
16827
16828 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
16829@@ -906,7 +933,7 @@ extern void default_banner(void);
16830
16831 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
16832 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
16833-#define PARA_INDIRECT(addr) *%cs:addr
16834+#define PARA_INDIRECT(addr) *%ss:addr
16835 #endif
16836
16837 #define INTERRUPT_RETURN \
16838@@ -981,6 +1008,21 @@ extern void default_banner(void);
16839 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
16840 CLBR_NONE, \
16841 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
16842+
16843+#define GET_CR0_INTO_RDI \
16844+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
16845+ mov %rax,%rdi
16846+
16847+#define SET_RDI_INTO_CR0 \
16848+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16849+
16850+#define GET_CR3_INTO_RDI \
16851+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
16852+ mov %rax,%rdi
16853+
16854+#define SET_RDI_INTO_CR3 \
16855+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
16856+
16857 #endif /* CONFIG_X86_32 */
16858
16859 #endif /* __ASSEMBLY__ */
16860diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
16861index aab8f67..0fb0ee4 100644
16862--- a/arch/x86/include/asm/paravirt_types.h
16863+++ b/arch/x86/include/asm/paravirt_types.h
16864@@ -84,7 +84,7 @@ struct pv_init_ops {
16865 */
16866 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
16867 unsigned long addr, unsigned len);
16868-};
16869+} __no_const __no_randomize_layout;
16870
16871
16872 struct pv_lazy_ops {
16873@@ -92,13 +92,13 @@ struct pv_lazy_ops {
16874 void (*enter)(void);
16875 void (*leave)(void);
16876 void (*flush)(void);
16877-};
16878+} __no_randomize_layout;
16879
16880 struct pv_time_ops {
16881 unsigned long long (*sched_clock)(void);
16882 unsigned long long (*steal_clock)(int cpu);
16883 unsigned long (*get_tsc_khz)(void);
16884-};
16885+} __no_const __no_randomize_layout;
16886
16887 struct pv_cpu_ops {
16888 /* hooks for various privileged instructions */
16889@@ -192,7 +192,7 @@ struct pv_cpu_ops {
16890
16891 void (*start_context_switch)(struct task_struct *prev);
16892 void (*end_context_switch)(struct task_struct *next);
16893-};
16894+} __no_const __no_randomize_layout;
16895
16896 struct pv_irq_ops {
16897 /*
16898@@ -215,7 +215,7 @@ struct pv_irq_ops {
16899 #ifdef CONFIG_X86_64
16900 void (*adjust_exception_frame)(void);
16901 #endif
16902-};
16903+} __no_randomize_layout;
16904
16905 struct pv_apic_ops {
16906 #ifdef CONFIG_X86_LOCAL_APIC
16907@@ -223,7 +223,7 @@ struct pv_apic_ops {
16908 unsigned long start_eip,
16909 unsigned long start_esp);
16910 #endif
16911-};
16912+} __no_const __no_randomize_layout;
16913
16914 struct pv_mmu_ops {
16915 unsigned long (*read_cr2)(void);
16916@@ -313,6 +313,7 @@ struct pv_mmu_ops {
16917 struct paravirt_callee_save make_pud;
16918
16919 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
16920+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
16921 #endif /* PAGETABLE_LEVELS == 4 */
16922 #endif /* PAGETABLE_LEVELS >= 3 */
16923
16924@@ -324,7 +325,13 @@ struct pv_mmu_ops {
16925 an mfn. We can tell which is which from the index. */
16926 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
16927 phys_addr_t phys, pgprot_t flags);
16928-};
16929+
16930+#ifdef CONFIG_PAX_KERNEXEC
16931+ unsigned long (*pax_open_kernel)(void);
16932+ unsigned long (*pax_close_kernel)(void);
16933+#endif
16934+
16935+} __no_randomize_layout;
16936
16937 struct arch_spinlock;
16938 #ifdef CONFIG_SMP
16939@@ -336,11 +343,14 @@ typedef u16 __ticket_t;
16940 struct pv_lock_ops {
16941 struct paravirt_callee_save lock_spinning;
16942 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
16943-};
16944+} __no_randomize_layout;
16945
16946 /* This contains all the paravirt structures: we get a convenient
16947 * number for each function using the offset which we use to indicate
16948- * what to patch. */
16949+ * what to patch.
16950+ * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
16951+ */
16952+
16953 struct paravirt_patch_template {
16954 struct pv_init_ops pv_init_ops;
16955 struct pv_time_ops pv_time_ops;
16956@@ -349,7 +359,7 @@ struct paravirt_patch_template {
16957 struct pv_apic_ops pv_apic_ops;
16958 struct pv_mmu_ops pv_mmu_ops;
16959 struct pv_lock_ops pv_lock_ops;
16960-};
16961+} __no_randomize_layout;
16962
16963 extern struct pv_info pv_info;
16964 extern struct pv_init_ops pv_init_ops;
16965diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
16966index c4412e9..90e88c5 100644
16967--- a/arch/x86/include/asm/pgalloc.h
16968+++ b/arch/x86/include/asm/pgalloc.h
16969@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
16970 pmd_t *pmd, pte_t *pte)
16971 {
16972 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16973+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
16974+}
16975+
16976+static inline void pmd_populate_user(struct mm_struct *mm,
16977+ pmd_t *pmd, pte_t *pte)
16978+{
16979+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16980 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
16981 }
16982
16983@@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
16984
16985 #ifdef CONFIG_X86_PAE
16986 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
16987+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
16988+{
16989+ pud_populate(mm, pudp, pmd);
16990+}
16991 #else /* !CONFIG_X86_PAE */
16992 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16993 {
16994 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16995 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
16996 }
16997+
16998+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16999+{
17000+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17001+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17002+}
17003 #endif /* CONFIG_X86_PAE */
17004
17005 #if PAGETABLE_LEVELS > 3
17006@@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17007 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17008 }
17009
17010+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17011+{
17012+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17013+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17014+}
17015+
17016 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17017 {
17018 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17019diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17020index 3bf2dd0..23d2a9f 100644
17021--- a/arch/x86/include/asm/pgtable-2level.h
17022+++ b/arch/x86/include/asm/pgtable-2level.h
17023@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17024
17025 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17026 {
17027+ pax_open_kernel();
17028 *pmdp = pmd;
17029+ pax_close_kernel();
17030 }
17031
17032 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17033diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17034index 81bb91b..9392125 100644
17035--- a/arch/x86/include/asm/pgtable-3level.h
17036+++ b/arch/x86/include/asm/pgtable-3level.h
17037@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17038
17039 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17040 {
17041+ pax_open_kernel();
17042 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17043+ pax_close_kernel();
17044 }
17045
17046 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17047 {
17048+ pax_open_kernel();
17049 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17050+ pax_close_kernel();
17051 }
17052
17053 /*
17054diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17055index bbc8b12..f228861 100644
17056--- a/arch/x86/include/asm/pgtable.h
17057+++ b/arch/x86/include/asm/pgtable.h
17058@@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17059
17060 #ifndef __PAGETABLE_PUD_FOLDED
17061 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17062+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17063 #define pgd_clear(pgd) native_pgd_clear(pgd)
17064 #endif
17065
17066@@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17067
17068 #define arch_end_context_switch(prev) do {} while(0)
17069
17070+#define pax_open_kernel() native_pax_open_kernel()
17071+#define pax_close_kernel() native_pax_close_kernel()
17072 #endif /* CONFIG_PARAVIRT */
17073
17074+#define __HAVE_ARCH_PAX_OPEN_KERNEL
17075+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17076+
17077+#ifdef CONFIG_PAX_KERNEXEC
17078+static inline unsigned long native_pax_open_kernel(void)
17079+{
17080+ unsigned long cr0;
17081+
17082+ preempt_disable();
17083+ barrier();
17084+ cr0 = read_cr0() ^ X86_CR0_WP;
17085+ BUG_ON(cr0 & X86_CR0_WP);
17086+ write_cr0(cr0);
17087+ return cr0 ^ X86_CR0_WP;
17088+}
17089+
17090+static inline unsigned long native_pax_close_kernel(void)
17091+{
17092+ unsigned long cr0;
17093+
17094+ cr0 = read_cr0() ^ X86_CR0_WP;
17095+ BUG_ON(!(cr0 & X86_CR0_WP));
17096+ write_cr0(cr0);
17097+ barrier();
17098+ preempt_enable_no_resched();
17099+ return cr0 ^ X86_CR0_WP;
17100+}
17101+#else
17102+static inline unsigned long native_pax_open_kernel(void) { return 0; }
17103+static inline unsigned long native_pax_close_kernel(void) { return 0; }
17104+#endif
17105+
17106 /*
17107 * The following only work if pte_present() is true.
17108 * Undefined behaviour if not..
17109 */
17110+static inline int pte_user(pte_t pte)
17111+{
17112+ return pte_val(pte) & _PAGE_USER;
17113+}
17114+
17115 static inline int pte_dirty(pte_t pte)
17116 {
17117 return pte_flags(pte) & _PAGE_DIRTY;
17118@@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17119 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17120 }
17121
17122+static inline unsigned long pgd_pfn(pgd_t pgd)
17123+{
17124+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17125+}
17126+
17127 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17128
17129 static inline int pmd_large(pmd_t pte)
17130@@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17131 return pte_clear_flags(pte, _PAGE_RW);
17132 }
17133
17134+static inline pte_t pte_mkread(pte_t pte)
17135+{
17136+ return __pte(pte_val(pte) | _PAGE_USER);
17137+}
17138+
17139 static inline pte_t pte_mkexec(pte_t pte)
17140 {
17141- return pte_clear_flags(pte, _PAGE_NX);
17142+#ifdef CONFIG_X86_PAE
17143+ if (__supported_pte_mask & _PAGE_NX)
17144+ return pte_clear_flags(pte, _PAGE_NX);
17145+ else
17146+#endif
17147+ return pte_set_flags(pte, _PAGE_USER);
17148+}
17149+
17150+static inline pte_t pte_exprotect(pte_t pte)
17151+{
17152+#ifdef CONFIG_X86_PAE
17153+ if (__supported_pte_mask & _PAGE_NX)
17154+ return pte_set_flags(pte, _PAGE_NX);
17155+ else
17156+#endif
17157+ return pte_clear_flags(pte, _PAGE_USER);
17158 }
17159
17160 static inline pte_t pte_mkdirty(pte_t pte)
17161@@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17162 #endif
17163
17164 #ifndef __ASSEMBLY__
17165+
17166+#ifdef CONFIG_PAX_PER_CPU_PGD
17167+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17168+enum cpu_pgd_type {kernel = 0, user = 1};
17169+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17170+{
17171+ return cpu_pgd[cpu][type];
17172+}
17173+#endif
17174+
17175 #include <linux/mm_types.h>
17176 #include <linux/mmdebug.h>
17177 #include <linux/log2.h>
17178@@ -570,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17179 * Currently stuck as a macro due to indirect forward reference to
17180 * linux/mmzone.h's __section_mem_map_addr() definition:
17181 */
17182-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17183+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17184
17185 /* Find an entry in the second-level page table.. */
17186 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17187@@ -610,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17188 * Currently stuck as a macro due to indirect forward reference to
17189 * linux/mmzone.h's __section_mem_map_addr() definition:
17190 */
17191-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17192+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17193
17194 /* to find an entry in a page-table-directory. */
17195 static inline unsigned long pud_index(unsigned long address)
17196@@ -625,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17197
17198 static inline int pgd_bad(pgd_t pgd)
17199 {
17200- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17201+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17202 }
17203
17204 static inline int pgd_none(pgd_t pgd)
17205@@ -648,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
17206 * pgd_offset() returns a (pgd_t *)
17207 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17208 */
17209-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17210+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17211+
17212+#ifdef CONFIG_PAX_PER_CPU_PGD
17213+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17214+#endif
17215+
17216 /*
17217 * a shortcut which implies the use of the kernel's pgd, instead
17218 * of a process's
17219@@ -659,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
17220 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17221 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17222
17223+#ifdef CONFIG_X86_32
17224+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17225+#else
17226+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17227+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17228+
17229+#ifdef CONFIG_PAX_MEMORY_UDEREF
17230+#ifdef __ASSEMBLY__
17231+#define pax_user_shadow_base pax_user_shadow_base(%rip)
17232+#else
17233+extern unsigned long pax_user_shadow_base;
17234+extern pgdval_t clone_pgd_mask;
17235+#endif
17236+#endif
17237+
17238+#endif
17239+
17240 #ifndef __ASSEMBLY__
17241
17242 extern int direct_gbpages;
17243@@ -825,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17244 * dst and src can be on the same page, but the range must not overlap,
17245 * and must not cross a page boundary.
17246 */
17247-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17248+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17249 {
17250- memcpy(dst, src, count * sizeof(pgd_t));
17251+ pax_open_kernel();
17252+ while (count--)
17253+ *dst++ = *src++;
17254+ pax_close_kernel();
17255 }
17256
17257+#ifdef CONFIG_PAX_PER_CPU_PGD
17258+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17259+#endif
17260+
17261+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17262+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17263+#else
17264+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17265+#endif
17266+
17267 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17268 static inline int page_level_shift(enum pg_level level)
17269 {
17270diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17271index 9ee3221..b979c6b 100644
17272--- a/arch/x86/include/asm/pgtable_32.h
17273+++ b/arch/x86/include/asm/pgtable_32.h
17274@@ -25,9 +25,6 @@
17275 struct mm_struct;
17276 struct vm_area_struct;
17277
17278-extern pgd_t swapper_pg_dir[1024];
17279-extern pgd_t initial_page_table[1024];
17280-
17281 static inline void pgtable_cache_init(void) { }
17282 static inline void check_pgt_cache(void) { }
17283 void paging_init(void);
17284@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17285 # include <asm/pgtable-2level.h>
17286 #endif
17287
17288+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17289+extern pgd_t initial_page_table[PTRS_PER_PGD];
17290+#ifdef CONFIG_X86_PAE
17291+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17292+#endif
17293+
17294 #if defined(CONFIG_HIGHPTE)
17295 #define pte_offset_map(dir, address) \
17296 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17297@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17298 /* Clear a kernel PTE and flush it from the TLB */
17299 #define kpte_clear_flush(ptep, vaddr) \
17300 do { \
17301+ pax_open_kernel(); \
17302 pte_clear(&init_mm, (vaddr), (ptep)); \
17303+ pax_close_kernel(); \
17304 __flush_tlb_one((vaddr)); \
17305 } while (0)
17306
17307 #endif /* !__ASSEMBLY__ */
17308
17309+#define HAVE_ARCH_UNMAPPED_AREA
17310+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17311+
17312 /*
17313 * kern_addr_valid() is (1) for FLATMEM and (0) for
17314 * SPARSEMEM and DISCONTIGMEM
17315diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17316index ed5903b..c7fe163 100644
17317--- a/arch/x86/include/asm/pgtable_32_types.h
17318+++ b/arch/x86/include/asm/pgtable_32_types.h
17319@@ -8,7 +8,7 @@
17320 */
17321 #ifdef CONFIG_X86_PAE
17322 # include <asm/pgtable-3level_types.h>
17323-# define PMD_SIZE (1UL << PMD_SHIFT)
17324+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17325 # define PMD_MASK (~(PMD_SIZE - 1))
17326 #else
17327 # include <asm/pgtable-2level_types.h>
17328@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17329 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17330 #endif
17331
17332+#ifdef CONFIG_PAX_KERNEXEC
17333+#ifndef __ASSEMBLY__
17334+extern unsigned char MODULES_EXEC_VADDR[];
17335+extern unsigned char MODULES_EXEC_END[];
17336+#endif
17337+#include <asm/boot.h>
17338+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17339+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17340+#else
17341+#define ktla_ktva(addr) (addr)
17342+#define ktva_ktla(addr) (addr)
17343+#endif
17344+
17345 #define MODULES_VADDR VMALLOC_START
17346 #define MODULES_END VMALLOC_END
17347 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17348diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17349index e22c1db..23a625a 100644
17350--- a/arch/x86/include/asm/pgtable_64.h
17351+++ b/arch/x86/include/asm/pgtable_64.h
17352@@ -16,10 +16,14 @@
17353
17354 extern pud_t level3_kernel_pgt[512];
17355 extern pud_t level3_ident_pgt[512];
17356+extern pud_t level3_vmalloc_start_pgt[512];
17357+extern pud_t level3_vmalloc_end_pgt[512];
17358+extern pud_t level3_vmemmap_pgt[512];
17359+extern pud_t level2_vmemmap_pgt[512];
17360 extern pmd_t level2_kernel_pgt[512];
17361 extern pmd_t level2_fixmap_pgt[512];
17362-extern pmd_t level2_ident_pgt[512];
17363-extern pgd_t init_level4_pgt[];
17364+extern pmd_t level2_ident_pgt[512*2];
17365+extern pgd_t init_level4_pgt[512];
17366
17367 #define swapper_pg_dir init_level4_pgt
17368
17369@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17370
17371 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17372 {
17373+ pax_open_kernel();
17374 *pmdp = pmd;
17375+ pax_close_kernel();
17376 }
17377
17378 static inline void native_pmd_clear(pmd_t *pmd)
17379@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
17380
17381 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17382 {
17383+ pax_open_kernel();
17384 *pudp = pud;
17385+ pax_close_kernel();
17386 }
17387
17388 static inline void native_pud_clear(pud_t *pud)
17389@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
17390
17391 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
17392 {
17393+ pax_open_kernel();
17394+ *pgdp = pgd;
17395+ pax_close_kernel();
17396+}
17397+
17398+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17399+{
17400 *pgdp = pgd;
17401 }
17402
17403diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
17404index 2d88344..4679fc3 100644
17405--- a/arch/x86/include/asm/pgtable_64_types.h
17406+++ b/arch/x86/include/asm/pgtable_64_types.h
17407@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
17408 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
17409 #define MODULES_END _AC(0xffffffffff000000, UL)
17410 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
17411+#define MODULES_EXEC_VADDR MODULES_VADDR
17412+#define MODULES_EXEC_END MODULES_END
17413+
17414+#define ktla_ktva(addr) (addr)
17415+#define ktva_ktla(addr) (addr)
17416
17417 #define EARLY_DYNAMIC_PAGE_TABLES 64
17418
17419diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
17420index 0ecac25..7a15e09 100644
17421--- a/arch/x86/include/asm/pgtable_types.h
17422+++ b/arch/x86/include/asm/pgtable_types.h
17423@@ -16,13 +16,12 @@
17424 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
17425 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
17426 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
17427-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
17428+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
17429 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
17430 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
17431 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
17432-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
17433-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
17434-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
17435+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
17436+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
17437 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
17438
17439 /* If _PAGE_BIT_PRESENT is clear, we use these: */
17440@@ -40,7 +39,6 @@
17441 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
17442 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
17443 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
17444-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
17445 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
17446 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
17447 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
17448@@ -87,8 +85,10 @@
17449
17450 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
17451 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
17452-#else
17453+#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
17454 #define _PAGE_NX (_AT(pteval_t, 0))
17455+#else
17456+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
17457 #endif
17458
17459 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
17460@@ -146,6 +146,9 @@
17461 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
17462 _PAGE_ACCESSED)
17463
17464+#define PAGE_READONLY_NOEXEC PAGE_READONLY
17465+#define PAGE_SHARED_NOEXEC PAGE_SHARED
17466+
17467 #define __PAGE_KERNEL_EXEC \
17468 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
17469 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
17470@@ -156,7 +159,7 @@
17471 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
17472 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
17473 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
17474-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
17475+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
17476 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
17477 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
17478 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
17479@@ -218,8 +221,8 @@
17480 * bits are combined, this will alow user to access the high address mapped
17481 * VDSO in the presence of CONFIG_COMPAT_VDSO
17482 */
17483-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
17484-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
17485+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17486+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17487 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
17488 #endif
17489
17490@@ -257,7 +260,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
17491 {
17492 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
17493 }
17494+#endif
17495
17496+#if PAGETABLE_LEVELS == 3
17497+#include <asm-generic/pgtable-nopud.h>
17498+#endif
17499+
17500+#if PAGETABLE_LEVELS == 2
17501+#include <asm-generic/pgtable-nopmd.h>
17502+#endif
17503+
17504+#ifndef __ASSEMBLY__
17505 #if PAGETABLE_LEVELS > 3
17506 typedef struct { pudval_t pud; } pud_t;
17507
17508@@ -271,8 +284,6 @@ static inline pudval_t native_pud_val(pud_t pud)
17509 return pud.pud;
17510 }
17511 #else
17512-#include <asm-generic/pgtable-nopud.h>
17513-
17514 static inline pudval_t native_pud_val(pud_t pud)
17515 {
17516 return native_pgd_val(pud.pgd);
17517@@ -292,8 +303,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
17518 return pmd.pmd;
17519 }
17520 #else
17521-#include <asm-generic/pgtable-nopmd.h>
17522-
17523 static inline pmdval_t native_pmd_val(pmd_t pmd)
17524 {
17525 return native_pgd_val(pmd.pud.pgd);
17526@@ -333,7 +342,6 @@ typedef struct page *pgtable_t;
17527
17528 extern pteval_t __supported_pte_mask;
17529 extern void set_nx(void);
17530-extern int nx_enabled;
17531
17532 #define pgprot_writecombine pgprot_writecombine
17533 extern pgprot_t pgprot_writecombine(pgprot_t prot);
17534diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
17535index c8b0519..fd29e73 100644
17536--- a/arch/x86/include/asm/preempt.h
17537+++ b/arch/x86/include/asm/preempt.h
17538@@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
17539 */
17540 static __always_inline bool __preempt_count_dec_and_test(void)
17541 {
17542- GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
17543+ GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
17544 }
17545
17546 /*
17547diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
17548index 7b034a4..4fe3e3f 100644
17549--- a/arch/x86/include/asm/processor.h
17550+++ b/arch/x86/include/asm/processor.h
17551@@ -128,7 +128,7 @@ struct cpuinfo_x86 {
17552 /* Index into per_cpu list: */
17553 u16 cpu_index;
17554 u32 microcode;
17555-} __attribute__((__aligned__(SMP_CACHE_BYTES)));
17556+} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
17557
17558 #define X86_VENDOR_INTEL 0
17559 #define X86_VENDOR_CYRIX 1
17560@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
17561 : "memory");
17562 }
17563
17564+/* invpcid (%rdx),%rax */
17565+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
17566+
17567+#define INVPCID_SINGLE_ADDRESS 0UL
17568+#define INVPCID_SINGLE_CONTEXT 1UL
17569+#define INVPCID_ALL_GLOBAL 2UL
17570+#define INVPCID_ALL_MONGLOBAL 3UL
17571+
17572+#define PCID_KERNEL 0UL
17573+#define PCID_USER 1UL
17574+#define PCID_NOFLUSH (1UL << 63)
17575+
17576 static inline void load_cr3(pgd_t *pgdir)
17577 {
17578- write_cr3(__pa(pgdir));
17579+ write_cr3(__pa(pgdir) | PCID_KERNEL);
17580 }
17581
17582 #ifdef CONFIG_X86_32
17583@@ -283,7 +295,7 @@ struct tss_struct {
17584
17585 } ____cacheline_aligned;
17586
17587-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
17588+extern struct tss_struct init_tss[NR_CPUS];
17589
17590 /*
17591 * Save the original ist values for checking stack pointers during debugging
17592@@ -453,6 +465,7 @@ struct thread_struct {
17593 unsigned short ds;
17594 unsigned short fsindex;
17595 unsigned short gsindex;
17596+ unsigned short ss;
17597 #endif
17598 #ifdef CONFIG_X86_32
17599 unsigned long ip;
17600@@ -562,29 +575,8 @@ static inline void load_sp0(struct tss_struct *tss,
17601 extern unsigned long mmu_cr4_features;
17602 extern u32 *trampoline_cr4_features;
17603
17604-static inline void set_in_cr4(unsigned long mask)
17605-{
17606- unsigned long cr4;
17607-
17608- mmu_cr4_features |= mask;
17609- if (trampoline_cr4_features)
17610- *trampoline_cr4_features = mmu_cr4_features;
17611- cr4 = read_cr4();
17612- cr4 |= mask;
17613- write_cr4(cr4);
17614-}
17615-
17616-static inline void clear_in_cr4(unsigned long mask)
17617-{
17618- unsigned long cr4;
17619-
17620- mmu_cr4_features &= ~mask;
17621- if (trampoline_cr4_features)
17622- *trampoline_cr4_features = mmu_cr4_features;
17623- cr4 = read_cr4();
17624- cr4 &= ~mask;
17625- write_cr4(cr4);
17626-}
17627+extern void set_in_cr4(unsigned long mask);
17628+extern void clear_in_cr4(unsigned long mask);
17629
17630 typedef struct {
17631 unsigned long seg;
17632@@ -833,11 +825,18 @@ static inline void spin_lock_prefetch(const void *x)
17633 */
17634 #define TASK_SIZE PAGE_OFFSET
17635 #define TASK_SIZE_MAX TASK_SIZE
17636+
17637+#ifdef CONFIG_PAX_SEGMEXEC
17638+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
17639+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
17640+#else
17641 #define STACK_TOP TASK_SIZE
17642-#define STACK_TOP_MAX STACK_TOP
17643+#endif
17644+
17645+#define STACK_TOP_MAX TASK_SIZE
17646
17647 #define INIT_THREAD { \
17648- .sp0 = sizeof(init_stack) + (long)&init_stack, \
17649+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
17650 .vm86_info = NULL, \
17651 .sysenter_cs = __KERNEL_CS, \
17652 .io_bitmap_ptr = NULL, \
17653@@ -851,7 +850,7 @@ static inline void spin_lock_prefetch(const void *x)
17654 */
17655 #define INIT_TSS { \
17656 .x86_tss = { \
17657- .sp0 = sizeof(init_stack) + (long)&init_stack, \
17658+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
17659 .ss0 = __KERNEL_DS, \
17660 .ss1 = __KERNEL_CS, \
17661 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
17662@@ -862,11 +861,7 @@ static inline void spin_lock_prefetch(const void *x)
17663 extern unsigned long thread_saved_pc(struct task_struct *tsk);
17664
17665 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
17666-#define KSTK_TOP(info) \
17667-({ \
17668- unsigned long *__ptr = (unsigned long *)(info); \
17669- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
17670-})
17671+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
17672
17673 /*
17674 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
17675@@ -881,7 +876,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17676 #define task_pt_regs(task) \
17677 ({ \
17678 struct pt_regs *__regs__; \
17679- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
17680+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
17681 __regs__ - 1; \
17682 })
17683
17684@@ -891,13 +886,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17685 /*
17686 * User space process size. 47bits minus one guard page.
17687 */
17688-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
17689+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
17690
17691 /* This decides where the kernel will search for a free chunk of vm
17692 * space during mmap's.
17693 */
17694 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
17695- 0xc0000000 : 0xFFFFe000)
17696+ 0xc0000000 : 0xFFFFf000)
17697
17698 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
17699 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
17700@@ -908,11 +903,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17701 #define STACK_TOP_MAX TASK_SIZE_MAX
17702
17703 #define INIT_THREAD { \
17704- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
17705+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
17706 }
17707
17708 #define INIT_TSS { \
17709- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
17710+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
17711 }
17712
17713 /*
17714@@ -940,6 +935,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
17715 */
17716 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
17717
17718+#ifdef CONFIG_PAX_SEGMEXEC
17719+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
17720+#endif
17721+
17722 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
17723
17724 /* Get/set a process' ability to use the timestamp counter instruction */
17725@@ -966,7 +965,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
17726 return 0;
17727 }
17728
17729-extern unsigned long arch_align_stack(unsigned long sp);
17730+#define arch_align_stack(x) ((x) & ~0xfUL)
17731 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
17732
17733 void default_idle(void);
17734@@ -976,6 +975,6 @@ bool xen_set_default_idle(void);
17735 #define xen_set_default_idle 0
17736 #endif
17737
17738-void stop_this_cpu(void *dummy);
17739+void stop_this_cpu(void *dummy) __noreturn;
17740 void df_debug(struct pt_regs *regs, long error_code);
17741 #endif /* _ASM_X86_PROCESSOR_H */
17742diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
17743index 942a086..6c26446 100644
17744--- a/arch/x86/include/asm/ptrace.h
17745+++ b/arch/x86/include/asm/ptrace.h
17746@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
17747 }
17748
17749 /*
17750- * user_mode_vm(regs) determines whether a register set came from user mode.
17751+ * user_mode(regs) determines whether a register set came from user mode.
17752 * This is true if V8086 mode was enabled OR if the register set was from
17753 * protected mode with RPL-3 CS value. This tricky test checks that with
17754 * one comparison. Many places in the kernel can bypass this full check
17755- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
17756+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
17757+ * be used.
17758 */
17759-static inline int user_mode(struct pt_regs *regs)
17760+static inline int user_mode_novm(struct pt_regs *regs)
17761 {
17762 #ifdef CONFIG_X86_32
17763 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
17764 #else
17765- return !!(regs->cs & 3);
17766+ return !!(regs->cs & SEGMENT_RPL_MASK);
17767 #endif
17768 }
17769
17770-static inline int user_mode_vm(struct pt_regs *regs)
17771+static inline int user_mode(struct pt_regs *regs)
17772 {
17773 #ifdef CONFIG_X86_32
17774 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
17775 USER_RPL;
17776 #else
17777- return user_mode(regs);
17778+ return user_mode_novm(regs);
17779 #endif
17780 }
17781
17782@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
17783 #ifdef CONFIG_X86_64
17784 static inline bool user_64bit_mode(struct pt_regs *regs)
17785 {
17786+ unsigned long cs = regs->cs & 0xffff;
17787 #ifndef CONFIG_PARAVIRT
17788 /*
17789 * On non-paravirt systems, this is the only long mode CPL 3
17790 * selector. We do not allow long mode selectors in the LDT.
17791 */
17792- return regs->cs == __USER_CS;
17793+ return cs == __USER_CS;
17794 #else
17795 /* Headers are too twisted for this to go in paravirt.h. */
17796- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
17797+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
17798 #endif
17799 }
17800
17801@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
17802 * Traps from the kernel do not save sp and ss.
17803 * Use the helper function to retrieve sp.
17804 */
17805- if (offset == offsetof(struct pt_regs, sp) &&
17806- regs->cs == __KERNEL_CS)
17807- return kernel_stack_pointer(regs);
17808+ if (offset == offsetof(struct pt_regs, sp)) {
17809+ unsigned long cs = regs->cs & 0xffff;
17810+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
17811+ return kernel_stack_pointer(regs);
17812+ }
17813 #endif
17814 return *(unsigned long *)((unsigned long)regs + offset);
17815 }
17816diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
17817index 9c6b890..5305f53 100644
17818--- a/arch/x86/include/asm/realmode.h
17819+++ b/arch/x86/include/asm/realmode.h
17820@@ -22,16 +22,14 @@ struct real_mode_header {
17821 #endif
17822 /* APM/BIOS reboot */
17823 u32 machine_real_restart_asm;
17824-#ifdef CONFIG_X86_64
17825 u32 machine_real_restart_seg;
17826-#endif
17827 };
17828
17829 /* This must match data at trampoline_32/64.S */
17830 struct trampoline_header {
17831 #ifdef CONFIG_X86_32
17832 u32 start;
17833- u16 gdt_pad;
17834+ u16 boot_cs;
17835 u16 gdt_limit;
17836 u32 gdt_base;
17837 #else
17838diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
17839index a82c4f1..ac45053 100644
17840--- a/arch/x86/include/asm/reboot.h
17841+++ b/arch/x86/include/asm/reboot.h
17842@@ -6,13 +6,13 @@
17843 struct pt_regs;
17844
17845 struct machine_ops {
17846- void (*restart)(char *cmd);
17847- void (*halt)(void);
17848- void (*power_off)(void);
17849+ void (* __noreturn restart)(char *cmd);
17850+ void (* __noreturn halt)(void);
17851+ void (* __noreturn power_off)(void);
17852 void (*shutdown)(void);
17853 void (*crash_shutdown)(struct pt_regs *);
17854- void (*emergency_restart)(void);
17855-};
17856+ void (* __noreturn emergency_restart)(void);
17857+} __no_const;
17858
17859 extern struct machine_ops machine_ops;
17860
17861diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
17862index 8f7866a..e442f20 100644
17863--- a/arch/x86/include/asm/rmwcc.h
17864+++ b/arch/x86/include/asm/rmwcc.h
17865@@ -3,7 +3,34 @@
17866
17867 #ifdef CC_HAVE_ASM_GOTO
17868
17869-#define __GEN_RMWcc(fullop, var, cc, ...) \
17870+#ifdef CONFIG_PAX_REFCOUNT
17871+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
17872+do { \
17873+ asm_volatile_goto (fullop \
17874+ ";jno 0f\n" \
17875+ fullantiop \
17876+ ";int $4\n0:\n" \
17877+ _ASM_EXTABLE(0b, 0b) \
17878+ ";j" cc " %l[cc_label]" \
17879+ : : "m" (var), ## __VA_ARGS__ \
17880+ : "memory" : cc_label); \
17881+ return 0; \
17882+cc_label: \
17883+ return 1; \
17884+} while (0)
17885+#else
17886+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
17887+do { \
17888+ asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
17889+ : : "m" (var), ## __VA_ARGS__ \
17890+ : "memory" : cc_label); \
17891+ return 0; \
17892+cc_label: \
17893+ return 1; \
17894+} while (0)
17895+#endif
17896+
17897+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
17898 do { \
17899 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
17900 : : "m" (var), ## __VA_ARGS__ \
17901@@ -13,15 +40,46 @@ cc_label: \
17902 return 1; \
17903 } while (0)
17904
17905-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
17906- __GEN_RMWcc(op " " arg0, var, cc)
17907+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
17908+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
17909
17910-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
17911- __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
17912+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
17913+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
17914+
17915+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
17916+ __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
17917+
17918+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
17919+ __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
17920
17921 #else /* !CC_HAVE_ASM_GOTO */
17922
17923-#define __GEN_RMWcc(fullop, var, cc, ...) \
17924+#ifdef CONFIG_PAX_REFCOUNT
17925+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
17926+do { \
17927+ char c; \
17928+ asm volatile (fullop \
17929+ ";jno 0f\n" \
17930+ fullantiop \
17931+ ";int $4\n0:\n" \
17932+ _ASM_EXTABLE(0b, 0b) \
17933+ "; set" cc " %1" \
17934+ : "+m" (var), "=qm" (c) \
17935+ : __VA_ARGS__ : "memory"); \
17936+ return c != 0; \
17937+} while (0)
17938+#else
17939+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
17940+do { \
17941+ char c; \
17942+ asm volatile (fullop "; set" cc " %1" \
17943+ : "+m" (var), "=qm" (c) \
17944+ : __VA_ARGS__ : "memory"); \
17945+ return c != 0; \
17946+} while (0)
17947+#endif
17948+
17949+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
17950 do { \
17951 char c; \
17952 asm volatile (fullop "; set" cc " %1" \
17953@@ -30,11 +88,17 @@ do { \
17954 return c != 0; \
17955 } while (0)
17956
17957-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
17958- __GEN_RMWcc(op " " arg0, var, cc)
17959+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
17960+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
17961+
17962+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
17963+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
17964+
17965+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
17966+ __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
17967
17968-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
17969- __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
17970+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
17971+ __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
17972
17973 #endif /* CC_HAVE_ASM_GOTO */
17974
17975diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
17976index cad82c9..2e5c5c1 100644
17977--- a/arch/x86/include/asm/rwsem.h
17978+++ b/arch/x86/include/asm/rwsem.h
17979@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
17980 {
17981 asm volatile("# beginning down_read\n\t"
17982 LOCK_PREFIX _ASM_INC "(%1)\n\t"
17983+
17984+#ifdef CONFIG_PAX_REFCOUNT
17985+ "jno 0f\n"
17986+ LOCK_PREFIX _ASM_DEC "(%1)\n"
17987+ "int $4\n0:\n"
17988+ _ASM_EXTABLE(0b, 0b)
17989+#endif
17990+
17991 /* adds 0x00000001 */
17992 " jns 1f\n"
17993 " call call_rwsem_down_read_failed\n"
17994@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
17995 "1:\n\t"
17996 " mov %1,%2\n\t"
17997 " add %3,%2\n\t"
17998+
17999+#ifdef CONFIG_PAX_REFCOUNT
18000+ "jno 0f\n"
18001+ "sub %3,%2\n"
18002+ "int $4\n0:\n"
18003+ _ASM_EXTABLE(0b, 0b)
18004+#endif
18005+
18006 " jle 2f\n\t"
18007 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18008 " jnz 1b\n\t"
18009@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18010 long tmp;
18011 asm volatile("# beginning down_write\n\t"
18012 LOCK_PREFIX " xadd %1,(%2)\n\t"
18013+
18014+#ifdef CONFIG_PAX_REFCOUNT
18015+ "jno 0f\n"
18016+ "mov %1,(%2)\n"
18017+ "int $4\n0:\n"
18018+ _ASM_EXTABLE(0b, 0b)
18019+#endif
18020+
18021 /* adds 0xffff0001, returns the old value */
18022 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18023 /* was the active mask 0 before? */
18024@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18025 long tmp;
18026 asm volatile("# beginning __up_read\n\t"
18027 LOCK_PREFIX " xadd %1,(%2)\n\t"
18028+
18029+#ifdef CONFIG_PAX_REFCOUNT
18030+ "jno 0f\n"
18031+ "mov %1,(%2)\n"
18032+ "int $4\n0:\n"
18033+ _ASM_EXTABLE(0b, 0b)
18034+#endif
18035+
18036 /* subtracts 1, returns the old value */
18037 " jns 1f\n\t"
18038 " call call_rwsem_wake\n" /* expects old value in %edx */
18039@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18040 long tmp;
18041 asm volatile("# beginning __up_write\n\t"
18042 LOCK_PREFIX " xadd %1,(%2)\n\t"
18043+
18044+#ifdef CONFIG_PAX_REFCOUNT
18045+ "jno 0f\n"
18046+ "mov %1,(%2)\n"
18047+ "int $4\n0:\n"
18048+ _ASM_EXTABLE(0b, 0b)
18049+#endif
18050+
18051 /* subtracts 0xffff0001, returns the old value */
18052 " jns 1f\n\t"
18053 " call call_rwsem_wake\n" /* expects old value in %edx */
18054@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18055 {
18056 asm volatile("# beginning __downgrade_write\n\t"
18057 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18058+
18059+#ifdef CONFIG_PAX_REFCOUNT
18060+ "jno 0f\n"
18061+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18062+ "int $4\n0:\n"
18063+ _ASM_EXTABLE(0b, 0b)
18064+#endif
18065+
18066 /*
18067 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18068 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18069@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18070 */
18071 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18072 {
18073- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18074+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18075+
18076+#ifdef CONFIG_PAX_REFCOUNT
18077+ "jno 0f\n"
18078+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
18079+ "int $4\n0:\n"
18080+ _ASM_EXTABLE(0b, 0b)
18081+#endif
18082+
18083 : "+m" (sem->count)
18084 : "er" (delta));
18085 }
18086@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18087 */
18088 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18089 {
18090- return delta + xadd(&sem->count, delta);
18091+ return delta + xadd_check_overflow(&sem->count, delta);
18092 }
18093
18094 #endif /* __KERNEL__ */
18095diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18096index 6f1c3a8..7744f19 100644
18097--- a/arch/x86/include/asm/segment.h
18098+++ b/arch/x86/include/asm/segment.h
18099@@ -64,10 +64,15 @@
18100 * 26 - ESPFIX small SS
18101 * 27 - per-cpu [ offset to per-cpu data area ]
18102 * 28 - stack_canary-20 [ for stack protector ]
18103- * 29 - unused
18104- * 30 - unused
18105+ * 29 - PCI BIOS CS
18106+ * 30 - PCI BIOS DS
18107 * 31 - TSS for double fault handler
18108 */
18109+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18110+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18111+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18112+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18113+
18114 #define GDT_ENTRY_TLS_MIN 6
18115 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18116
18117@@ -79,6 +84,8 @@
18118
18119 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18120
18121+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18122+
18123 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18124
18125 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18126@@ -104,6 +111,12 @@
18127 #define __KERNEL_STACK_CANARY 0
18128 #endif
18129
18130+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18131+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18132+
18133+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18134+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18135+
18136 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18137
18138 /*
18139@@ -141,7 +154,7 @@
18140 */
18141
18142 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18143-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18144+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18145
18146
18147 #else
18148@@ -165,6 +178,8 @@
18149 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18150 #define __USER32_DS __USER_DS
18151
18152+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18153+
18154 #define GDT_ENTRY_TSS 8 /* needs two entries */
18155 #define GDT_ENTRY_LDT 10 /* needs two entries */
18156 #define GDT_ENTRY_TLS_MIN 12
18157@@ -173,6 +188,8 @@
18158 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18159 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18160
18161+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18162+
18163 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18164 #define FS_TLS 0
18165 #define GS_TLS 1
18166@@ -180,12 +197,14 @@
18167 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18168 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18169
18170-#define GDT_ENTRIES 16
18171+#define GDT_ENTRIES 17
18172
18173 #endif
18174
18175 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18176+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18177 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18178+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18179 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18180 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18181 #ifndef CONFIG_PARAVIRT
18182@@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18183 {
18184 unsigned long __limit;
18185 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18186- return __limit + 1;
18187+ return __limit;
18188 }
18189
18190 #endif /* !__ASSEMBLY__ */
18191diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18192index 8d3120f..352b440 100644
18193--- a/arch/x86/include/asm/smap.h
18194+++ b/arch/x86/include/asm/smap.h
18195@@ -25,11 +25,40 @@
18196
18197 #include <asm/alternative-asm.h>
18198
18199+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18200+#define ASM_PAX_OPEN_USERLAND \
18201+ 661: jmp 663f; \
18202+ .pushsection .altinstr_replacement, "a" ; \
18203+ 662: pushq %rax; nop; \
18204+ .popsection ; \
18205+ .pushsection .altinstructions, "a" ; \
18206+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18207+ .popsection ; \
18208+ call __pax_open_userland; \
18209+ popq %rax; \
18210+ 663:
18211+
18212+#define ASM_PAX_CLOSE_USERLAND \
18213+ 661: jmp 663f; \
18214+ .pushsection .altinstr_replacement, "a" ; \
18215+ 662: pushq %rax; nop; \
18216+ .popsection; \
18217+ .pushsection .altinstructions, "a" ; \
18218+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18219+ .popsection; \
18220+ call __pax_close_userland; \
18221+ popq %rax; \
18222+ 663:
18223+#else
18224+#define ASM_PAX_OPEN_USERLAND
18225+#define ASM_PAX_CLOSE_USERLAND
18226+#endif
18227+
18228 #ifdef CONFIG_X86_SMAP
18229
18230 #define ASM_CLAC \
18231 661: ASM_NOP3 ; \
18232- .pushsection .altinstr_replacement, "ax" ; \
18233+ .pushsection .altinstr_replacement, "a" ; \
18234 662: __ASM_CLAC ; \
18235 .popsection ; \
18236 .pushsection .altinstructions, "a" ; \
18237@@ -38,7 +67,7 @@
18238
18239 #define ASM_STAC \
18240 661: ASM_NOP3 ; \
18241- .pushsection .altinstr_replacement, "ax" ; \
18242+ .pushsection .altinstr_replacement, "a" ; \
18243 662: __ASM_STAC ; \
18244 .popsection ; \
18245 .pushsection .altinstructions, "a" ; \
18246@@ -56,6 +85,37 @@
18247
18248 #include <asm/alternative.h>
18249
18250+#define __HAVE_ARCH_PAX_OPEN_USERLAND
18251+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18252+
18253+extern void __pax_open_userland(void);
18254+static __always_inline unsigned long pax_open_userland(void)
18255+{
18256+
18257+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18258+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18259+ :
18260+ : [open] "i" (__pax_open_userland)
18261+ : "memory", "rax");
18262+#endif
18263+
18264+ return 0;
18265+}
18266+
18267+extern void __pax_close_userland(void);
18268+static __always_inline unsigned long pax_close_userland(void)
18269+{
18270+
18271+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18272+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18273+ :
18274+ : [close] "i" (__pax_close_userland)
18275+ : "memory", "rax");
18276+#endif
18277+
18278+ return 0;
18279+}
18280+
18281 #ifdef CONFIG_X86_SMAP
18282
18283 static __always_inline void clac(void)
18284diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18285index 4137890..03fa172 100644
18286--- a/arch/x86/include/asm/smp.h
18287+++ b/arch/x86/include/asm/smp.h
18288@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18289 /* cpus sharing the last level cache: */
18290 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18291 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18292-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18293+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18294
18295 static inline struct cpumask *cpu_sibling_mask(int cpu)
18296 {
18297@@ -79,7 +79,7 @@ struct smp_ops {
18298
18299 void (*send_call_func_ipi)(const struct cpumask *mask);
18300 void (*send_call_func_single_ipi)(int cpu);
18301-};
18302+} __no_const;
18303
18304 /* Globals due to paravirt */
18305 extern void set_cpu_sibling_map(int cpu);
18306@@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
18307 extern int safe_smp_processor_id(void);
18308
18309 #elif defined(CONFIG_X86_64_SMP)
18310-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18311-
18312-#define stack_smp_processor_id() \
18313-({ \
18314- struct thread_info *ti; \
18315- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18316- ti->cpu; \
18317-})
18318+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18319+#define stack_smp_processor_id() raw_smp_processor_id()
18320 #define safe_smp_processor_id() smp_processor_id()
18321
18322 #endif
18323diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18324index bf156de..1a782ab 100644
18325--- a/arch/x86/include/asm/spinlock.h
18326+++ b/arch/x86/include/asm/spinlock.h
18327@@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18328 static inline void arch_read_lock(arch_rwlock_t *rw)
18329 {
18330 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18331+
18332+#ifdef CONFIG_PAX_REFCOUNT
18333+ "jno 0f\n"
18334+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18335+ "int $4\n0:\n"
18336+ _ASM_EXTABLE(0b, 0b)
18337+#endif
18338+
18339 "jns 1f\n"
18340 "call __read_lock_failed\n\t"
18341 "1:\n"
18342@@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18343 static inline void arch_write_lock(arch_rwlock_t *rw)
18344 {
18345 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18346+
18347+#ifdef CONFIG_PAX_REFCOUNT
18348+ "jno 0f\n"
18349+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18350+ "int $4\n0:\n"
18351+ _ASM_EXTABLE(0b, 0b)
18352+#endif
18353+
18354 "jz 1f\n"
18355 "call __write_lock_failed\n\t"
18356 "1:\n"
18357@@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18358
18359 static inline void arch_read_unlock(arch_rwlock_t *rw)
18360 {
18361- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18362+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18363+
18364+#ifdef CONFIG_PAX_REFCOUNT
18365+ "jno 0f\n"
18366+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18367+ "int $4\n0:\n"
18368+ _ASM_EXTABLE(0b, 0b)
18369+#endif
18370+
18371 :"+m" (rw->lock) : : "memory");
18372 }
18373
18374 static inline void arch_write_unlock(arch_rwlock_t *rw)
18375 {
18376- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
18377+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
18378+
18379+#ifdef CONFIG_PAX_REFCOUNT
18380+ "jno 0f\n"
18381+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
18382+ "int $4\n0:\n"
18383+ _ASM_EXTABLE(0b, 0b)
18384+#endif
18385+
18386 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
18387 }
18388
18389diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
18390index 6a99859..03cb807 100644
18391--- a/arch/x86/include/asm/stackprotector.h
18392+++ b/arch/x86/include/asm/stackprotector.h
18393@@ -47,7 +47,7 @@
18394 * head_32 for boot CPU and setup_per_cpu_areas() for others.
18395 */
18396 #define GDT_STACK_CANARY_INIT \
18397- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
18398+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
18399
18400 /*
18401 * Initialize the stackprotector canary value.
18402@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
18403
18404 static inline void load_stack_canary_segment(void)
18405 {
18406-#ifdef CONFIG_X86_32
18407+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18408 asm volatile ("mov %0, %%gs" : : "r" (0));
18409 #endif
18410 }
18411diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
18412index 70bbe39..4ae2bd4 100644
18413--- a/arch/x86/include/asm/stacktrace.h
18414+++ b/arch/x86/include/asm/stacktrace.h
18415@@ -11,28 +11,20 @@
18416
18417 extern int kstack_depth_to_print;
18418
18419-struct thread_info;
18420+struct task_struct;
18421 struct stacktrace_ops;
18422
18423-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
18424- unsigned long *stack,
18425- unsigned long bp,
18426- const struct stacktrace_ops *ops,
18427- void *data,
18428- unsigned long *end,
18429- int *graph);
18430+typedef unsigned long walk_stack_t(struct task_struct *task,
18431+ void *stack_start,
18432+ unsigned long *stack,
18433+ unsigned long bp,
18434+ const struct stacktrace_ops *ops,
18435+ void *data,
18436+ unsigned long *end,
18437+ int *graph);
18438
18439-extern unsigned long
18440-print_context_stack(struct thread_info *tinfo,
18441- unsigned long *stack, unsigned long bp,
18442- const struct stacktrace_ops *ops, void *data,
18443- unsigned long *end, int *graph);
18444-
18445-extern unsigned long
18446-print_context_stack_bp(struct thread_info *tinfo,
18447- unsigned long *stack, unsigned long bp,
18448- const struct stacktrace_ops *ops, void *data,
18449- unsigned long *end, int *graph);
18450+extern walk_stack_t print_context_stack;
18451+extern walk_stack_t print_context_stack_bp;
18452
18453 /* Generic stack tracer with callbacks */
18454
18455@@ -40,7 +32,7 @@ struct stacktrace_ops {
18456 void (*address)(void *data, unsigned long address, int reliable);
18457 /* On negative return stop dumping */
18458 int (*stack)(void *data, char *name);
18459- walk_stack_t walk_stack;
18460+ walk_stack_t *walk_stack;
18461 };
18462
18463 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
18464diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
18465index d7f3b3b..3cc39f1 100644
18466--- a/arch/x86/include/asm/switch_to.h
18467+++ b/arch/x86/include/asm/switch_to.h
18468@@ -108,7 +108,7 @@ do { \
18469 "call __switch_to\n\t" \
18470 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
18471 __switch_canary \
18472- "movq %P[thread_info](%%rsi),%%r8\n\t" \
18473+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
18474 "movq %%rax,%%rdi\n\t" \
18475 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
18476 "jnz ret_from_fork\n\t" \
18477@@ -119,7 +119,7 @@ do { \
18478 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
18479 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
18480 [_tif_fork] "i" (_TIF_FORK), \
18481- [thread_info] "i" (offsetof(struct task_struct, stack)), \
18482+ [thread_info] "m" (current_tinfo), \
18483 [current_task] "m" (current_task) \
18484 __switch_canary_iparam \
18485 : "memory", "cc" __EXTRA_CLOBBER)
18486diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
18487index 3ba3de4..6c113b2 100644
18488--- a/arch/x86/include/asm/thread_info.h
18489+++ b/arch/x86/include/asm/thread_info.h
18490@@ -10,6 +10,7 @@
18491 #include <linux/compiler.h>
18492 #include <asm/page.h>
18493 #include <asm/types.h>
18494+#include <asm/percpu.h>
18495
18496 /*
18497 * low level task data that entry.S needs immediate access to
18498@@ -23,7 +24,6 @@ struct exec_domain;
18499 #include <linux/atomic.h>
18500
18501 struct thread_info {
18502- struct task_struct *task; /* main task structure */
18503 struct exec_domain *exec_domain; /* execution domain */
18504 __u32 flags; /* low level flags */
18505 __u32 status; /* thread synchronous flags */
18506@@ -32,19 +32,13 @@ struct thread_info {
18507 mm_segment_t addr_limit;
18508 struct restart_block restart_block;
18509 void __user *sysenter_return;
18510-#ifdef CONFIG_X86_32
18511- unsigned long previous_esp; /* ESP of the previous stack in
18512- case of nested (IRQ) stacks
18513- */
18514- __u8 supervisor_stack[0];
18515-#endif
18516+ unsigned long lowest_stack;
18517 unsigned int sig_on_uaccess_error:1;
18518 unsigned int uaccess_err:1; /* uaccess failed */
18519 };
18520
18521-#define INIT_THREAD_INFO(tsk) \
18522+#define INIT_THREAD_INFO \
18523 { \
18524- .task = &tsk, \
18525 .exec_domain = &default_exec_domain, \
18526 .flags = 0, \
18527 .cpu = 0, \
18528@@ -55,7 +49,7 @@ struct thread_info {
18529 }, \
18530 }
18531
18532-#define init_thread_info (init_thread_union.thread_info)
18533+#define init_thread_info (init_thread_union.stack)
18534 #define init_stack (init_thread_union.stack)
18535
18536 #else /* !__ASSEMBLY__ */
18537@@ -95,6 +89,7 @@ struct thread_info {
18538 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
18539 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
18540 #define TIF_X32 30 /* 32-bit native x86-64 binary */
18541+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
18542
18543 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
18544 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
18545@@ -118,17 +113,18 @@ struct thread_info {
18546 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
18547 #define _TIF_ADDR32 (1 << TIF_ADDR32)
18548 #define _TIF_X32 (1 << TIF_X32)
18549+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
18550
18551 /* work to do in syscall_trace_enter() */
18552 #define _TIF_WORK_SYSCALL_ENTRY \
18553 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
18554 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
18555- _TIF_NOHZ)
18556+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
18557
18558 /* work to do in syscall_trace_leave() */
18559 #define _TIF_WORK_SYSCALL_EXIT \
18560 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
18561- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
18562+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
18563
18564 /* work to do on interrupt/exception return */
18565 #define _TIF_WORK_MASK \
18566@@ -139,7 +135,7 @@ struct thread_info {
18567 /* work to do on any return to user space */
18568 #define _TIF_ALLWORK_MASK \
18569 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
18570- _TIF_NOHZ)
18571+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
18572
18573 /* Only used for 64 bit */
18574 #define _TIF_DO_NOTIFY_MASK \
18575@@ -153,45 +149,40 @@ struct thread_info {
18576 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
18577 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
18578
18579-#ifdef CONFIG_X86_32
18580-
18581-#define STACK_WARN (THREAD_SIZE/8)
18582-/*
18583- * macros/functions for gaining access to the thread information structure
18584- *
18585- * preempt_count needs to be 1 initially, until the scheduler is functional.
18586- */
18587-#ifndef __ASSEMBLY__
18588-
18589-
18590-/* how to get the current stack pointer from C */
18591-register unsigned long current_stack_pointer asm("esp") __used;
18592-
18593-/* how to get the thread information struct from C */
18594-static inline struct thread_info *current_thread_info(void)
18595-{
18596- return (struct thread_info *)
18597- (current_stack_pointer & ~(THREAD_SIZE - 1));
18598-}
18599-
18600-#else /* !__ASSEMBLY__ */
18601-
18602+#ifdef __ASSEMBLY__
18603 /* how to get the thread information struct from ASM */
18604 #define GET_THREAD_INFO(reg) \
18605- movl $-THREAD_SIZE, reg; \
18606- andl %esp, reg
18607+ mov PER_CPU_VAR(current_tinfo), reg
18608
18609 /* use this one if reg already contains %esp */
18610-#define GET_THREAD_INFO_WITH_ESP(reg) \
18611- andl $-THREAD_SIZE, reg
18612+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
18613+#else
18614+/* how to get the thread information struct from C */
18615+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
18616+
18617+static __always_inline struct thread_info *current_thread_info(void)
18618+{
18619+ return this_cpu_read_stable(current_tinfo);
18620+}
18621+#endif
18622+
18623+#ifdef CONFIG_X86_32
18624+
18625+#define STACK_WARN (THREAD_SIZE/8)
18626+/*
18627+ * macros/functions for gaining access to the thread information structure
18628+ *
18629+ * preempt_count needs to be 1 initially, until the scheduler is functional.
18630+ */
18631+#ifndef __ASSEMBLY__
18632+
18633+/* how to get the current stack pointer from C */
18634+register unsigned long current_stack_pointer asm("esp") __used;
18635
18636 #endif
18637
18638 #else /* X86_32 */
18639
18640-#include <asm/percpu.h>
18641-#define KERNEL_STACK_OFFSET (5*8)
18642-
18643 /*
18644 * macros/functions for gaining access to the thread information structure
18645 * preempt_count needs to be 1 initially, until the scheduler is functional.
18646@@ -199,27 +190,8 @@ static inline struct thread_info *current_thread_info(void)
18647 #ifndef __ASSEMBLY__
18648 DECLARE_PER_CPU(unsigned long, kernel_stack);
18649
18650-static inline struct thread_info *current_thread_info(void)
18651-{
18652- struct thread_info *ti;
18653- ti = (void *)(this_cpu_read_stable(kernel_stack) +
18654- KERNEL_STACK_OFFSET - THREAD_SIZE);
18655- return ti;
18656-}
18657-
18658-#else /* !__ASSEMBLY__ */
18659-
18660-/* how to get the thread information struct from ASM */
18661-#define GET_THREAD_INFO(reg) \
18662- movq PER_CPU_VAR(kernel_stack),reg ; \
18663- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
18664-
18665-/*
18666- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
18667- * a certain register (to be used in assembler memory operands).
18668- */
18669-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
18670-
18671+/* how to get the current stack pointer from C */
18672+register unsigned long current_stack_pointer asm("rsp") __used;
18673 #endif
18674
18675 #endif /* !X86_32 */
18676@@ -278,5 +250,12 @@ static inline bool is_ia32_task(void)
18677 extern void arch_task_cache_init(void);
18678 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
18679 extern void arch_release_task_struct(struct task_struct *tsk);
18680+
18681+#define __HAVE_THREAD_FUNCTIONS
18682+#define task_thread_info(task) (&(task)->tinfo)
18683+#define task_stack_page(task) ((task)->stack)
18684+#define setup_thread_stack(p, org) do {} while (0)
18685+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
18686+
18687 #endif
18688 #endif /* _ASM_X86_THREAD_INFO_H */
18689diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
18690index e6d90ba..f81f114 100644
18691--- a/arch/x86/include/asm/tlbflush.h
18692+++ b/arch/x86/include/asm/tlbflush.h
18693@@ -17,18 +17,44 @@
18694
18695 static inline void __native_flush_tlb(void)
18696 {
18697+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
18698+ u64 descriptor[2];
18699+
18700+ descriptor[0] = PCID_KERNEL;
18701+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
18702+ return;
18703+ }
18704+
18705+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18706+ if (static_cpu_has(X86_FEATURE_PCID)) {
18707+ unsigned int cpu = raw_get_cpu();
18708+
18709+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
18710+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
18711+ raw_put_cpu_no_resched();
18712+ return;
18713+ }
18714+#endif
18715+
18716 native_write_cr3(native_read_cr3());
18717 }
18718
18719 static inline void __native_flush_tlb_global_irq_disabled(void)
18720 {
18721- unsigned long cr4;
18722+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
18723+ u64 descriptor[2];
18724
18725- cr4 = native_read_cr4();
18726- /* clear PGE */
18727- native_write_cr4(cr4 & ~X86_CR4_PGE);
18728- /* write old PGE again and flush TLBs */
18729- native_write_cr4(cr4);
18730+ descriptor[0] = PCID_KERNEL;
18731+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
18732+ } else {
18733+ unsigned long cr4;
18734+
18735+ cr4 = native_read_cr4();
18736+ /* clear PGE */
18737+ native_write_cr4(cr4 & ~X86_CR4_PGE);
18738+ /* write old PGE again and flush TLBs */
18739+ native_write_cr4(cr4);
18740+ }
18741 }
18742
18743 static inline void __native_flush_tlb_global(void)
18744@@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
18745
18746 static inline void __native_flush_tlb_single(unsigned long addr)
18747 {
18748+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
18749+ u64 descriptor[2];
18750+
18751+ descriptor[0] = PCID_KERNEL;
18752+ descriptor[1] = addr;
18753+
18754+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18755+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
18756+ if (addr < TASK_SIZE_MAX)
18757+ descriptor[1] += pax_user_shadow_base;
18758+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
18759+ }
18760+
18761+ descriptor[0] = PCID_USER;
18762+ descriptor[1] = addr;
18763+#endif
18764+
18765+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
18766+ return;
18767+ }
18768+
18769+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18770+ if (static_cpu_has(X86_FEATURE_PCID)) {
18771+ unsigned int cpu = raw_get_cpu();
18772+
18773+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
18774+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
18775+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
18776+ raw_put_cpu_no_resched();
18777+
18778+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
18779+ addr += pax_user_shadow_base;
18780+ }
18781+#endif
18782+
18783 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
18784 }
18785
18786diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
18787index 8ec57c0..3ee58c9 100644
18788--- a/arch/x86/include/asm/uaccess.h
18789+++ b/arch/x86/include/asm/uaccess.h
18790@@ -7,6 +7,7 @@
18791 #include <linux/compiler.h>
18792 #include <linux/thread_info.h>
18793 #include <linux/string.h>
18794+#include <linux/spinlock.h>
18795 #include <asm/asm.h>
18796 #include <asm/page.h>
18797 #include <asm/smap.h>
18798@@ -29,7 +30,12 @@
18799
18800 #define get_ds() (KERNEL_DS)
18801 #define get_fs() (current_thread_info()->addr_limit)
18802+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18803+void __set_fs(mm_segment_t x);
18804+void set_fs(mm_segment_t x);
18805+#else
18806 #define set_fs(x) (current_thread_info()->addr_limit = (x))
18807+#endif
18808
18809 #define segment_eq(a, b) ((a).seg == (b).seg)
18810
18811@@ -77,8 +83,34 @@
18812 * checks that the pointer is in the user space range - after calling
18813 * this function, memory access functions may still return -EFAULT.
18814 */
18815-#define access_ok(type, addr, size) \
18816- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
18817+extern int _cond_resched(void);
18818+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
18819+#define access_ok(type, addr, size) \
18820+({ \
18821+ long __size = size; \
18822+ unsigned long __addr = (unsigned long)addr; \
18823+ unsigned long __addr_ao = __addr & PAGE_MASK; \
18824+ unsigned long __end_ao = __addr + __size - 1; \
18825+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
18826+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
18827+ while(__addr_ao <= __end_ao) { \
18828+ char __c_ao; \
18829+ __addr_ao += PAGE_SIZE; \
18830+ if (__size > PAGE_SIZE) \
18831+ _cond_resched(); \
18832+ if (__get_user(__c_ao, (char __user *)__addr)) \
18833+ break; \
18834+ if (type != VERIFY_WRITE) { \
18835+ __addr = __addr_ao; \
18836+ continue; \
18837+ } \
18838+ if (__put_user(__c_ao, (char __user *)__addr)) \
18839+ break; \
18840+ __addr = __addr_ao; \
18841+ } \
18842+ } \
18843+ __ret_ao; \
18844+})
18845
18846 /*
18847 * The exception table consists of pairs of addresses relative to the
18848@@ -168,10 +200,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18849 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
18850 __chk_user_ptr(ptr); \
18851 might_fault(); \
18852+ pax_open_userland(); \
18853 asm volatile("call __get_user_%P3" \
18854 : "=a" (__ret_gu), "=r" (__val_gu) \
18855 : "0" (ptr), "i" (sizeof(*(ptr)))); \
18856 (x) = (__typeof__(*(ptr))) __val_gu; \
18857+ pax_close_userland(); \
18858 __ret_gu; \
18859 })
18860
18861@@ -179,13 +213,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18862 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
18863 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
18864
18865-
18866+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18867+#define __copyuser_seg "gs;"
18868+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
18869+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
18870+#else
18871+#define __copyuser_seg
18872+#define __COPYUSER_SET_ES
18873+#define __COPYUSER_RESTORE_ES
18874+#endif
18875
18876 #ifdef CONFIG_X86_32
18877 #define __put_user_asm_u64(x, addr, err, errret) \
18878 asm volatile(ASM_STAC "\n" \
18879- "1: movl %%eax,0(%2)\n" \
18880- "2: movl %%edx,4(%2)\n" \
18881+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
18882+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
18883 "3: " ASM_CLAC "\n" \
18884 ".section .fixup,\"ax\"\n" \
18885 "4: movl %3,%0\n" \
18886@@ -198,8 +240,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18887
18888 #define __put_user_asm_ex_u64(x, addr) \
18889 asm volatile(ASM_STAC "\n" \
18890- "1: movl %%eax,0(%1)\n" \
18891- "2: movl %%edx,4(%1)\n" \
18892+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
18893+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
18894 "3: " ASM_CLAC "\n" \
18895 _ASM_EXTABLE_EX(1b, 2b) \
18896 _ASM_EXTABLE_EX(2b, 3b) \
18897@@ -249,7 +291,8 @@ extern void __put_user_8(void);
18898 __typeof__(*(ptr)) __pu_val; \
18899 __chk_user_ptr(ptr); \
18900 might_fault(); \
18901- __pu_val = x; \
18902+ __pu_val = (x); \
18903+ pax_open_userland(); \
18904 switch (sizeof(*(ptr))) { \
18905 case 1: \
18906 __put_user_x(1, __pu_val, ptr, __ret_pu); \
18907@@ -267,6 +310,7 @@ extern void __put_user_8(void);
18908 __put_user_x(X, __pu_val, ptr, __ret_pu); \
18909 break; \
18910 } \
18911+ pax_close_userland(); \
18912 __ret_pu; \
18913 })
18914
18915@@ -347,8 +391,10 @@ do { \
18916 } while (0)
18917
18918 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18919+do { \
18920+ pax_open_userland(); \
18921 asm volatile(ASM_STAC "\n" \
18922- "1: mov"itype" %2,%"rtype"1\n" \
18923+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
18924 "2: " ASM_CLAC "\n" \
18925 ".section .fixup,\"ax\"\n" \
18926 "3: mov %3,%0\n" \
18927@@ -356,8 +402,10 @@ do { \
18928 " jmp 2b\n" \
18929 ".previous\n" \
18930 _ASM_EXTABLE(1b, 3b) \
18931- : "=r" (err), ltype(x) \
18932- : "m" (__m(addr)), "i" (errret), "0" (err))
18933+ : "=r" (err), ltype (x) \
18934+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
18935+ pax_close_userland(); \
18936+} while (0)
18937
18938 #define __get_user_size_ex(x, ptr, size) \
18939 do { \
18940@@ -381,7 +429,7 @@ do { \
18941 } while (0)
18942
18943 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
18944- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
18945+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
18946 "2:\n" \
18947 _ASM_EXTABLE_EX(1b, 2b) \
18948 : ltype(x) : "m" (__m(addr)))
18949@@ -398,13 +446,24 @@ do { \
18950 int __gu_err; \
18951 unsigned long __gu_val; \
18952 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
18953- (x) = (__force __typeof__(*(ptr)))__gu_val; \
18954+ (x) = (__typeof__(*(ptr)))__gu_val; \
18955 __gu_err; \
18956 })
18957
18958 /* FIXME: this hack is definitely wrong -AK */
18959 struct __large_struct { unsigned long buf[100]; };
18960-#define __m(x) (*(struct __large_struct __user *)(x))
18961+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18962+#define ____m(x) \
18963+({ \
18964+ unsigned long ____x = (unsigned long)(x); \
18965+ if (____x < pax_user_shadow_base) \
18966+ ____x += pax_user_shadow_base; \
18967+ (typeof(x))____x; \
18968+})
18969+#else
18970+#define ____m(x) (x)
18971+#endif
18972+#define __m(x) (*(struct __large_struct __user *)____m(x))
18973
18974 /*
18975 * Tell gcc we read from memory instead of writing: this is because
18976@@ -412,8 +471,10 @@ struct __large_struct { unsigned long buf[100]; };
18977 * aliasing issues.
18978 */
18979 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18980+do { \
18981+ pax_open_userland(); \
18982 asm volatile(ASM_STAC "\n" \
18983- "1: mov"itype" %"rtype"1,%2\n" \
18984+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
18985 "2: " ASM_CLAC "\n" \
18986 ".section .fixup,\"ax\"\n" \
18987 "3: mov %3,%0\n" \
18988@@ -421,10 +482,12 @@ struct __large_struct { unsigned long buf[100]; };
18989 ".previous\n" \
18990 _ASM_EXTABLE(1b, 3b) \
18991 : "=r"(err) \
18992- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
18993+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
18994+ pax_close_userland(); \
18995+} while (0)
18996
18997 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
18998- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
18999+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19000 "2:\n" \
19001 _ASM_EXTABLE_EX(1b, 2b) \
19002 : : ltype(x), "m" (__m(addr)))
19003@@ -434,11 +497,13 @@ struct __large_struct { unsigned long buf[100]; };
19004 */
19005 #define uaccess_try do { \
19006 current_thread_info()->uaccess_err = 0; \
19007+ pax_open_userland(); \
19008 stac(); \
19009 barrier();
19010
19011 #define uaccess_catch(err) \
19012 clac(); \
19013+ pax_close_userland(); \
19014 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19015 } while (0)
19016
19017@@ -463,8 +528,12 @@ struct __large_struct { unsigned long buf[100]; };
19018 * On error, the variable @x is set to zero.
19019 */
19020
19021+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19022+#define __get_user(x, ptr) get_user((x), (ptr))
19023+#else
19024 #define __get_user(x, ptr) \
19025 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19026+#endif
19027
19028 /**
19029 * __put_user: - Write a simple value into user space, with less checking.
19030@@ -486,8 +555,12 @@ struct __large_struct { unsigned long buf[100]; };
19031 * Returns zero on success, or -EFAULT on error.
19032 */
19033
19034+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19035+#define __put_user(x, ptr) put_user((x), (ptr))
19036+#else
19037 #define __put_user(x, ptr) \
19038 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19039+#endif
19040
19041 #define __get_user_unaligned __get_user
19042 #define __put_user_unaligned __put_user
19043@@ -505,7 +578,7 @@ struct __large_struct { unsigned long buf[100]; };
19044 #define get_user_ex(x, ptr) do { \
19045 unsigned long __gue_val; \
19046 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19047- (x) = (__force __typeof__(*(ptr)))__gue_val; \
19048+ (x) = (__typeof__(*(ptr)))__gue_val; \
19049 } while (0)
19050
19051 #define put_user_try uaccess_try
19052@@ -536,17 +609,6 @@ extern struct movsl_mask {
19053
19054 #define ARCH_HAS_NOCACHE_UACCESS 1
19055
19056-#ifdef CONFIG_X86_32
19057-# include <asm/uaccess_32.h>
19058-#else
19059-# include <asm/uaccess_64.h>
19060-#endif
19061-
19062-unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19063- unsigned n);
19064-unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19065- unsigned n);
19066-
19067 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19068 # define copy_user_diag __compiletime_error
19069 #else
19070@@ -556,7 +618,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19071 extern void copy_user_diag("copy_from_user() buffer size is too small")
19072 copy_from_user_overflow(void);
19073 extern void copy_user_diag("copy_to_user() buffer size is too small")
19074-copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19075+copy_to_user_overflow(void);
19076
19077 #undef copy_user_diag
19078
19079@@ -569,7 +631,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19080
19081 extern void
19082 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19083-__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19084+__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19085 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19086
19087 #else
19088@@ -584,10 +646,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19089
19090 #endif
19091
19092+#ifdef CONFIG_X86_32
19093+# include <asm/uaccess_32.h>
19094+#else
19095+# include <asm/uaccess_64.h>
19096+#endif
19097+
19098 static inline unsigned long __must_check
19099 copy_from_user(void *to, const void __user *from, unsigned long n)
19100 {
19101- int sz = __compiletime_object_size(to);
19102+ size_t sz = __compiletime_object_size(to);
19103
19104 might_fault();
19105
19106@@ -609,12 +677,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19107 * case, and do only runtime checking for non-constant sizes.
19108 */
19109
19110- if (likely(sz < 0 || sz >= n))
19111- n = _copy_from_user(to, from, n);
19112- else if(__builtin_constant_p(n))
19113- copy_from_user_overflow();
19114- else
19115- __copy_from_user_overflow(sz, n);
19116+ if (likely(sz != (size_t)-1 && sz < n)) {
19117+ if(__builtin_constant_p(n))
19118+ copy_from_user_overflow();
19119+ else
19120+ __copy_from_user_overflow(sz, n);
19121+ } if (access_ok(VERIFY_READ, from, n))
19122+ n = __copy_from_user(to, from, n);
19123+ else if ((long)n > 0)
19124+ memset(to, 0, n);
19125
19126 return n;
19127 }
19128@@ -622,17 +693,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19129 static inline unsigned long __must_check
19130 copy_to_user(void __user *to, const void *from, unsigned long n)
19131 {
19132- int sz = __compiletime_object_size(from);
19133+ size_t sz = __compiletime_object_size(from);
19134
19135 might_fault();
19136
19137 /* See the comment in copy_from_user() above. */
19138- if (likely(sz < 0 || sz >= n))
19139- n = _copy_to_user(to, from, n);
19140- else if(__builtin_constant_p(n))
19141- copy_to_user_overflow();
19142- else
19143- __copy_to_user_overflow(sz, n);
19144+ if (likely(sz != (size_t)-1 && sz < n)) {
19145+ if(__builtin_constant_p(n))
19146+ copy_to_user_overflow();
19147+ else
19148+ __copy_to_user_overflow(sz, n);
19149+ } else if (access_ok(VERIFY_WRITE, to, n))
19150+ n = __copy_to_user(to, from, n);
19151
19152 return n;
19153 }
19154diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19155index 3c03a5d..1071638 100644
19156--- a/arch/x86/include/asm/uaccess_32.h
19157+++ b/arch/x86/include/asm/uaccess_32.h
19158@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19159 static __always_inline unsigned long __must_check
19160 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19161 {
19162+ if ((long)n < 0)
19163+ return n;
19164+
19165+ check_object_size(from, n, true);
19166+
19167 if (__builtin_constant_p(n)) {
19168 unsigned long ret;
19169
19170@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19171 __copy_to_user(void __user *to, const void *from, unsigned long n)
19172 {
19173 might_fault();
19174+
19175 return __copy_to_user_inatomic(to, from, n);
19176 }
19177
19178 static __always_inline unsigned long
19179 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19180 {
19181+ if ((long)n < 0)
19182+ return n;
19183+
19184 /* Avoid zeroing the tail if the copy fails..
19185 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19186 * but as the zeroing behaviour is only significant when n is not
19187@@ -137,6 +146,12 @@ static __always_inline unsigned long
19188 __copy_from_user(void *to, const void __user *from, unsigned long n)
19189 {
19190 might_fault();
19191+
19192+ if ((long)n < 0)
19193+ return n;
19194+
19195+ check_object_size(to, n, false);
19196+
19197 if (__builtin_constant_p(n)) {
19198 unsigned long ret;
19199
19200@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19201 const void __user *from, unsigned long n)
19202 {
19203 might_fault();
19204+
19205+ if ((long)n < 0)
19206+ return n;
19207+
19208 if (__builtin_constant_p(n)) {
19209 unsigned long ret;
19210
19211@@ -181,7 +200,10 @@ static __always_inline unsigned long
19212 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19213 unsigned long n)
19214 {
19215- return __copy_from_user_ll_nocache_nozero(to, from, n);
19216+ if ((long)n < 0)
19217+ return n;
19218+
19219+ return __copy_from_user_ll_nocache_nozero(to, from, n);
19220 }
19221
19222 #endif /* _ASM_X86_UACCESS_32_H */
19223diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19224index 190413d..8a80c2a 100644
19225--- a/arch/x86/include/asm/uaccess_64.h
19226+++ b/arch/x86/include/asm/uaccess_64.h
19227@@ -10,6 +10,9 @@
19228 #include <asm/alternative.h>
19229 #include <asm/cpufeature.h>
19230 #include <asm/page.h>
19231+#include <asm/pgtable.h>
19232+
19233+#define set_fs(x) (current_thread_info()->addr_limit = (x))
19234
19235 /*
19236 * Copy To/From Userspace
19237@@ -17,14 +20,14 @@
19238
19239 /* Handles exceptions in both to and from, but doesn't do access_ok */
19240 __must_check unsigned long
19241-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19242+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19243 __must_check unsigned long
19244-copy_user_generic_string(void *to, const void *from, unsigned len);
19245+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19246 __must_check unsigned long
19247-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19248+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19249
19250 static __always_inline __must_check unsigned long
19251-copy_user_generic(void *to, const void *from, unsigned len)
19252+copy_user_generic(void *to, const void *from, unsigned long len)
19253 {
19254 unsigned ret;
19255
19256@@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19257 }
19258
19259 __must_check unsigned long
19260-copy_in_user(void __user *to, const void __user *from, unsigned len);
19261+copy_in_user(void __user *to, const void __user *from, unsigned long len);
19262
19263 static __always_inline __must_check
19264-int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19265+unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19266 {
19267- int ret = 0;
19268+ size_t sz = __compiletime_object_size(dst);
19269+ unsigned ret = 0;
19270+
19271+ if (size > INT_MAX)
19272+ return size;
19273+
19274+ check_object_size(dst, size, false);
19275+
19276+#ifdef CONFIG_PAX_MEMORY_UDEREF
19277+ if (!__access_ok(VERIFY_READ, src, size))
19278+ return size;
19279+#endif
19280+
19281+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19282+ if(__builtin_constant_p(size))
19283+ copy_from_user_overflow();
19284+ else
19285+ __copy_from_user_overflow(sz, size);
19286+ return size;
19287+ }
19288
19289 if (!__builtin_constant_p(size))
19290- return copy_user_generic(dst, (__force void *)src, size);
19291+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19292 switch (size) {
19293- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19294+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19295 ret, "b", "b", "=q", 1);
19296 return ret;
19297- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19298+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19299 ret, "w", "w", "=r", 2);
19300 return ret;
19301- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19302+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19303 ret, "l", "k", "=r", 4);
19304 return ret;
19305- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19306+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19307 ret, "q", "", "=r", 8);
19308 return ret;
19309 case 10:
19310- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19311+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19312 ret, "q", "", "=r", 10);
19313 if (unlikely(ret))
19314 return ret;
19315 __get_user_asm(*(u16 *)(8 + (char *)dst),
19316- (u16 __user *)(8 + (char __user *)src),
19317+ (const u16 __user *)(8 + (const char __user *)src),
19318 ret, "w", "w", "=r", 2);
19319 return ret;
19320 case 16:
19321- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19322+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19323 ret, "q", "", "=r", 16);
19324 if (unlikely(ret))
19325 return ret;
19326 __get_user_asm(*(u64 *)(8 + (char *)dst),
19327- (u64 __user *)(8 + (char __user *)src),
19328+ (const u64 __user *)(8 + (const char __user *)src),
19329 ret, "q", "", "=r", 8);
19330 return ret;
19331 default:
19332- return copy_user_generic(dst, (__force void *)src, size);
19333+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19334 }
19335 }
19336
19337 static __always_inline __must_check
19338-int __copy_from_user(void *dst, const void __user *src, unsigned size)
19339+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19340 {
19341 might_fault();
19342 return __copy_from_user_nocheck(dst, src, size);
19343 }
19344
19345 static __always_inline __must_check
19346-int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
19347+unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
19348 {
19349- int ret = 0;
19350+ size_t sz = __compiletime_object_size(src);
19351+ unsigned ret = 0;
19352+
19353+ if (size > INT_MAX)
19354+ return size;
19355+
19356+ check_object_size(src, size, true);
19357+
19358+#ifdef CONFIG_PAX_MEMORY_UDEREF
19359+ if (!__access_ok(VERIFY_WRITE, dst, size))
19360+ return size;
19361+#endif
19362+
19363+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19364+ if(__builtin_constant_p(size))
19365+ copy_to_user_overflow();
19366+ else
19367+ __copy_to_user_overflow(sz, size);
19368+ return size;
19369+ }
19370
19371 if (!__builtin_constant_p(size))
19372- return copy_user_generic((__force void *)dst, src, size);
19373+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19374 switch (size) {
19375- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
19376+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
19377 ret, "b", "b", "iq", 1);
19378 return ret;
19379- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
19380+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
19381 ret, "w", "w", "ir", 2);
19382 return ret;
19383- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
19384+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
19385 ret, "l", "k", "ir", 4);
19386 return ret;
19387- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
19388+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19389 ret, "q", "", "er", 8);
19390 return ret;
19391 case 10:
19392- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19393+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19394 ret, "q", "", "er", 10);
19395 if (unlikely(ret))
19396 return ret;
19397 asm("":::"memory");
19398- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
19399+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
19400 ret, "w", "w", "ir", 2);
19401 return ret;
19402 case 16:
19403- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19404+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19405 ret, "q", "", "er", 16);
19406 if (unlikely(ret))
19407 return ret;
19408 asm("":::"memory");
19409- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
19410+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
19411 ret, "q", "", "er", 8);
19412 return ret;
19413 default:
19414- return copy_user_generic((__force void *)dst, src, size);
19415+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19416 }
19417 }
19418
19419 static __always_inline __must_check
19420-int __copy_to_user(void __user *dst, const void *src, unsigned size)
19421+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
19422 {
19423 might_fault();
19424 return __copy_to_user_nocheck(dst, src, size);
19425 }
19426
19427 static __always_inline __must_check
19428-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19429+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19430 {
19431- int ret = 0;
19432+ unsigned ret = 0;
19433
19434 might_fault();
19435+
19436+ if (size > INT_MAX)
19437+ return size;
19438+
19439+#ifdef CONFIG_PAX_MEMORY_UDEREF
19440+ if (!__access_ok(VERIFY_READ, src, size))
19441+ return size;
19442+ if (!__access_ok(VERIFY_WRITE, dst, size))
19443+ return size;
19444+#endif
19445+
19446 if (!__builtin_constant_p(size))
19447- return copy_user_generic((__force void *)dst,
19448- (__force void *)src, size);
19449+ return copy_user_generic((__force_kernel void *)____m(dst),
19450+ (__force_kernel const void *)____m(src), size);
19451 switch (size) {
19452 case 1: {
19453 u8 tmp;
19454- __get_user_asm(tmp, (u8 __user *)src,
19455+ __get_user_asm(tmp, (const u8 __user *)src,
19456 ret, "b", "b", "=q", 1);
19457 if (likely(!ret))
19458 __put_user_asm(tmp, (u8 __user *)dst,
19459@@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19460 }
19461 case 2: {
19462 u16 tmp;
19463- __get_user_asm(tmp, (u16 __user *)src,
19464+ __get_user_asm(tmp, (const u16 __user *)src,
19465 ret, "w", "w", "=r", 2);
19466 if (likely(!ret))
19467 __put_user_asm(tmp, (u16 __user *)dst,
19468@@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19469
19470 case 4: {
19471 u32 tmp;
19472- __get_user_asm(tmp, (u32 __user *)src,
19473+ __get_user_asm(tmp, (const u32 __user *)src,
19474 ret, "l", "k", "=r", 4);
19475 if (likely(!ret))
19476 __put_user_asm(tmp, (u32 __user *)dst,
19477@@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19478 }
19479 case 8: {
19480 u64 tmp;
19481- __get_user_asm(tmp, (u64 __user *)src,
19482+ __get_user_asm(tmp, (const u64 __user *)src,
19483 ret, "q", "", "=r", 8);
19484 if (likely(!ret))
19485 __put_user_asm(tmp, (u64 __user *)dst,
19486@@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19487 return ret;
19488 }
19489 default:
19490- return copy_user_generic((__force void *)dst,
19491- (__force void *)src, size);
19492+ return copy_user_generic((__force_kernel void *)____m(dst),
19493+ (__force_kernel const void *)____m(src), size);
19494 }
19495 }
19496
19497-static __must_check __always_inline int
19498-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
19499+static __must_check __always_inline unsigned long
19500+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
19501 {
19502- return __copy_from_user_nocheck(dst, (__force const void *)src, size);
19503+ return __copy_from_user_nocheck(dst, src, size);
19504 }
19505
19506-static __must_check __always_inline int
19507-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
19508+static __must_check __always_inline unsigned long
19509+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
19510 {
19511- return __copy_to_user_nocheck((__force void *)dst, src, size);
19512+ return __copy_to_user_nocheck(dst, src, size);
19513 }
19514
19515-extern long __copy_user_nocache(void *dst, const void __user *src,
19516- unsigned size, int zerorest);
19517+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
19518+ unsigned long size, int zerorest);
19519
19520-static inline int
19521-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
19522+static inline unsigned long
19523+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
19524 {
19525 might_fault();
19526+
19527+ if (size > INT_MAX)
19528+ return size;
19529+
19530+#ifdef CONFIG_PAX_MEMORY_UDEREF
19531+ if (!__access_ok(VERIFY_READ, src, size))
19532+ return size;
19533+#endif
19534+
19535 return __copy_user_nocache(dst, src, size, 1);
19536 }
19537
19538-static inline int
19539+static inline unsigned long
19540 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
19541- unsigned size)
19542+ unsigned long size)
19543 {
19544+ if (size > INT_MAX)
19545+ return size;
19546+
19547+#ifdef CONFIG_PAX_MEMORY_UDEREF
19548+ if (!__access_ok(VERIFY_READ, src, size))
19549+ return size;
19550+#endif
19551+
19552 return __copy_user_nocache(dst, src, size, 0);
19553 }
19554
19555 unsigned long
19556-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
19557+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
19558
19559 #endif /* _ASM_X86_UACCESS_64_H */
19560diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
19561index 5b238981..77fdd78 100644
19562--- a/arch/x86/include/asm/word-at-a-time.h
19563+++ b/arch/x86/include/asm/word-at-a-time.h
19564@@ -11,7 +11,7 @@
19565 * and shift, for example.
19566 */
19567 struct word_at_a_time {
19568- const unsigned long one_bits, high_bits;
19569+ unsigned long one_bits, high_bits;
19570 };
19571
19572 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
19573diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
19574index 0f1be11..f7542bf 100644
19575--- a/arch/x86/include/asm/x86_init.h
19576+++ b/arch/x86/include/asm/x86_init.h
19577@@ -129,7 +129,7 @@ struct x86_init_ops {
19578 struct x86_init_timers timers;
19579 struct x86_init_iommu iommu;
19580 struct x86_init_pci pci;
19581-};
19582+} __no_const;
19583
19584 /**
19585 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
19586@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
19587 void (*setup_percpu_clockev)(void);
19588 void (*early_percpu_clock_init)(void);
19589 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
19590-};
19591+} __no_const;
19592
19593 struct timespec;
19594
19595@@ -168,7 +168,7 @@ struct x86_platform_ops {
19596 void (*save_sched_clock_state)(void);
19597 void (*restore_sched_clock_state)(void);
19598 void (*apic_post_init)(void);
19599-};
19600+} __no_const;
19601
19602 struct pci_dev;
19603 struct msi_msg;
19604@@ -185,7 +185,7 @@ struct x86_msi_ops {
19605 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
19606 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
19607 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
19608-};
19609+} __no_const;
19610
19611 struct IO_APIC_route_entry;
19612 struct io_apic_irq_attr;
19613@@ -206,7 +206,7 @@ struct x86_io_apic_ops {
19614 unsigned int destination, int vector,
19615 struct io_apic_irq_attr *attr);
19616 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
19617-};
19618+} __no_const;
19619
19620 extern struct x86_init_ops x86_init;
19621 extern struct x86_cpuinit_ops x86_cpuinit;
19622diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
19623index b913915..4f5a581 100644
19624--- a/arch/x86/include/asm/xen/page.h
19625+++ b/arch/x86/include/asm/xen/page.h
19626@@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
19627 extern struct page *m2p_find_override(unsigned long mfn);
19628 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
19629
19630-static inline unsigned long pfn_to_mfn(unsigned long pfn)
19631+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
19632 {
19633 unsigned long mfn;
19634
19635diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
19636index 0415cda..3b22adc 100644
19637--- a/arch/x86/include/asm/xsave.h
19638+++ b/arch/x86/include/asm/xsave.h
19639@@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
19640 if (unlikely(err))
19641 return -EFAULT;
19642
19643+ pax_open_userland();
19644 __asm__ __volatile__(ASM_STAC "\n"
19645- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
19646+ "1:"
19647+ __copyuser_seg
19648+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
19649 "2: " ASM_CLAC "\n"
19650 ".section .fixup,\"ax\"\n"
19651 "3: movl $-1,%[err]\n"
19652@@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
19653 : [err] "=r" (err)
19654 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
19655 : "memory");
19656+ pax_close_userland();
19657 return err;
19658 }
19659
19660 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
19661 {
19662 int err;
19663- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
19664+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
19665 u32 lmask = mask;
19666 u32 hmask = mask >> 32;
19667
19668+ pax_open_userland();
19669 __asm__ __volatile__(ASM_STAC "\n"
19670- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
19671+ "1:"
19672+ __copyuser_seg
19673+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
19674 "2: " ASM_CLAC "\n"
19675 ".section .fixup,\"ax\"\n"
19676 "3: movl $-1,%[err]\n"
19677@@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
19678 : [err] "=r" (err)
19679 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
19680 : "memory"); /* memory required? */
19681+ pax_close_userland();
19682 return err;
19683 }
19684
19685diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
19686index bbae024..e1528f9 100644
19687--- a/arch/x86/include/uapi/asm/e820.h
19688+++ b/arch/x86/include/uapi/asm/e820.h
19689@@ -63,7 +63,7 @@ struct e820map {
19690 #define ISA_START_ADDRESS 0xa0000
19691 #define ISA_END_ADDRESS 0x100000
19692
19693-#define BIOS_BEGIN 0x000a0000
19694+#define BIOS_BEGIN 0x000c0000
19695 #define BIOS_END 0x00100000
19696
19697 #define BIOS_ROM_BASE 0xffe00000
19698diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
19699index 7b0a55a..ad115bf 100644
19700--- a/arch/x86/include/uapi/asm/ptrace-abi.h
19701+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
19702@@ -49,7 +49,6 @@
19703 #define EFLAGS 144
19704 #define RSP 152
19705 #define SS 160
19706-#define ARGOFFSET R11
19707 #endif /* __ASSEMBLY__ */
19708
19709 /* top of stack page */
19710diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
19711index 9b0a34e..fc7e553 100644
19712--- a/arch/x86/kernel/Makefile
19713+++ b/arch/x86/kernel/Makefile
19714@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
19715 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
19716 obj-$(CONFIG_IRQ_WORK) += irq_work.o
19717 obj-y += probe_roms.o
19718-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
19719+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
19720 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
19721 obj-y += syscall_$(BITS).o
19722 obj-$(CONFIG_X86_64) += vsyscall_64.o
19723diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
19724index 6c0b43b..e67bb31 100644
19725--- a/arch/x86/kernel/acpi/boot.c
19726+++ b/arch/x86/kernel/acpi/boot.c
19727@@ -1315,7 +1315,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
19728 * If your system is blacklisted here, but you find that acpi=force
19729 * works for you, please contact linux-acpi@vger.kernel.org
19730 */
19731-static struct dmi_system_id __initdata acpi_dmi_table[] = {
19732+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
19733 /*
19734 * Boxes that need ACPI disabled
19735 */
19736@@ -1390,7 +1390,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
19737 };
19738
19739 /* second table for DMI checks that should run after early-quirks */
19740-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
19741+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
19742 /*
19743 * HP laptops which use a DSDT reporting as HP/SB400/10000,
19744 * which includes some code which overrides all temperature
19745diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
19746index 3a2ae4c..9db31d6 100644
19747--- a/arch/x86/kernel/acpi/sleep.c
19748+++ b/arch/x86/kernel/acpi/sleep.c
19749@@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
19750 #else /* CONFIG_64BIT */
19751 #ifdef CONFIG_SMP
19752 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
19753+
19754+ pax_open_kernel();
19755 early_gdt_descr.address =
19756 (unsigned long)get_cpu_gdt_table(smp_processor_id());
19757+ pax_close_kernel();
19758+
19759 initial_gs = per_cpu_offset(smp_processor_id());
19760 #endif
19761 initial_code = (unsigned long)wakeup_long64;
19762diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
19763index 665c6b7..eae4d56 100644
19764--- a/arch/x86/kernel/acpi/wakeup_32.S
19765+++ b/arch/x86/kernel/acpi/wakeup_32.S
19766@@ -29,13 +29,11 @@ wakeup_pmode_return:
19767 # and restore the stack ... but you need gdt for this to work
19768 movl saved_context_esp, %esp
19769
19770- movl %cs:saved_magic, %eax
19771- cmpl $0x12345678, %eax
19772+ cmpl $0x12345678, saved_magic
19773 jne bogus_magic
19774
19775 # jump to place where we left off
19776- movl saved_eip, %eax
19777- jmp *%eax
19778+ jmp *(saved_eip)
19779
19780 bogus_magic:
19781 jmp bogus_magic
19782diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
19783index df94598..f3b29bf 100644
19784--- a/arch/x86/kernel/alternative.c
19785+++ b/arch/x86/kernel/alternative.c
19786@@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
19787 */
19788 for (a = start; a < end; a++) {
19789 instr = (u8 *)&a->instr_offset + a->instr_offset;
19790+
19791+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19792+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19793+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
19794+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19795+#endif
19796+
19797 replacement = (u8 *)&a->repl_offset + a->repl_offset;
19798 BUG_ON(a->replacementlen > a->instrlen);
19799 BUG_ON(a->instrlen > sizeof(insnbuf));
19800@@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
19801 for (poff = start; poff < end; poff++) {
19802 u8 *ptr = (u8 *)poff + *poff;
19803
19804+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19805+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19806+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
19807+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19808+#endif
19809+
19810 if (!*poff || ptr < text || ptr >= text_end)
19811 continue;
19812 /* turn DS segment override prefix into lock prefix */
19813- if (*ptr == 0x3e)
19814+ if (*ktla_ktva(ptr) == 0x3e)
19815 text_poke(ptr, ((unsigned char []){0xf0}), 1);
19816 }
19817 mutex_unlock(&text_mutex);
19818@@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
19819 for (poff = start; poff < end; poff++) {
19820 u8 *ptr = (u8 *)poff + *poff;
19821
19822+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19823+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19824+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
19825+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19826+#endif
19827+
19828 if (!*poff || ptr < text || ptr >= text_end)
19829 continue;
19830 /* turn lock prefix into DS segment override prefix */
19831- if (*ptr == 0xf0)
19832+ if (*ktla_ktva(ptr) == 0xf0)
19833 text_poke(ptr, ((unsigned char []){0x3E}), 1);
19834 }
19835 mutex_unlock(&text_mutex);
19836@@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
19837
19838 BUG_ON(p->len > MAX_PATCH_LEN);
19839 /* prep the buffer with the original instructions */
19840- memcpy(insnbuf, p->instr, p->len);
19841+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
19842 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
19843 (unsigned long)p->instr, p->len);
19844
19845@@ -505,7 +524,7 @@ void __init alternative_instructions(void)
19846 if (!uniproc_patched || num_possible_cpus() == 1)
19847 free_init_pages("SMP alternatives",
19848 (unsigned long)__smp_locks,
19849- (unsigned long)__smp_locks_end);
19850+ PAGE_ALIGN((unsigned long)__smp_locks_end));
19851 #endif
19852
19853 apply_paravirt(__parainstructions, __parainstructions_end);
19854@@ -525,13 +544,17 @@ void __init alternative_instructions(void)
19855 * instructions. And on the local CPU you need to be protected again NMI or MCE
19856 * handlers seeing an inconsistent instruction while you patch.
19857 */
19858-void *__init_or_module text_poke_early(void *addr, const void *opcode,
19859+void *__kprobes text_poke_early(void *addr, const void *opcode,
19860 size_t len)
19861 {
19862 unsigned long flags;
19863 local_irq_save(flags);
19864- memcpy(addr, opcode, len);
19865+
19866+ pax_open_kernel();
19867+ memcpy(ktla_ktva(addr), opcode, len);
19868 sync_core();
19869+ pax_close_kernel();
19870+
19871 local_irq_restore(flags);
19872 /* Could also do a CLFLUSH here to speed up CPU recovery; but
19873 that causes hangs on some VIA CPUs. */
19874@@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
19875 */
19876 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
19877 {
19878- unsigned long flags;
19879- char *vaddr;
19880+ unsigned char *vaddr = ktla_ktva(addr);
19881 struct page *pages[2];
19882- int i;
19883+ size_t i;
19884
19885 if (!core_kernel_text((unsigned long)addr)) {
19886- pages[0] = vmalloc_to_page(addr);
19887- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
19888+ pages[0] = vmalloc_to_page(vaddr);
19889+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
19890 } else {
19891- pages[0] = virt_to_page(addr);
19892+ pages[0] = virt_to_page(vaddr);
19893 WARN_ON(!PageReserved(pages[0]));
19894- pages[1] = virt_to_page(addr + PAGE_SIZE);
19895+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
19896 }
19897 BUG_ON(!pages[0]);
19898- local_irq_save(flags);
19899- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
19900- if (pages[1])
19901- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
19902- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
19903- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
19904- clear_fixmap(FIX_TEXT_POKE0);
19905- if (pages[1])
19906- clear_fixmap(FIX_TEXT_POKE1);
19907- local_flush_tlb();
19908- sync_core();
19909- /* Could also do a CLFLUSH here to speed up CPU recovery; but
19910- that causes hangs on some VIA CPUs. */
19911+ text_poke_early(addr, opcode, len);
19912 for (i = 0; i < len; i++)
19913- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
19914- local_irq_restore(flags);
19915+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
19916 return addr;
19917 }
19918
19919@@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
19920 if (likely(!bp_patching_in_progress))
19921 return 0;
19922
19923- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
19924+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
19925 return 0;
19926
19927 /* set up the specified breakpoint handler */
19928@@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
19929 */
19930 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
19931 {
19932- unsigned char int3 = 0xcc;
19933+ const unsigned char int3 = 0xcc;
19934
19935 bp_int3_handler = handler;
19936 bp_int3_addr = (u8 *)addr + sizeof(int3);
19937diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
19938index d278736..0b4af9a8 100644
19939--- a/arch/x86/kernel/apic/apic.c
19940+++ b/arch/x86/kernel/apic/apic.c
19941@@ -191,7 +191,7 @@ int first_system_vector = 0xfe;
19942 /*
19943 * Debug level, exported for io_apic.c
19944 */
19945-unsigned int apic_verbosity;
19946+int apic_verbosity;
19947
19948 int pic_mode;
19949
19950@@ -1986,7 +1986,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
19951 apic_write(APIC_ESR, 0);
19952 v1 = apic_read(APIC_ESR);
19953 ack_APIC_irq();
19954- atomic_inc(&irq_err_count);
19955+ atomic_inc_unchecked(&irq_err_count);
19956
19957 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
19958 smp_processor_id(), v0 , v1);
19959diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
19960index 00c77cf..2dc6a2d 100644
19961--- a/arch/x86/kernel/apic/apic_flat_64.c
19962+++ b/arch/x86/kernel/apic/apic_flat_64.c
19963@@ -157,7 +157,7 @@ static int flat_probe(void)
19964 return 1;
19965 }
19966
19967-static struct apic apic_flat = {
19968+static struct apic apic_flat __read_only = {
19969 .name = "flat",
19970 .probe = flat_probe,
19971 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
19972@@ -271,7 +271,7 @@ static int physflat_probe(void)
19973 return 0;
19974 }
19975
19976-static struct apic apic_physflat = {
19977+static struct apic apic_physflat __read_only = {
19978
19979 .name = "physical flat",
19980 .probe = physflat_probe,
19981diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
19982index e145f28..2752888 100644
19983--- a/arch/x86/kernel/apic/apic_noop.c
19984+++ b/arch/x86/kernel/apic/apic_noop.c
19985@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
19986 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
19987 }
19988
19989-struct apic apic_noop = {
19990+struct apic apic_noop __read_only = {
19991 .name = "noop",
19992 .probe = noop_probe,
19993 .acpi_madt_oem_check = NULL,
19994diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
19995index d50e364..543bee3 100644
19996--- a/arch/x86/kernel/apic/bigsmp_32.c
19997+++ b/arch/x86/kernel/apic/bigsmp_32.c
19998@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
19999 return dmi_bigsmp;
20000 }
20001
20002-static struct apic apic_bigsmp = {
20003+static struct apic apic_bigsmp __read_only = {
20004
20005 .name = "bigsmp",
20006 .probe = probe_bigsmp,
20007diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
20008index c552247..587a316 100644
20009--- a/arch/x86/kernel/apic/es7000_32.c
20010+++ b/arch/x86/kernel/apic/es7000_32.c
20011@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
20012 return ret && es7000_apic_is_cluster();
20013 }
20014
20015-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
20016-static struct apic __refdata apic_es7000_cluster = {
20017+static struct apic apic_es7000_cluster __read_only = {
20018
20019 .name = "es7000",
20020 .probe = probe_es7000,
20021@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
20022 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
20023 };
20024
20025-static struct apic __refdata apic_es7000 = {
20026+static struct apic apic_es7000 __read_only = {
20027
20028 .name = "es7000",
20029 .probe = probe_es7000,
20030diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20031index e63a5bd..c0babf8 100644
20032--- a/arch/x86/kernel/apic/io_apic.c
20033+++ b/arch/x86/kernel/apic/io_apic.c
20034@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20035 }
20036 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20037
20038-void lock_vector_lock(void)
20039+void lock_vector_lock(void) __acquires(vector_lock)
20040 {
20041 /* Used to the online set of cpus does not change
20042 * during assign_irq_vector.
20043@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
20044 raw_spin_lock(&vector_lock);
20045 }
20046
20047-void unlock_vector_lock(void)
20048+void unlock_vector_lock(void) __releases(vector_lock)
20049 {
20050 raw_spin_unlock(&vector_lock);
20051 }
20052@@ -2367,7 +2367,7 @@ static void ack_apic_edge(struct irq_data *data)
20053 ack_APIC_irq();
20054 }
20055
20056-atomic_t irq_mis_count;
20057+atomic_unchecked_t irq_mis_count;
20058
20059 #ifdef CONFIG_GENERIC_PENDING_IRQ
20060 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20061@@ -2508,7 +2508,7 @@ static void ack_apic_level(struct irq_data *data)
20062 * at the cpu.
20063 */
20064 if (!(v & (1 << (i & 0x1f)))) {
20065- atomic_inc(&irq_mis_count);
20066+ atomic_inc_unchecked(&irq_mis_count);
20067
20068 eoi_ioapic_irq(irq, cfg);
20069 }
20070diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
20071index 1e42e8f..daacf44 100644
20072--- a/arch/x86/kernel/apic/numaq_32.c
20073+++ b/arch/x86/kernel/apic/numaq_32.c
20074@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
20075 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
20076 }
20077
20078-/* Use __refdata to keep false positive warning calm. */
20079-static struct apic __refdata apic_numaq = {
20080+static struct apic apic_numaq __read_only = {
20081
20082 .name = "NUMAQ",
20083 .probe = probe_numaq,
20084diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20085index eb35ef9..f184a21 100644
20086--- a/arch/x86/kernel/apic/probe_32.c
20087+++ b/arch/x86/kernel/apic/probe_32.c
20088@@ -72,7 +72,7 @@ static int probe_default(void)
20089 return 1;
20090 }
20091
20092-static struct apic apic_default = {
20093+static struct apic apic_default __read_only = {
20094
20095 .name = "default",
20096 .probe = probe_default,
20097diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
20098index 77c95c0..434f8a4 100644
20099--- a/arch/x86/kernel/apic/summit_32.c
20100+++ b/arch/x86/kernel/apic/summit_32.c
20101@@ -486,7 +486,7 @@ void setup_summit(void)
20102 }
20103 #endif
20104
20105-static struct apic apic_summit = {
20106+static struct apic apic_summit __read_only = {
20107
20108 .name = "summit",
20109 .probe = probe_summit,
20110diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20111index 140e29d..d88bc95 100644
20112--- a/arch/x86/kernel/apic/x2apic_cluster.c
20113+++ b/arch/x86/kernel/apic/x2apic_cluster.c
20114@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20115 return notifier_from_errno(err);
20116 }
20117
20118-static struct notifier_block __refdata x2apic_cpu_notifier = {
20119+static struct notifier_block x2apic_cpu_notifier = {
20120 .notifier_call = update_clusterinfo,
20121 };
20122
20123@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20124 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20125 }
20126
20127-static struct apic apic_x2apic_cluster = {
20128+static struct apic apic_x2apic_cluster __read_only = {
20129
20130 .name = "cluster x2apic",
20131 .probe = x2apic_cluster_probe,
20132diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20133index 562a76d..a003c0f 100644
20134--- a/arch/x86/kernel/apic/x2apic_phys.c
20135+++ b/arch/x86/kernel/apic/x2apic_phys.c
20136@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
20137 return apic == &apic_x2apic_phys;
20138 }
20139
20140-static struct apic apic_x2apic_phys = {
20141+static struct apic apic_x2apic_phys __read_only = {
20142
20143 .name = "physical x2apic",
20144 .probe = x2apic_phys_probe,
20145diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20146index ad0dc04..0d9cc56 100644
20147--- a/arch/x86/kernel/apic/x2apic_uv_x.c
20148+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20149@@ -350,7 +350,7 @@ static int uv_probe(void)
20150 return apic == &apic_x2apic_uv_x;
20151 }
20152
20153-static struct apic __refdata apic_x2apic_uv_x = {
20154+static struct apic apic_x2apic_uv_x __read_only = {
20155
20156 .name = "UV large system",
20157 .probe = uv_probe,
20158diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20159index 3ab0343..814c4787 100644
20160--- a/arch/x86/kernel/apm_32.c
20161+++ b/arch/x86/kernel/apm_32.c
20162@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20163 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20164 * even though they are called in protected mode.
20165 */
20166-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20167+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20168 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20169
20170 static const char driver_version[] = "1.16ac"; /* no spaces */
20171@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20172 BUG_ON(cpu != 0);
20173 gdt = get_cpu_gdt_table(cpu);
20174 save_desc_40 = gdt[0x40 / 8];
20175+
20176+ pax_open_kernel();
20177 gdt[0x40 / 8] = bad_bios_desc;
20178+ pax_close_kernel();
20179
20180 apm_irq_save(flags);
20181 APM_DO_SAVE_SEGS;
20182@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20183 &call->esi);
20184 APM_DO_RESTORE_SEGS;
20185 apm_irq_restore(flags);
20186+
20187+ pax_open_kernel();
20188 gdt[0x40 / 8] = save_desc_40;
20189+ pax_close_kernel();
20190+
20191 put_cpu();
20192
20193 return call->eax & 0xff;
20194@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20195 BUG_ON(cpu != 0);
20196 gdt = get_cpu_gdt_table(cpu);
20197 save_desc_40 = gdt[0x40 / 8];
20198+
20199+ pax_open_kernel();
20200 gdt[0x40 / 8] = bad_bios_desc;
20201+ pax_close_kernel();
20202
20203 apm_irq_save(flags);
20204 APM_DO_SAVE_SEGS;
20205@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20206 &call->eax);
20207 APM_DO_RESTORE_SEGS;
20208 apm_irq_restore(flags);
20209+
20210+ pax_open_kernel();
20211 gdt[0x40 / 8] = save_desc_40;
20212+ pax_close_kernel();
20213+
20214 put_cpu();
20215 return error;
20216 }
20217@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20218 * code to that CPU.
20219 */
20220 gdt = get_cpu_gdt_table(0);
20221+
20222+ pax_open_kernel();
20223 set_desc_base(&gdt[APM_CS >> 3],
20224 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20225 set_desc_base(&gdt[APM_CS_16 >> 3],
20226 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20227 set_desc_base(&gdt[APM_DS >> 3],
20228 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20229+ pax_close_kernel();
20230
20231 proc_create("apm", 0, NULL, &apm_file_ops);
20232
20233diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20234index 9f6b934..cf5ffb3 100644
20235--- a/arch/x86/kernel/asm-offsets.c
20236+++ b/arch/x86/kernel/asm-offsets.c
20237@@ -32,6 +32,8 @@ void common(void) {
20238 OFFSET(TI_flags, thread_info, flags);
20239 OFFSET(TI_status, thread_info, status);
20240 OFFSET(TI_addr_limit, thread_info, addr_limit);
20241+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20242+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20243
20244 BLANK();
20245 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20246@@ -52,8 +54,26 @@ void common(void) {
20247 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20248 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20249 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20250+
20251+#ifdef CONFIG_PAX_KERNEXEC
20252+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20253 #endif
20254
20255+#ifdef CONFIG_PAX_MEMORY_UDEREF
20256+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20257+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20258+#ifdef CONFIG_X86_64
20259+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20260+#endif
20261+#endif
20262+
20263+#endif
20264+
20265+ BLANK();
20266+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20267+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20268+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20269+
20270 #ifdef CONFIG_XEN
20271 BLANK();
20272 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20273diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20274index e7c798b..2b2019b 100644
20275--- a/arch/x86/kernel/asm-offsets_64.c
20276+++ b/arch/x86/kernel/asm-offsets_64.c
20277@@ -77,6 +77,7 @@ int main(void)
20278 BLANK();
20279 #undef ENTRY
20280
20281+ DEFINE(TSS_size, sizeof(struct tss_struct));
20282 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20283 BLANK();
20284
20285diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20286index 47b56a7..efc2bc6 100644
20287--- a/arch/x86/kernel/cpu/Makefile
20288+++ b/arch/x86/kernel/cpu/Makefile
20289@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20290 CFLAGS_REMOVE_perf_event.o = -pg
20291 endif
20292
20293-# Make sure load_percpu_segment has no stackprotector
20294-nostackp := $(call cc-option, -fno-stack-protector)
20295-CFLAGS_common.o := $(nostackp)
20296-
20297 obj-y := intel_cacheinfo.o scattered.o topology.o
20298 obj-y += proc.o capflags.o powerflags.o common.o
20299 obj-y += rdrand.o
20300diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20301index 59bfebc..d8f27bd 100644
20302--- a/arch/x86/kernel/cpu/amd.c
20303+++ b/arch/x86/kernel/cpu/amd.c
20304@@ -753,7 +753,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20305 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20306 {
20307 /* AMD errata T13 (order #21922) */
20308- if ((c->x86 == 6)) {
20309+ if (c->x86 == 6) {
20310 /* Duron Rev A0 */
20311 if (c->x86_model == 3 && c->x86_mask == 0)
20312 size = 64;
20313diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20314index 6abc172..3b0df94 100644
20315--- a/arch/x86/kernel/cpu/common.c
20316+++ b/arch/x86/kernel/cpu/common.c
20317@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20318
20319 static const struct cpu_dev *this_cpu = &default_cpu;
20320
20321-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20322-#ifdef CONFIG_X86_64
20323- /*
20324- * We need valid kernel segments for data and code in long mode too
20325- * IRET will check the segment types kkeil 2000/10/28
20326- * Also sysret mandates a special GDT layout
20327- *
20328- * TLS descriptors are currently at a different place compared to i386.
20329- * Hopefully nobody expects them at a fixed place (Wine?)
20330- */
20331- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20332- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20333- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20334- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20335- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20336- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20337-#else
20338- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20339- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20340- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20341- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20342- /*
20343- * Segments used for calling PnP BIOS have byte granularity.
20344- * They code segments and data segments have fixed 64k limits,
20345- * the transfer segment sizes are set at run time.
20346- */
20347- /* 32-bit code */
20348- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20349- /* 16-bit code */
20350- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20351- /* 16-bit data */
20352- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20353- /* 16-bit data */
20354- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20355- /* 16-bit data */
20356- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20357- /*
20358- * The APM segments have byte granularity and their bases
20359- * are set at run time. All have 64k limits.
20360- */
20361- /* 32-bit code */
20362- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20363- /* 16-bit code */
20364- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20365- /* data */
20366- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20367-
20368- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20369- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20370- GDT_STACK_CANARY_INIT
20371-#endif
20372-} };
20373-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20374-
20375 static int __init x86_xsave_setup(char *s)
20376 {
20377 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20378@@ -288,6 +234,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20379 set_in_cr4(X86_CR4_SMAP);
20380 }
20381
20382+#ifdef CONFIG_X86_64
20383+static __init int setup_disable_pcid(char *arg)
20384+{
20385+ setup_clear_cpu_cap(X86_FEATURE_PCID);
20386+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20387+
20388+#ifdef CONFIG_PAX_MEMORY_UDEREF
20389+ if (clone_pgd_mask != ~(pgdval_t)0UL)
20390+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20391+#endif
20392+
20393+ return 1;
20394+}
20395+__setup("nopcid", setup_disable_pcid);
20396+
20397+static void setup_pcid(struct cpuinfo_x86 *c)
20398+{
20399+ if (!cpu_has(c, X86_FEATURE_PCID)) {
20400+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
20401+
20402+#ifdef CONFIG_PAX_MEMORY_UDEREF
20403+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
20404+ pax_open_kernel();
20405+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20406+ pax_close_kernel();
20407+ printk("PAX: slow and weak UDEREF enabled\n");
20408+ } else
20409+ printk("PAX: UDEREF disabled\n");
20410+#endif
20411+
20412+ return;
20413+ }
20414+
20415+ printk("PAX: PCID detected\n");
20416+ set_in_cr4(X86_CR4_PCIDE);
20417+
20418+#ifdef CONFIG_PAX_MEMORY_UDEREF
20419+ pax_open_kernel();
20420+ clone_pgd_mask = ~(pgdval_t)0UL;
20421+ pax_close_kernel();
20422+ if (pax_user_shadow_base)
20423+ printk("PAX: weak UDEREF enabled\n");
20424+ else {
20425+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
20426+ printk("PAX: strong UDEREF enabled\n");
20427+ }
20428+#endif
20429+
20430+ if (cpu_has(c, X86_FEATURE_INVPCID))
20431+ printk("PAX: INVPCID detected\n");
20432+}
20433+#endif
20434+
20435 /*
20436 * Some CPU features depend on higher CPUID levels, which may not always
20437 * be available due to CPUID level capping or broken virtualization
20438@@ -388,7 +387,7 @@ void switch_to_new_gdt(int cpu)
20439 {
20440 struct desc_ptr gdt_descr;
20441
20442- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
20443+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20444 gdt_descr.size = GDT_SIZE - 1;
20445 load_gdt(&gdt_descr);
20446 /* Reload the per-cpu base */
20447@@ -877,6 +876,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20448 setup_smep(c);
20449 setup_smap(c);
20450
20451+#ifdef CONFIG_X86_64
20452+ setup_pcid(c);
20453+#endif
20454+
20455 /*
20456 * The vendor-specific functions might have changed features.
20457 * Now we do "generic changes."
20458@@ -885,6 +888,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20459 /* Filter out anything that depends on CPUID levels we don't have */
20460 filter_cpuid_features(c, true);
20461
20462+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20463+ setup_clear_cpu_cap(X86_FEATURE_SEP);
20464+#endif
20465+
20466 /* If the model name is still unset, do table lookup. */
20467 if (!c->x86_model_id[0]) {
20468 const char *p;
20469@@ -1072,10 +1079,12 @@ static __init int setup_disablecpuid(char *arg)
20470 }
20471 __setup("clearcpuid=", setup_disablecpuid);
20472
20473+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
20474+EXPORT_PER_CPU_SYMBOL(current_tinfo);
20475+
20476 #ifdef CONFIG_X86_64
20477-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20478-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
20479- (unsigned long) debug_idt_table };
20480+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20481+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
20482
20483 DEFINE_PER_CPU_FIRST(union irq_stack_union,
20484 irq_stack_union) __aligned(PAGE_SIZE) __visible;
20485@@ -1089,7 +1098,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
20486 EXPORT_PER_CPU_SYMBOL(current_task);
20487
20488 DEFINE_PER_CPU(unsigned long, kernel_stack) =
20489- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
20490+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
20491 EXPORT_PER_CPU_SYMBOL(kernel_stack);
20492
20493 DEFINE_PER_CPU(char *, irq_stack_ptr) =
20494@@ -1239,7 +1248,7 @@ void cpu_init(void)
20495 load_ucode_ap();
20496
20497 cpu = stack_smp_processor_id();
20498- t = &per_cpu(init_tss, cpu);
20499+ t = init_tss + cpu;
20500 oist = &per_cpu(orig_ist, cpu);
20501
20502 #ifdef CONFIG_NUMA
20503@@ -1274,7 +1283,6 @@ void cpu_init(void)
20504 wrmsrl(MSR_KERNEL_GS_BASE, 0);
20505 barrier();
20506
20507- x86_configure_nx();
20508 enable_x2apic();
20509
20510 /*
20511@@ -1326,7 +1334,7 @@ void cpu_init(void)
20512 {
20513 int cpu = smp_processor_id();
20514 struct task_struct *curr = current;
20515- struct tss_struct *t = &per_cpu(init_tss, cpu);
20516+ struct tss_struct *t = init_tss + cpu;
20517 struct thread_struct *thread = &curr->thread;
20518
20519 show_ucode_info_early();
20520diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
20521index 0641113..06f5ba4 100644
20522--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
20523+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
20524@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
20525 };
20526
20527 #ifdef CONFIG_AMD_NB
20528+static struct attribute *default_attrs_amd_nb[] = {
20529+ &type.attr,
20530+ &level.attr,
20531+ &coherency_line_size.attr,
20532+ &physical_line_partition.attr,
20533+ &ways_of_associativity.attr,
20534+ &number_of_sets.attr,
20535+ &size.attr,
20536+ &shared_cpu_map.attr,
20537+ &shared_cpu_list.attr,
20538+ NULL,
20539+ NULL,
20540+ NULL,
20541+ NULL
20542+};
20543+
20544 static struct attribute **amd_l3_attrs(void)
20545 {
20546 static struct attribute **attrs;
20547@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
20548
20549 n = ARRAY_SIZE(default_attrs);
20550
20551- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
20552- n += 2;
20553-
20554- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
20555- n += 1;
20556-
20557- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
20558- if (attrs == NULL)
20559- return attrs = default_attrs;
20560-
20561- for (n = 0; default_attrs[n]; n++)
20562- attrs[n] = default_attrs[n];
20563+ attrs = default_attrs_amd_nb;
20564
20565 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
20566 attrs[n++] = &cache_disable_0.attr;
20567@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
20568 .default_attrs = default_attrs,
20569 };
20570
20571+#ifdef CONFIG_AMD_NB
20572+static struct kobj_type ktype_cache_amd_nb = {
20573+ .sysfs_ops = &sysfs_ops,
20574+ .default_attrs = default_attrs_amd_nb,
20575+};
20576+#endif
20577+
20578 static struct kobj_type ktype_percpu_entry = {
20579 .sysfs_ops = &sysfs_ops,
20580 };
20581@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
20582 return retval;
20583 }
20584
20585+#ifdef CONFIG_AMD_NB
20586+ amd_l3_attrs();
20587+#endif
20588+
20589 for (i = 0; i < num_cache_leaves; i++) {
20590+ struct kobj_type *ktype;
20591+
20592 this_object = INDEX_KOBJECT_PTR(cpu, i);
20593 this_object->cpu = cpu;
20594 this_object->index = i;
20595
20596 this_leaf = CPUID4_INFO_IDX(cpu, i);
20597
20598- ktype_cache.default_attrs = default_attrs;
20599+ ktype = &ktype_cache;
20600 #ifdef CONFIG_AMD_NB
20601 if (this_leaf->base.nb)
20602- ktype_cache.default_attrs = amd_l3_attrs();
20603+ ktype = &ktype_cache_amd_nb;
20604 #endif
20605 retval = kobject_init_and_add(&(this_object->kobj),
20606- &ktype_cache,
20607+ ktype,
20608 per_cpu(ici_cache_kobject, cpu),
20609 "index%1lu", i);
20610 if (unlikely(retval)) {
20611diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
20612index b3218cd..99a75de 100644
20613--- a/arch/x86/kernel/cpu/mcheck/mce.c
20614+++ b/arch/x86/kernel/cpu/mcheck/mce.c
20615@@ -45,6 +45,7 @@
20616 #include <asm/processor.h>
20617 #include <asm/mce.h>
20618 #include <asm/msr.h>
20619+#include <asm/local.h>
20620
20621 #include "mce-internal.h"
20622
20623@@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
20624 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
20625 m->cs, m->ip);
20626
20627- if (m->cs == __KERNEL_CS)
20628+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
20629 print_symbol("{%s}", m->ip);
20630 pr_cont("\n");
20631 }
20632@@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
20633
20634 #define PANIC_TIMEOUT 5 /* 5 seconds */
20635
20636-static atomic_t mce_paniced;
20637+static atomic_unchecked_t mce_paniced;
20638
20639 static int fake_panic;
20640-static atomic_t mce_fake_paniced;
20641+static atomic_unchecked_t mce_fake_paniced;
20642
20643 /* Panic in progress. Enable interrupts and wait for final IPI */
20644 static void wait_for_panic(void)
20645@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20646 /*
20647 * Make sure only one CPU runs in machine check panic
20648 */
20649- if (atomic_inc_return(&mce_paniced) > 1)
20650+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
20651 wait_for_panic();
20652 barrier();
20653
20654@@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20655 console_verbose();
20656 } else {
20657 /* Don't log too much for fake panic */
20658- if (atomic_inc_return(&mce_fake_paniced) > 1)
20659+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
20660 return;
20661 }
20662 /* First print corrected ones that are still unlogged */
20663@@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20664 if (!fake_panic) {
20665 if (panic_timeout == 0)
20666 panic_timeout = mca_cfg.panic_timeout;
20667- panic(msg);
20668+ panic("%s", msg);
20669 } else
20670 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
20671 }
20672@@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
20673 * might have been modified by someone else.
20674 */
20675 rmb();
20676- if (atomic_read(&mce_paniced))
20677+ if (atomic_read_unchecked(&mce_paniced))
20678 wait_for_panic();
20679 if (!mca_cfg.monarch_timeout)
20680 goto out;
20681@@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
20682 }
20683
20684 /* Call the installed machine check handler for this CPU setup. */
20685-void (*machine_check_vector)(struct pt_regs *, long error_code) =
20686+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
20687 unexpected_machine_check;
20688
20689 /*
20690@@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
20691 return;
20692 }
20693
20694+ pax_open_kernel();
20695 machine_check_vector = do_machine_check;
20696+ pax_close_kernel();
20697
20698 __mcheck_cpu_init_generic();
20699 __mcheck_cpu_init_vendor(c);
20700@@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
20701 */
20702
20703 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
20704-static int mce_chrdev_open_count; /* #times opened */
20705+static local_t mce_chrdev_open_count; /* #times opened */
20706 static int mce_chrdev_open_exclu; /* already open exclusive? */
20707
20708 static int mce_chrdev_open(struct inode *inode, struct file *file)
20709@@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
20710 spin_lock(&mce_chrdev_state_lock);
20711
20712 if (mce_chrdev_open_exclu ||
20713- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
20714+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
20715 spin_unlock(&mce_chrdev_state_lock);
20716
20717 return -EBUSY;
20718@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
20719
20720 if (file->f_flags & O_EXCL)
20721 mce_chrdev_open_exclu = 1;
20722- mce_chrdev_open_count++;
20723+ local_inc(&mce_chrdev_open_count);
20724
20725 spin_unlock(&mce_chrdev_state_lock);
20726
20727@@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
20728 {
20729 spin_lock(&mce_chrdev_state_lock);
20730
20731- mce_chrdev_open_count--;
20732+ local_dec(&mce_chrdev_open_count);
20733 mce_chrdev_open_exclu = 0;
20734
20735 spin_unlock(&mce_chrdev_state_lock);
20736@@ -2404,7 +2407,7 @@ static __init void mce_init_banks(void)
20737
20738 for (i = 0; i < mca_cfg.banks; i++) {
20739 struct mce_bank *b = &mce_banks[i];
20740- struct device_attribute *a = &b->attr;
20741+ device_attribute_no_const *a = &b->attr;
20742
20743 sysfs_attr_init(&a->attr);
20744 a->attr.name = b->attrname;
20745@@ -2472,7 +2475,7 @@ struct dentry *mce_get_debugfs_dir(void)
20746 static void mce_reset(void)
20747 {
20748 cpu_missing = 0;
20749- atomic_set(&mce_fake_paniced, 0);
20750+ atomic_set_unchecked(&mce_fake_paniced, 0);
20751 atomic_set(&mce_executing, 0);
20752 atomic_set(&mce_callin, 0);
20753 atomic_set(&global_nwo, 0);
20754diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
20755index 1c044b1..37a2a43 100644
20756--- a/arch/x86/kernel/cpu/mcheck/p5.c
20757+++ b/arch/x86/kernel/cpu/mcheck/p5.c
20758@@ -11,6 +11,7 @@
20759 #include <asm/processor.h>
20760 #include <asm/mce.h>
20761 #include <asm/msr.h>
20762+#include <asm/pgtable.h>
20763
20764 /* By default disabled */
20765 int mce_p5_enabled __read_mostly;
20766@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
20767 if (!cpu_has(c, X86_FEATURE_MCE))
20768 return;
20769
20770+ pax_open_kernel();
20771 machine_check_vector = pentium_machine_check;
20772+ pax_close_kernel();
20773 /* Make sure the vector pointer is visible before we enable MCEs: */
20774 wmb();
20775
20776diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
20777index e9a701a..35317d6 100644
20778--- a/arch/x86/kernel/cpu/mcheck/winchip.c
20779+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
20780@@ -10,6 +10,7 @@
20781 #include <asm/processor.h>
20782 #include <asm/mce.h>
20783 #include <asm/msr.h>
20784+#include <asm/pgtable.h>
20785
20786 /* Machine check handler for WinChip C6: */
20787 static void winchip_machine_check(struct pt_regs *regs, long error_code)
20788@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
20789 {
20790 u32 lo, hi;
20791
20792+ pax_open_kernel();
20793 machine_check_vector = winchip_machine_check;
20794+ pax_close_kernel();
20795 /* Make sure the vector pointer is visible before we enable MCEs: */
20796 wmb();
20797
20798diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
20799index f961de9..8a9d332 100644
20800--- a/arch/x86/kernel/cpu/mtrr/main.c
20801+++ b/arch/x86/kernel/cpu/mtrr/main.c
20802@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
20803 u64 size_or_mask, size_and_mask;
20804 static bool mtrr_aps_delayed_init;
20805
20806-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
20807+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
20808
20809 const struct mtrr_ops *mtrr_if;
20810
20811diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
20812index df5e41f..816c719 100644
20813--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
20814+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
20815@@ -25,7 +25,7 @@ struct mtrr_ops {
20816 int (*validate_add_page)(unsigned long base, unsigned long size,
20817 unsigned int type);
20818 int (*have_wrcomb)(void);
20819-};
20820+} __do_const;
20821
20822 extern int generic_get_free_region(unsigned long base, unsigned long size,
20823 int replace_reg);
20824diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
20825index 8e13293..9bfd68c 100644
20826--- a/arch/x86/kernel/cpu/perf_event.c
20827+++ b/arch/x86/kernel/cpu/perf_event.c
20828@@ -1348,7 +1348,7 @@ static void __init pmu_check_apic(void)
20829 pr_info("no hardware sampling interrupt available.\n");
20830 }
20831
20832-static struct attribute_group x86_pmu_format_group = {
20833+static attribute_group_no_const x86_pmu_format_group = {
20834 .name = "format",
20835 .attrs = NULL,
20836 };
20837@@ -1447,7 +1447,7 @@ static struct attribute *events_attr[] = {
20838 NULL,
20839 };
20840
20841-static struct attribute_group x86_pmu_events_group = {
20842+static attribute_group_no_const x86_pmu_events_group = {
20843 .name = "events",
20844 .attrs = events_attr,
20845 };
20846@@ -1958,7 +1958,7 @@ static unsigned long get_segment_base(unsigned int segment)
20847 if (idx > GDT_ENTRIES)
20848 return 0;
20849
20850- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
20851+ desc = get_cpu_gdt_table(smp_processor_id());
20852 }
20853
20854 return get_desc_base(desc + idx);
20855@@ -2048,7 +2048,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
20856 break;
20857
20858 perf_callchain_store(entry, frame.return_address);
20859- fp = frame.next_frame;
20860+ fp = (const void __force_user *)frame.next_frame;
20861 }
20862 }
20863
20864diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20865index 639d128..e92d7e5 100644
20866--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20867+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20868@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
20869 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
20870 {
20871 struct attribute **attrs;
20872- struct attribute_group *attr_group;
20873+ attribute_group_no_const *attr_group;
20874 int i = 0, j;
20875
20876 while (amd_iommu_v2_event_descs[i].attr.attr.name)
20877diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
20878index 0fa4f24..17990ed 100644
20879--- a/arch/x86/kernel/cpu/perf_event_intel.c
20880+++ b/arch/x86/kernel/cpu/perf_event_intel.c
20881@@ -2314,10 +2314,10 @@ __init int intel_pmu_init(void)
20882 * v2 and above have a perf capabilities MSR
20883 */
20884 if (version > 1) {
20885- u64 capabilities;
20886+ u64 capabilities = x86_pmu.intel_cap.capabilities;
20887
20888- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
20889- x86_pmu.intel_cap.capabilities = capabilities;
20890+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
20891+ x86_pmu.intel_cap.capabilities = capabilities;
20892 }
20893
20894 intel_ds_init();
20895diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20896index 29c2487..a5606fa 100644
20897--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20898+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20899@@ -3318,7 +3318,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
20900 static int __init uncore_type_init(struct intel_uncore_type *type)
20901 {
20902 struct intel_uncore_pmu *pmus;
20903- struct attribute_group *attr_group;
20904+ attribute_group_no_const *attr_group;
20905 struct attribute **attrs;
20906 int i, j;
20907
20908diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20909index a80ab71..4089da5 100644
20910--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20911+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20912@@ -498,7 +498,7 @@ struct intel_uncore_box {
20913 struct uncore_event_desc {
20914 struct kobj_attribute attr;
20915 const char *config;
20916-};
20917+} __do_const;
20918
20919 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
20920 { \
20921diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
20922index 7d9481c..99c7e4b 100644
20923--- a/arch/x86/kernel/cpuid.c
20924+++ b/arch/x86/kernel/cpuid.c
20925@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
20926 return notifier_from_errno(err);
20927 }
20928
20929-static struct notifier_block __refdata cpuid_class_cpu_notifier =
20930+static struct notifier_block cpuid_class_cpu_notifier =
20931 {
20932 .notifier_call = cpuid_class_cpu_callback,
20933 };
20934diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
20935index 18677a9..f67c45b 100644
20936--- a/arch/x86/kernel/crash.c
20937+++ b/arch/x86/kernel/crash.c
20938@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
20939 {
20940 #ifdef CONFIG_X86_32
20941 struct pt_regs fixed_regs;
20942-#endif
20943
20944-#ifdef CONFIG_X86_32
20945- if (!user_mode_vm(regs)) {
20946+ if (!user_mode(regs)) {
20947 crash_fixup_ss_esp(&fixed_regs, regs);
20948 regs = &fixed_regs;
20949 }
20950diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
20951index afa64ad..dce67dd 100644
20952--- a/arch/x86/kernel/crash_dump_64.c
20953+++ b/arch/x86/kernel/crash_dump_64.c
20954@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
20955 return -ENOMEM;
20956
20957 if (userbuf) {
20958- if (copy_to_user(buf, vaddr + offset, csize)) {
20959+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
20960 iounmap(vaddr);
20961 return -EFAULT;
20962 }
20963diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
20964index 5d3fe8d..02e1429 100644
20965--- a/arch/x86/kernel/doublefault.c
20966+++ b/arch/x86/kernel/doublefault.c
20967@@ -13,7 +13,7 @@
20968
20969 #define DOUBLEFAULT_STACKSIZE (1024)
20970 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
20971-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
20972+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
20973
20974 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
20975
20976@@ -23,7 +23,7 @@ static void doublefault_fn(void)
20977 unsigned long gdt, tss;
20978
20979 native_store_gdt(&gdt_desc);
20980- gdt = gdt_desc.address;
20981+ gdt = (unsigned long)gdt_desc.address;
20982
20983 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
20984
20985@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
20986 /* 0x2 bit is always set */
20987 .flags = X86_EFLAGS_SF | 0x2,
20988 .sp = STACK_START,
20989- .es = __USER_DS,
20990+ .es = __KERNEL_DS,
20991 .cs = __KERNEL_CS,
20992 .ss = __KERNEL_DS,
20993- .ds = __USER_DS,
20994+ .ds = __KERNEL_DS,
20995 .fs = __KERNEL_PERCPU,
20996
20997 .__cr3 = __pa_nodebug(swapper_pg_dir),
20998diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
20999index d9c12d3..7858b62 100644
21000--- a/arch/x86/kernel/dumpstack.c
21001+++ b/arch/x86/kernel/dumpstack.c
21002@@ -2,6 +2,9 @@
21003 * Copyright (C) 1991, 1992 Linus Torvalds
21004 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21005 */
21006+#ifdef CONFIG_GRKERNSEC_HIDESYM
21007+#define __INCLUDED_BY_HIDESYM 1
21008+#endif
21009 #include <linux/kallsyms.h>
21010 #include <linux/kprobes.h>
21011 #include <linux/uaccess.h>
21012@@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21013 static void
21014 print_ftrace_graph_addr(unsigned long addr, void *data,
21015 const struct stacktrace_ops *ops,
21016- struct thread_info *tinfo, int *graph)
21017+ struct task_struct *task, int *graph)
21018 {
21019- struct task_struct *task;
21020 unsigned long ret_addr;
21021 int index;
21022
21023 if (addr != (unsigned long)return_to_handler)
21024 return;
21025
21026- task = tinfo->task;
21027 index = task->curr_ret_stack;
21028
21029 if (!task->ret_stack || index < *graph)
21030@@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21031 static inline void
21032 print_ftrace_graph_addr(unsigned long addr, void *data,
21033 const struct stacktrace_ops *ops,
21034- struct thread_info *tinfo, int *graph)
21035+ struct task_struct *task, int *graph)
21036 { }
21037 #endif
21038
21039@@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21040 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21041 */
21042
21043-static inline int valid_stack_ptr(struct thread_info *tinfo,
21044- void *p, unsigned int size, void *end)
21045+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21046 {
21047- void *t = tinfo;
21048 if (end) {
21049 if (p < end && p >= (end-THREAD_SIZE))
21050 return 1;
21051@@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21052 }
21053
21054 unsigned long
21055-print_context_stack(struct thread_info *tinfo,
21056+print_context_stack(struct task_struct *task, void *stack_start,
21057 unsigned long *stack, unsigned long bp,
21058 const struct stacktrace_ops *ops, void *data,
21059 unsigned long *end, int *graph)
21060 {
21061 struct stack_frame *frame = (struct stack_frame *)bp;
21062
21063- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21064+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21065 unsigned long addr;
21066
21067 addr = *stack;
21068@@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21069 } else {
21070 ops->address(data, addr, 0);
21071 }
21072- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21073+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21074 }
21075 stack++;
21076 }
21077@@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21078 EXPORT_SYMBOL_GPL(print_context_stack);
21079
21080 unsigned long
21081-print_context_stack_bp(struct thread_info *tinfo,
21082+print_context_stack_bp(struct task_struct *task, void *stack_start,
21083 unsigned long *stack, unsigned long bp,
21084 const struct stacktrace_ops *ops, void *data,
21085 unsigned long *end, int *graph)
21086@@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21087 struct stack_frame *frame = (struct stack_frame *)bp;
21088 unsigned long *ret_addr = &frame->return_address;
21089
21090- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21091+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21092 unsigned long addr = *ret_addr;
21093
21094 if (!__kernel_text_address(addr))
21095@@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21096 ops->address(data, addr, 1);
21097 frame = frame->next_frame;
21098 ret_addr = &frame->return_address;
21099- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21100+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21101 }
21102
21103 return (unsigned long)frame;
21104@@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21105 static void print_trace_address(void *data, unsigned long addr, int reliable)
21106 {
21107 touch_nmi_watchdog();
21108- printk(data);
21109+ printk("%s", (char *)data);
21110 printk_stack_address(addr, reliable);
21111 }
21112
21113@@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21114 }
21115 EXPORT_SYMBOL_GPL(oops_begin);
21116
21117+extern void gr_handle_kernel_exploit(void);
21118+
21119 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21120 {
21121 if (regs && kexec_should_crash(current))
21122@@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21123 panic("Fatal exception in interrupt");
21124 if (panic_on_oops)
21125 panic("Fatal exception");
21126- do_exit(signr);
21127+
21128+ gr_handle_kernel_exploit();
21129+
21130+ do_group_exit(signr);
21131 }
21132
21133 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21134@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21135 print_modules();
21136 show_regs(regs);
21137 #ifdef CONFIG_X86_32
21138- if (user_mode_vm(regs)) {
21139+ if (user_mode(regs)) {
21140 sp = regs->sp;
21141 ss = regs->ss & 0xffff;
21142 } else {
21143@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21144 unsigned long flags = oops_begin();
21145 int sig = SIGSEGV;
21146
21147- if (!user_mode_vm(regs))
21148+ if (!user_mode(regs))
21149 report_bug(regs->ip, regs);
21150
21151 if (__die(str, regs, err))
21152diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21153index f2a1770..540657f 100644
21154--- a/arch/x86/kernel/dumpstack_32.c
21155+++ b/arch/x86/kernel/dumpstack_32.c
21156@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21157 bp = stack_frame(task, regs);
21158
21159 for (;;) {
21160- struct thread_info *context;
21161+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21162
21163- context = (struct thread_info *)
21164- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
21165- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
21166+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21167
21168- stack = (unsigned long *)context->previous_esp;
21169- if (!stack)
21170+ if (stack_start == task_stack_page(task))
21171 break;
21172+ stack = *(unsigned long **)stack_start;
21173 if (ops->stack(data, "IRQ") < 0)
21174 break;
21175 touch_nmi_watchdog();
21176@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
21177 int i;
21178
21179 show_regs_print_info(KERN_EMERG);
21180- __show_regs(regs, !user_mode_vm(regs));
21181+ __show_regs(regs, !user_mode(regs));
21182
21183 /*
21184 * When in-kernel, we also print out the stack and code at the
21185 * time of the fault..
21186 */
21187- if (!user_mode_vm(regs)) {
21188+ if (!user_mode(regs)) {
21189 unsigned int code_prologue = code_bytes * 43 / 64;
21190 unsigned int code_len = code_bytes;
21191 unsigned char c;
21192 u8 *ip;
21193+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21194
21195 pr_emerg("Stack:\n");
21196 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21197
21198 pr_emerg("Code:");
21199
21200- ip = (u8 *)regs->ip - code_prologue;
21201+ ip = (u8 *)regs->ip - code_prologue + cs_base;
21202 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21203 /* try starting at IP */
21204- ip = (u8 *)regs->ip;
21205+ ip = (u8 *)regs->ip + cs_base;
21206 code_len = code_len - code_prologue + 1;
21207 }
21208 for (i = 0; i < code_len; i++, ip++) {
21209@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
21210 pr_cont(" Bad EIP value.");
21211 break;
21212 }
21213- if (ip == (u8 *)regs->ip)
21214+ if (ip == (u8 *)regs->ip + cs_base)
21215 pr_cont(" <%02x>", c);
21216 else
21217 pr_cont(" %02x", c);
21218@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
21219 {
21220 unsigned short ud2;
21221
21222+ ip = ktla_ktva(ip);
21223 if (ip < PAGE_OFFSET)
21224 return 0;
21225 if (probe_kernel_address((unsigned short *)ip, ud2))
21226@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
21227
21228 return ud2 == 0x0b0f;
21229 }
21230+
21231+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21232+void pax_check_alloca(unsigned long size)
21233+{
21234+ unsigned long sp = (unsigned long)&sp, stack_left;
21235+
21236+ /* all kernel stacks are of the same size */
21237+ stack_left = sp & (THREAD_SIZE - 1);
21238+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21239+}
21240+EXPORT_SYMBOL(pax_check_alloca);
21241+#endif
21242diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21243index addb207..99635fa 100644
21244--- a/arch/x86/kernel/dumpstack_64.c
21245+++ b/arch/x86/kernel/dumpstack_64.c
21246@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21247 unsigned long *irq_stack_end =
21248 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21249 unsigned used = 0;
21250- struct thread_info *tinfo;
21251 int graph = 0;
21252 unsigned long dummy;
21253+ void *stack_start;
21254
21255 if (!task)
21256 task = current;
21257@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21258 * current stack address. If the stacks consist of nested
21259 * exceptions
21260 */
21261- tinfo = task_thread_info(task);
21262 for (;;) {
21263 char *id;
21264 unsigned long *estack_end;
21265+
21266 estack_end = in_exception_stack(cpu, (unsigned long)stack,
21267 &used, &id);
21268
21269@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21270 if (ops->stack(data, id) < 0)
21271 break;
21272
21273- bp = ops->walk_stack(tinfo, stack, bp, ops,
21274+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
21275 data, estack_end, &graph);
21276 ops->stack(data, "<EOE>");
21277 /*
21278@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21279 * second-to-last pointer (index -2 to end) in the
21280 * exception stack:
21281 */
21282+ if ((u16)estack_end[-1] != __KERNEL_DS)
21283+ goto out;
21284 stack = (unsigned long *) estack_end[-2];
21285 continue;
21286 }
21287@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21288 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
21289 if (ops->stack(data, "IRQ") < 0)
21290 break;
21291- bp = ops->walk_stack(tinfo, stack, bp,
21292+ bp = ops->walk_stack(task, irq_stack, stack, bp,
21293 ops, data, irq_stack_end, &graph);
21294 /*
21295 * We link to the next stack (which would be
21296@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21297 /*
21298 * This handles the process stack:
21299 */
21300- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21301+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21302+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21303+out:
21304 put_cpu();
21305 }
21306 EXPORT_SYMBOL(dump_trace);
21307@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
21308
21309 return ud2 == 0x0b0f;
21310 }
21311+
21312+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21313+void pax_check_alloca(unsigned long size)
21314+{
21315+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21316+ unsigned cpu, used;
21317+ char *id;
21318+
21319+ /* check the process stack first */
21320+ stack_start = (unsigned long)task_stack_page(current);
21321+ stack_end = stack_start + THREAD_SIZE;
21322+ if (likely(stack_start <= sp && sp < stack_end)) {
21323+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
21324+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21325+ return;
21326+ }
21327+
21328+ cpu = get_cpu();
21329+
21330+ /* check the irq stacks */
21331+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21332+ stack_start = stack_end - IRQ_STACK_SIZE;
21333+ if (stack_start <= sp && sp < stack_end) {
21334+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21335+ put_cpu();
21336+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21337+ return;
21338+ }
21339+
21340+ /* check the exception stacks */
21341+ used = 0;
21342+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21343+ stack_start = stack_end - EXCEPTION_STKSZ;
21344+ if (stack_end && stack_start <= sp && sp < stack_end) {
21345+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21346+ put_cpu();
21347+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21348+ return;
21349+ }
21350+
21351+ put_cpu();
21352+
21353+ /* unknown stack */
21354+ BUG();
21355+}
21356+EXPORT_SYMBOL(pax_check_alloca);
21357+#endif
21358diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21359index 174da5f..5e55606 100644
21360--- a/arch/x86/kernel/e820.c
21361+++ b/arch/x86/kernel/e820.c
21362@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21363
21364 static void early_panic(char *msg)
21365 {
21366- early_printk(msg);
21367- panic(msg);
21368+ early_printk("%s", msg);
21369+ panic("%s", msg);
21370 }
21371
21372 static int userdef __initdata;
21373diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
21374index 01d1c18..8073693 100644
21375--- a/arch/x86/kernel/early_printk.c
21376+++ b/arch/x86/kernel/early_printk.c
21377@@ -7,6 +7,7 @@
21378 #include <linux/pci_regs.h>
21379 #include <linux/pci_ids.h>
21380 #include <linux/errno.h>
21381+#include <linux/sched.h>
21382 #include <asm/io.h>
21383 #include <asm/processor.h>
21384 #include <asm/fcntl.h>
21385diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
21386index a2a4f46..6cab058 100644
21387--- a/arch/x86/kernel/entry_32.S
21388+++ b/arch/x86/kernel/entry_32.S
21389@@ -177,13 +177,153 @@
21390 /*CFI_REL_OFFSET gs, PT_GS*/
21391 .endm
21392 .macro SET_KERNEL_GS reg
21393+
21394+#ifdef CONFIG_CC_STACKPROTECTOR
21395 movl $(__KERNEL_STACK_CANARY), \reg
21396+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
21397+ movl $(__USER_DS), \reg
21398+#else
21399+ xorl \reg, \reg
21400+#endif
21401+
21402 movl \reg, %gs
21403 .endm
21404
21405 #endif /* CONFIG_X86_32_LAZY_GS */
21406
21407-.macro SAVE_ALL
21408+.macro pax_enter_kernel
21409+#ifdef CONFIG_PAX_KERNEXEC
21410+ call pax_enter_kernel
21411+#endif
21412+.endm
21413+
21414+.macro pax_exit_kernel
21415+#ifdef CONFIG_PAX_KERNEXEC
21416+ call pax_exit_kernel
21417+#endif
21418+.endm
21419+
21420+#ifdef CONFIG_PAX_KERNEXEC
21421+ENTRY(pax_enter_kernel)
21422+#ifdef CONFIG_PARAVIRT
21423+ pushl %eax
21424+ pushl %ecx
21425+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
21426+ mov %eax, %esi
21427+#else
21428+ mov %cr0, %esi
21429+#endif
21430+ bts $16, %esi
21431+ jnc 1f
21432+ mov %cs, %esi
21433+ cmp $__KERNEL_CS, %esi
21434+ jz 3f
21435+ ljmp $__KERNEL_CS, $3f
21436+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
21437+2:
21438+#ifdef CONFIG_PARAVIRT
21439+ mov %esi, %eax
21440+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
21441+#else
21442+ mov %esi, %cr0
21443+#endif
21444+3:
21445+#ifdef CONFIG_PARAVIRT
21446+ popl %ecx
21447+ popl %eax
21448+#endif
21449+ ret
21450+ENDPROC(pax_enter_kernel)
21451+
21452+ENTRY(pax_exit_kernel)
21453+#ifdef CONFIG_PARAVIRT
21454+ pushl %eax
21455+ pushl %ecx
21456+#endif
21457+ mov %cs, %esi
21458+ cmp $__KERNEXEC_KERNEL_CS, %esi
21459+ jnz 2f
21460+#ifdef CONFIG_PARAVIRT
21461+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
21462+ mov %eax, %esi
21463+#else
21464+ mov %cr0, %esi
21465+#endif
21466+ btr $16, %esi
21467+ ljmp $__KERNEL_CS, $1f
21468+1:
21469+#ifdef CONFIG_PARAVIRT
21470+ mov %esi, %eax
21471+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
21472+#else
21473+ mov %esi, %cr0
21474+#endif
21475+2:
21476+#ifdef CONFIG_PARAVIRT
21477+ popl %ecx
21478+ popl %eax
21479+#endif
21480+ ret
21481+ENDPROC(pax_exit_kernel)
21482+#endif
21483+
21484+ .macro pax_erase_kstack
21485+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21486+ call pax_erase_kstack
21487+#endif
21488+ .endm
21489+
21490+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21491+/*
21492+ * ebp: thread_info
21493+ */
21494+ENTRY(pax_erase_kstack)
21495+ pushl %edi
21496+ pushl %ecx
21497+ pushl %eax
21498+
21499+ mov TI_lowest_stack(%ebp), %edi
21500+ mov $-0xBEEF, %eax
21501+ std
21502+
21503+1: mov %edi, %ecx
21504+ and $THREAD_SIZE_asm - 1, %ecx
21505+ shr $2, %ecx
21506+ repne scasl
21507+ jecxz 2f
21508+
21509+ cmp $2*16, %ecx
21510+ jc 2f
21511+
21512+ mov $2*16, %ecx
21513+ repe scasl
21514+ jecxz 2f
21515+ jne 1b
21516+
21517+2: cld
21518+ mov %esp, %ecx
21519+ sub %edi, %ecx
21520+
21521+ cmp $THREAD_SIZE_asm, %ecx
21522+ jb 3f
21523+ ud2
21524+3:
21525+
21526+ shr $2, %ecx
21527+ rep stosl
21528+
21529+ mov TI_task_thread_sp0(%ebp), %edi
21530+ sub $128, %edi
21531+ mov %edi, TI_lowest_stack(%ebp)
21532+
21533+ popl %eax
21534+ popl %ecx
21535+ popl %edi
21536+ ret
21537+ENDPROC(pax_erase_kstack)
21538+#endif
21539+
21540+.macro __SAVE_ALL _DS
21541 cld
21542 PUSH_GS
21543 pushl_cfi %fs
21544@@ -206,7 +346,7 @@
21545 CFI_REL_OFFSET ecx, 0
21546 pushl_cfi %ebx
21547 CFI_REL_OFFSET ebx, 0
21548- movl $(__USER_DS), %edx
21549+ movl $\_DS, %edx
21550 movl %edx, %ds
21551 movl %edx, %es
21552 movl $(__KERNEL_PERCPU), %edx
21553@@ -214,6 +354,15 @@
21554 SET_KERNEL_GS %edx
21555 .endm
21556
21557+.macro SAVE_ALL
21558+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21559+ __SAVE_ALL __KERNEL_DS
21560+ pax_enter_kernel
21561+#else
21562+ __SAVE_ALL __USER_DS
21563+#endif
21564+.endm
21565+
21566 .macro RESTORE_INT_REGS
21567 popl_cfi %ebx
21568 CFI_RESTORE ebx
21569@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
21570 popfl_cfi
21571 jmp syscall_exit
21572 CFI_ENDPROC
21573-END(ret_from_fork)
21574+ENDPROC(ret_from_fork)
21575
21576 ENTRY(ret_from_kernel_thread)
21577 CFI_STARTPROC
21578@@ -344,7 +493,15 @@ ret_from_intr:
21579 andl $SEGMENT_RPL_MASK, %eax
21580 #endif
21581 cmpl $USER_RPL, %eax
21582+
21583+#ifdef CONFIG_PAX_KERNEXEC
21584+ jae resume_userspace
21585+
21586+ pax_exit_kernel
21587+ jmp resume_kernel
21588+#else
21589 jb resume_kernel # not returning to v8086 or userspace
21590+#endif
21591
21592 ENTRY(resume_userspace)
21593 LOCKDEP_SYS_EXIT
21594@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
21595 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
21596 # int/exception return?
21597 jne work_pending
21598- jmp restore_all
21599-END(ret_from_exception)
21600+ jmp restore_all_pax
21601+ENDPROC(ret_from_exception)
21602
21603 #ifdef CONFIG_PREEMPT
21604 ENTRY(resume_kernel)
21605@@ -369,7 +526,7 @@ need_resched:
21606 jz restore_all
21607 call preempt_schedule_irq
21608 jmp need_resched
21609-END(resume_kernel)
21610+ENDPROC(resume_kernel)
21611 #endif
21612 CFI_ENDPROC
21613 /*
21614@@ -403,30 +560,45 @@ sysenter_past_esp:
21615 /*CFI_REL_OFFSET cs, 0*/
21616 /*
21617 * Push current_thread_info()->sysenter_return to the stack.
21618- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
21619- * pushed above; +8 corresponds to copy_thread's esp0 setting.
21620 */
21621- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
21622+ pushl_cfi $0
21623 CFI_REL_OFFSET eip, 0
21624
21625 pushl_cfi %eax
21626 SAVE_ALL
21627+ GET_THREAD_INFO(%ebp)
21628+ movl TI_sysenter_return(%ebp),%ebp
21629+ movl %ebp,PT_EIP(%esp)
21630 ENABLE_INTERRUPTS(CLBR_NONE)
21631
21632 /*
21633 * Load the potential sixth argument from user stack.
21634 * Careful about security.
21635 */
21636+ movl PT_OLDESP(%esp),%ebp
21637+
21638+#ifdef CONFIG_PAX_MEMORY_UDEREF
21639+ mov PT_OLDSS(%esp),%ds
21640+1: movl %ds:(%ebp),%ebp
21641+ push %ss
21642+ pop %ds
21643+#else
21644 cmpl $__PAGE_OFFSET-3,%ebp
21645 jae syscall_fault
21646 ASM_STAC
21647 1: movl (%ebp),%ebp
21648 ASM_CLAC
21649+#endif
21650+
21651 movl %ebp,PT_EBP(%esp)
21652 _ASM_EXTABLE(1b,syscall_fault)
21653
21654 GET_THREAD_INFO(%ebp)
21655
21656+#ifdef CONFIG_PAX_RANDKSTACK
21657+ pax_erase_kstack
21658+#endif
21659+
21660 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
21661 jnz sysenter_audit
21662 sysenter_do_call:
21663@@ -441,12 +613,24 @@ sysenter_do_call:
21664 testl $_TIF_ALLWORK_MASK, %ecx
21665 jne sysexit_audit
21666 sysenter_exit:
21667+
21668+#ifdef CONFIG_PAX_RANDKSTACK
21669+ pushl_cfi %eax
21670+ movl %esp, %eax
21671+ call pax_randomize_kstack
21672+ popl_cfi %eax
21673+#endif
21674+
21675+ pax_erase_kstack
21676+
21677 /* if something modifies registers it must also disable sysexit */
21678 movl PT_EIP(%esp), %edx
21679 movl PT_OLDESP(%esp), %ecx
21680 xorl %ebp,%ebp
21681 TRACE_IRQS_ON
21682 1: mov PT_FS(%esp), %fs
21683+2: mov PT_DS(%esp), %ds
21684+3: mov PT_ES(%esp), %es
21685 PTGS_TO_GS
21686 ENABLE_INTERRUPTS_SYSEXIT
21687
21688@@ -463,6 +647,9 @@ sysenter_audit:
21689 movl %eax,%edx /* 2nd arg: syscall number */
21690 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
21691 call __audit_syscall_entry
21692+
21693+ pax_erase_kstack
21694+
21695 pushl_cfi %ebx
21696 movl PT_EAX(%esp),%eax /* reload syscall number */
21697 jmp sysenter_do_call
21698@@ -488,10 +675,16 @@ sysexit_audit:
21699
21700 CFI_ENDPROC
21701 .pushsection .fixup,"ax"
21702-2: movl $0,PT_FS(%esp)
21703+4: movl $0,PT_FS(%esp)
21704+ jmp 1b
21705+5: movl $0,PT_DS(%esp)
21706+ jmp 1b
21707+6: movl $0,PT_ES(%esp)
21708 jmp 1b
21709 .popsection
21710- _ASM_EXTABLE(1b,2b)
21711+ _ASM_EXTABLE(1b,4b)
21712+ _ASM_EXTABLE(2b,5b)
21713+ _ASM_EXTABLE(3b,6b)
21714 PTGS_TO_GS_EX
21715 ENDPROC(ia32_sysenter_target)
21716
21717@@ -506,6 +699,11 @@ ENTRY(system_call)
21718 pushl_cfi %eax # save orig_eax
21719 SAVE_ALL
21720 GET_THREAD_INFO(%ebp)
21721+
21722+#ifdef CONFIG_PAX_RANDKSTACK
21723+ pax_erase_kstack
21724+#endif
21725+
21726 # system call tracing in operation / emulation
21727 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
21728 jnz syscall_trace_entry
21729@@ -524,6 +722,15 @@ syscall_exit:
21730 testl $_TIF_ALLWORK_MASK, %ecx # current->work
21731 jne syscall_exit_work
21732
21733+restore_all_pax:
21734+
21735+#ifdef CONFIG_PAX_RANDKSTACK
21736+ movl %esp, %eax
21737+ call pax_randomize_kstack
21738+#endif
21739+
21740+ pax_erase_kstack
21741+
21742 restore_all:
21743 TRACE_IRQS_IRET
21744 restore_all_notrace:
21745@@ -580,14 +787,34 @@ ldt_ss:
21746 * compensating for the offset by changing to the ESPFIX segment with
21747 * a base address that matches for the difference.
21748 */
21749-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
21750+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
21751 mov %esp, %edx /* load kernel esp */
21752 mov PT_OLDESP(%esp), %eax /* load userspace esp */
21753 mov %dx, %ax /* eax: new kernel esp */
21754 sub %eax, %edx /* offset (low word is 0) */
21755+#ifdef CONFIG_SMP
21756+ movl PER_CPU_VAR(cpu_number), %ebx
21757+ shll $PAGE_SHIFT_asm, %ebx
21758+ addl $cpu_gdt_table, %ebx
21759+#else
21760+ movl $cpu_gdt_table, %ebx
21761+#endif
21762 shr $16, %edx
21763- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
21764- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
21765+
21766+#ifdef CONFIG_PAX_KERNEXEC
21767+ mov %cr0, %esi
21768+ btr $16, %esi
21769+ mov %esi, %cr0
21770+#endif
21771+
21772+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
21773+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
21774+
21775+#ifdef CONFIG_PAX_KERNEXEC
21776+ bts $16, %esi
21777+ mov %esi, %cr0
21778+#endif
21779+
21780 pushl_cfi $__ESPFIX_SS
21781 pushl_cfi %eax /* new kernel esp */
21782 /* Disable interrupts, but do not irqtrace this section: we
21783@@ -616,20 +843,18 @@ work_resched:
21784 movl TI_flags(%ebp), %ecx
21785 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
21786 # than syscall tracing?
21787- jz restore_all
21788+ jz restore_all_pax
21789 testb $_TIF_NEED_RESCHED, %cl
21790 jnz work_resched
21791
21792 work_notifysig: # deal with pending signals and
21793 # notify-resume requests
21794+ movl %esp, %eax
21795 #ifdef CONFIG_VM86
21796 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
21797- movl %esp, %eax
21798 jne work_notifysig_v86 # returning to kernel-space or
21799 # vm86-space
21800 1:
21801-#else
21802- movl %esp, %eax
21803 #endif
21804 TRACE_IRQS_ON
21805 ENABLE_INTERRUPTS(CLBR_NONE)
21806@@ -650,7 +875,7 @@ work_notifysig_v86:
21807 movl %eax, %esp
21808 jmp 1b
21809 #endif
21810-END(work_pending)
21811+ENDPROC(work_pending)
21812
21813 # perform syscall exit tracing
21814 ALIGN
21815@@ -658,11 +883,14 @@ syscall_trace_entry:
21816 movl $-ENOSYS,PT_EAX(%esp)
21817 movl %esp, %eax
21818 call syscall_trace_enter
21819+
21820+ pax_erase_kstack
21821+
21822 /* What it returned is what we'll actually use. */
21823 cmpl $(NR_syscalls), %eax
21824 jnae syscall_call
21825 jmp syscall_exit
21826-END(syscall_trace_entry)
21827+ENDPROC(syscall_trace_entry)
21828
21829 # perform syscall exit tracing
21830 ALIGN
21831@@ -675,21 +903,25 @@ syscall_exit_work:
21832 movl %esp, %eax
21833 call syscall_trace_leave
21834 jmp resume_userspace
21835-END(syscall_exit_work)
21836+ENDPROC(syscall_exit_work)
21837 CFI_ENDPROC
21838
21839 RING0_INT_FRAME # can't unwind into user space anyway
21840 syscall_fault:
21841+#ifdef CONFIG_PAX_MEMORY_UDEREF
21842+ push %ss
21843+ pop %ds
21844+#endif
21845 ASM_CLAC
21846 GET_THREAD_INFO(%ebp)
21847 movl $-EFAULT,PT_EAX(%esp)
21848 jmp resume_userspace
21849-END(syscall_fault)
21850+ENDPROC(syscall_fault)
21851
21852 syscall_badsys:
21853 movl $-ENOSYS,PT_EAX(%esp)
21854 jmp resume_userspace
21855-END(syscall_badsys)
21856+ENDPROC(syscall_badsys)
21857 CFI_ENDPROC
21858 /*
21859 * End of kprobes section
21860@@ -705,8 +937,15 @@ END(syscall_badsys)
21861 * normal stack and adjusts ESP with the matching offset.
21862 */
21863 /* fixup the stack */
21864- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
21865- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
21866+#ifdef CONFIG_SMP
21867+ movl PER_CPU_VAR(cpu_number), %ebx
21868+ shll $PAGE_SHIFT_asm, %ebx
21869+ addl $cpu_gdt_table, %ebx
21870+#else
21871+ movl $cpu_gdt_table, %ebx
21872+#endif
21873+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
21874+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
21875 shl $16, %eax
21876 addl %esp, %eax /* the adjusted stack pointer */
21877 pushl_cfi $__KERNEL_DS
21878@@ -759,7 +998,7 @@ vector=vector+1
21879 .endr
21880 2: jmp common_interrupt
21881 .endr
21882-END(irq_entries_start)
21883+ENDPROC(irq_entries_start)
21884
21885 .previous
21886 END(interrupt)
21887@@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
21888 pushl_cfi $do_coprocessor_error
21889 jmp error_code
21890 CFI_ENDPROC
21891-END(coprocessor_error)
21892+ENDPROC(coprocessor_error)
21893
21894 ENTRY(simd_coprocessor_error)
21895 RING0_INT_FRAME
21896@@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
21897 .section .altinstructions,"a"
21898 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
21899 .previous
21900-.section .altinstr_replacement,"ax"
21901+.section .altinstr_replacement,"a"
21902 663: pushl $do_simd_coprocessor_error
21903 664:
21904 .previous
21905@@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
21906 #endif
21907 jmp error_code
21908 CFI_ENDPROC
21909-END(simd_coprocessor_error)
21910+ENDPROC(simd_coprocessor_error)
21911
21912 ENTRY(device_not_available)
21913 RING0_INT_FRAME
21914@@ -851,18 +1090,18 @@ ENTRY(device_not_available)
21915 pushl_cfi $do_device_not_available
21916 jmp error_code
21917 CFI_ENDPROC
21918-END(device_not_available)
21919+ENDPROC(device_not_available)
21920
21921 #ifdef CONFIG_PARAVIRT
21922 ENTRY(native_iret)
21923 iret
21924 _ASM_EXTABLE(native_iret, iret_exc)
21925-END(native_iret)
21926+ENDPROC(native_iret)
21927
21928 ENTRY(native_irq_enable_sysexit)
21929 sti
21930 sysexit
21931-END(native_irq_enable_sysexit)
21932+ENDPROC(native_irq_enable_sysexit)
21933 #endif
21934
21935 ENTRY(overflow)
21936@@ -872,7 +1111,7 @@ ENTRY(overflow)
21937 pushl_cfi $do_overflow
21938 jmp error_code
21939 CFI_ENDPROC
21940-END(overflow)
21941+ENDPROC(overflow)
21942
21943 ENTRY(bounds)
21944 RING0_INT_FRAME
21945@@ -881,7 +1120,7 @@ ENTRY(bounds)
21946 pushl_cfi $do_bounds
21947 jmp error_code
21948 CFI_ENDPROC
21949-END(bounds)
21950+ENDPROC(bounds)
21951
21952 ENTRY(invalid_op)
21953 RING0_INT_FRAME
21954@@ -890,7 +1129,7 @@ ENTRY(invalid_op)
21955 pushl_cfi $do_invalid_op
21956 jmp error_code
21957 CFI_ENDPROC
21958-END(invalid_op)
21959+ENDPROC(invalid_op)
21960
21961 ENTRY(coprocessor_segment_overrun)
21962 RING0_INT_FRAME
21963@@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
21964 pushl_cfi $do_coprocessor_segment_overrun
21965 jmp error_code
21966 CFI_ENDPROC
21967-END(coprocessor_segment_overrun)
21968+ENDPROC(coprocessor_segment_overrun)
21969
21970 ENTRY(invalid_TSS)
21971 RING0_EC_FRAME
21972@@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
21973 pushl_cfi $do_invalid_TSS
21974 jmp error_code
21975 CFI_ENDPROC
21976-END(invalid_TSS)
21977+ENDPROC(invalid_TSS)
21978
21979 ENTRY(segment_not_present)
21980 RING0_EC_FRAME
21981@@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
21982 pushl_cfi $do_segment_not_present
21983 jmp error_code
21984 CFI_ENDPROC
21985-END(segment_not_present)
21986+ENDPROC(segment_not_present)
21987
21988 ENTRY(stack_segment)
21989 RING0_EC_FRAME
21990@@ -923,7 +1162,7 @@ ENTRY(stack_segment)
21991 pushl_cfi $do_stack_segment
21992 jmp error_code
21993 CFI_ENDPROC
21994-END(stack_segment)
21995+ENDPROC(stack_segment)
21996
21997 ENTRY(alignment_check)
21998 RING0_EC_FRAME
21999@@ -931,7 +1170,7 @@ ENTRY(alignment_check)
22000 pushl_cfi $do_alignment_check
22001 jmp error_code
22002 CFI_ENDPROC
22003-END(alignment_check)
22004+ENDPROC(alignment_check)
22005
22006 ENTRY(divide_error)
22007 RING0_INT_FRAME
22008@@ -940,7 +1179,7 @@ ENTRY(divide_error)
22009 pushl_cfi $do_divide_error
22010 jmp error_code
22011 CFI_ENDPROC
22012-END(divide_error)
22013+ENDPROC(divide_error)
22014
22015 #ifdef CONFIG_X86_MCE
22016 ENTRY(machine_check)
22017@@ -950,7 +1189,7 @@ ENTRY(machine_check)
22018 pushl_cfi machine_check_vector
22019 jmp error_code
22020 CFI_ENDPROC
22021-END(machine_check)
22022+ENDPROC(machine_check)
22023 #endif
22024
22025 ENTRY(spurious_interrupt_bug)
22026@@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
22027 pushl_cfi $do_spurious_interrupt_bug
22028 jmp error_code
22029 CFI_ENDPROC
22030-END(spurious_interrupt_bug)
22031+ENDPROC(spurious_interrupt_bug)
22032 /*
22033 * End of kprobes section
22034 */
22035@@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22036
22037 ENTRY(mcount)
22038 ret
22039-END(mcount)
22040+ENDPROC(mcount)
22041
22042 ENTRY(ftrace_caller)
22043 cmpl $0, function_trace_stop
22044@@ -1103,7 +1342,7 @@ ftrace_graph_call:
22045 .globl ftrace_stub
22046 ftrace_stub:
22047 ret
22048-END(ftrace_caller)
22049+ENDPROC(ftrace_caller)
22050
22051 ENTRY(ftrace_regs_caller)
22052 pushf /* push flags before compare (in cs location) */
22053@@ -1207,7 +1446,7 @@ trace:
22054 popl %ecx
22055 popl %eax
22056 jmp ftrace_stub
22057-END(mcount)
22058+ENDPROC(mcount)
22059 #endif /* CONFIG_DYNAMIC_FTRACE */
22060 #endif /* CONFIG_FUNCTION_TRACER */
22061
22062@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
22063 popl %ecx
22064 popl %eax
22065 ret
22066-END(ftrace_graph_caller)
22067+ENDPROC(ftrace_graph_caller)
22068
22069 .globl return_to_handler
22070 return_to_handler:
22071@@ -1291,15 +1530,18 @@ error_code:
22072 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22073 REG_TO_PTGS %ecx
22074 SET_KERNEL_GS %ecx
22075- movl $(__USER_DS), %ecx
22076+ movl $(__KERNEL_DS), %ecx
22077 movl %ecx, %ds
22078 movl %ecx, %es
22079+
22080+ pax_enter_kernel
22081+
22082 TRACE_IRQS_OFF
22083 movl %esp,%eax # pt_regs pointer
22084 call *%edi
22085 jmp ret_from_exception
22086 CFI_ENDPROC
22087-END(page_fault)
22088+ENDPROC(page_fault)
22089
22090 /*
22091 * Debug traps and NMI can happen at the one SYSENTER instruction
22092@@ -1342,7 +1584,7 @@ debug_stack_correct:
22093 call do_debug
22094 jmp ret_from_exception
22095 CFI_ENDPROC
22096-END(debug)
22097+ENDPROC(debug)
22098
22099 /*
22100 * NMI is doubly nasty. It can happen _while_ we're handling
22101@@ -1380,6 +1622,9 @@ nmi_stack_correct:
22102 xorl %edx,%edx # zero error code
22103 movl %esp,%eax # pt_regs pointer
22104 call do_nmi
22105+
22106+ pax_exit_kernel
22107+
22108 jmp restore_all_notrace
22109 CFI_ENDPROC
22110
22111@@ -1416,12 +1661,15 @@ nmi_espfix_stack:
22112 FIXUP_ESPFIX_STACK # %eax == %esp
22113 xorl %edx,%edx # zero error code
22114 call do_nmi
22115+
22116+ pax_exit_kernel
22117+
22118 RESTORE_REGS
22119 lss 12+4(%esp), %esp # back to espfix stack
22120 CFI_ADJUST_CFA_OFFSET -24
22121 jmp irq_return
22122 CFI_ENDPROC
22123-END(nmi)
22124+ENDPROC(nmi)
22125
22126 ENTRY(int3)
22127 RING0_INT_FRAME
22128@@ -1434,14 +1682,14 @@ ENTRY(int3)
22129 call do_int3
22130 jmp ret_from_exception
22131 CFI_ENDPROC
22132-END(int3)
22133+ENDPROC(int3)
22134
22135 ENTRY(general_protection)
22136 RING0_EC_FRAME
22137 pushl_cfi $do_general_protection
22138 jmp error_code
22139 CFI_ENDPROC
22140-END(general_protection)
22141+ENDPROC(general_protection)
22142
22143 #ifdef CONFIG_KVM_GUEST
22144 ENTRY(async_page_fault)
22145@@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
22146 pushl_cfi $do_async_page_fault
22147 jmp error_code
22148 CFI_ENDPROC
22149-END(async_page_fault)
22150+ENDPROC(async_page_fault)
22151 #endif
22152
22153 /*
22154diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22155index 1e96c36..3ff710a 100644
22156--- a/arch/x86/kernel/entry_64.S
22157+++ b/arch/x86/kernel/entry_64.S
22158@@ -59,6 +59,8 @@
22159 #include <asm/context_tracking.h>
22160 #include <asm/smap.h>
22161 #include <linux/err.h>
22162+#include <asm/pgtable.h>
22163+#include <asm/alternative-asm.h>
22164
22165 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22166 #include <linux/elf-em.h>
22167@@ -80,8 +82,9 @@
22168 #ifdef CONFIG_DYNAMIC_FTRACE
22169
22170 ENTRY(function_hook)
22171+ pax_force_retaddr
22172 retq
22173-END(function_hook)
22174+ENDPROC(function_hook)
22175
22176 /* skip is set if stack has been adjusted */
22177 .macro ftrace_caller_setup skip=0
22178@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22179 #endif
22180
22181 GLOBAL(ftrace_stub)
22182+ pax_force_retaddr
22183 retq
22184-END(ftrace_caller)
22185+ENDPROC(ftrace_caller)
22186
22187 ENTRY(ftrace_regs_caller)
22188 /* Save the current flags before compare (in SS location)*/
22189@@ -191,7 +195,7 @@ ftrace_restore_flags:
22190 popfq
22191 jmp ftrace_stub
22192
22193-END(ftrace_regs_caller)
22194+ENDPROC(ftrace_regs_caller)
22195
22196
22197 #else /* ! CONFIG_DYNAMIC_FTRACE */
22198@@ -212,6 +216,7 @@ ENTRY(function_hook)
22199 #endif
22200
22201 GLOBAL(ftrace_stub)
22202+ pax_force_retaddr
22203 retq
22204
22205 trace:
22206@@ -225,12 +230,13 @@ trace:
22207 #endif
22208 subq $MCOUNT_INSN_SIZE, %rdi
22209
22210+ pax_force_fptr ftrace_trace_function
22211 call *ftrace_trace_function
22212
22213 MCOUNT_RESTORE_FRAME
22214
22215 jmp ftrace_stub
22216-END(function_hook)
22217+ENDPROC(function_hook)
22218 #endif /* CONFIG_DYNAMIC_FTRACE */
22219 #endif /* CONFIG_FUNCTION_TRACER */
22220
22221@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22222
22223 MCOUNT_RESTORE_FRAME
22224
22225+ pax_force_retaddr
22226 retq
22227-END(ftrace_graph_caller)
22228+ENDPROC(ftrace_graph_caller)
22229
22230 GLOBAL(return_to_handler)
22231 subq $24, %rsp
22232@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22233 movq 8(%rsp), %rdx
22234 movq (%rsp), %rax
22235 addq $24, %rsp
22236+ pax_force_fptr %rdi
22237 jmp *%rdi
22238+ENDPROC(return_to_handler)
22239 #endif
22240
22241
22242@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22243 ENDPROC(native_usergs_sysret64)
22244 #endif /* CONFIG_PARAVIRT */
22245
22246+ .macro ljmpq sel, off
22247+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22248+ .byte 0x48; ljmp *1234f(%rip)
22249+ .pushsection .rodata
22250+ .align 16
22251+ 1234: .quad \off; .word \sel
22252+ .popsection
22253+#else
22254+ pushq $\sel
22255+ pushq $\off
22256+ lretq
22257+#endif
22258+ .endm
22259+
22260+ .macro pax_enter_kernel
22261+ pax_set_fptr_mask
22262+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22263+ call pax_enter_kernel
22264+#endif
22265+ .endm
22266+
22267+ .macro pax_exit_kernel
22268+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22269+ call pax_exit_kernel
22270+#endif
22271+
22272+ .endm
22273+
22274+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22275+ENTRY(pax_enter_kernel)
22276+ pushq %rdi
22277+
22278+#ifdef CONFIG_PARAVIRT
22279+ PV_SAVE_REGS(CLBR_RDI)
22280+#endif
22281+
22282+#ifdef CONFIG_PAX_KERNEXEC
22283+ GET_CR0_INTO_RDI
22284+ bts $16,%rdi
22285+ jnc 3f
22286+ mov %cs,%edi
22287+ cmp $__KERNEL_CS,%edi
22288+ jnz 2f
22289+1:
22290+#endif
22291+
22292+#ifdef CONFIG_PAX_MEMORY_UDEREF
22293+ 661: jmp 111f
22294+ .pushsection .altinstr_replacement, "a"
22295+ 662: ASM_NOP2
22296+ .popsection
22297+ .pushsection .altinstructions, "a"
22298+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22299+ .popsection
22300+ GET_CR3_INTO_RDI
22301+ cmp $0,%dil
22302+ jnz 112f
22303+ mov $__KERNEL_DS,%edi
22304+ mov %edi,%ss
22305+ jmp 111f
22306+112: cmp $1,%dil
22307+ jz 113f
22308+ ud2
22309+113: sub $4097,%rdi
22310+ bts $63,%rdi
22311+ SET_RDI_INTO_CR3
22312+ mov $__UDEREF_KERNEL_DS,%edi
22313+ mov %edi,%ss
22314+111:
22315+#endif
22316+
22317+#ifdef CONFIG_PARAVIRT
22318+ PV_RESTORE_REGS(CLBR_RDI)
22319+#endif
22320+
22321+ popq %rdi
22322+ pax_force_retaddr
22323+ retq
22324+
22325+#ifdef CONFIG_PAX_KERNEXEC
22326+2: ljmpq __KERNEL_CS,1b
22327+3: ljmpq __KERNEXEC_KERNEL_CS,4f
22328+4: SET_RDI_INTO_CR0
22329+ jmp 1b
22330+#endif
22331+ENDPROC(pax_enter_kernel)
22332+
22333+ENTRY(pax_exit_kernel)
22334+ pushq %rdi
22335+
22336+#ifdef CONFIG_PARAVIRT
22337+ PV_SAVE_REGS(CLBR_RDI)
22338+#endif
22339+
22340+#ifdef CONFIG_PAX_KERNEXEC
22341+ mov %cs,%rdi
22342+ cmp $__KERNEXEC_KERNEL_CS,%edi
22343+ jz 2f
22344+ GET_CR0_INTO_RDI
22345+ bts $16,%rdi
22346+ jnc 4f
22347+1:
22348+#endif
22349+
22350+#ifdef CONFIG_PAX_MEMORY_UDEREF
22351+ 661: jmp 111f
22352+ .pushsection .altinstr_replacement, "a"
22353+ 662: ASM_NOP2
22354+ .popsection
22355+ .pushsection .altinstructions, "a"
22356+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22357+ .popsection
22358+ mov %ss,%edi
22359+ cmp $__UDEREF_KERNEL_DS,%edi
22360+ jnz 111f
22361+ GET_CR3_INTO_RDI
22362+ cmp $0,%dil
22363+ jz 112f
22364+ ud2
22365+112: add $4097,%rdi
22366+ bts $63,%rdi
22367+ SET_RDI_INTO_CR3
22368+ mov $__KERNEL_DS,%edi
22369+ mov %edi,%ss
22370+111:
22371+#endif
22372+
22373+#ifdef CONFIG_PARAVIRT
22374+ PV_RESTORE_REGS(CLBR_RDI);
22375+#endif
22376+
22377+ popq %rdi
22378+ pax_force_retaddr
22379+ retq
22380+
22381+#ifdef CONFIG_PAX_KERNEXEC
22382+2: GET_CR0_INTO_RDI
22383+ btr $16,%rdi
22384+ jnc 4f
22385+ ljmpq __KERNEL_CS,3f
22386+3: SET_RDI_INTO_CR0
22387+ jmp 1b
22388+4: ud2
22389+ jmp 4b
22390+#endif
22391+ENDPROC(pax_exit_kernel)
22392+#endif
22393+
22394+ .macro pax_enter_kernel_user
22395+ pax_set_fptr_mask
22396+#ifdef CONFIG_PAX_MEMORY_UDEREF
22397+ call pax_enter_kernel_user
22398+#endif
22399+ .endm
22400+
22401+ .macro pax_exit_kernel_user
22402+#ifdef CONFIG_PAX_MEMORY_UDEREF
22403+ call pax_exit_kernel_user
22404+#endif
22405+#ifdef CONFIG_PAX_RANDKSTACK
22406+ pushq %rax
22407+ pushq %r11
22408+ call pax_randomize_kstack
22409+ popq %r11
22410+ popq %rax
22411+#endif
22412+ .endm
22413+
22414+#ifdef CONFIG_PAX_MEMORY_UDEREF
22415+ENTRY(pax_enter_kernel_user)
22416+ pushq %rdi
22417+ pushq %rbx
22418+
22419+#ifdef CONFIG_PARAVIRT
22420+ PV_SAVE_REGS(CLBR_RDI)
22421+#endif
22422+
22423+ 661: jmp 111f
22424+ .pushsection .altinstr_replacement, "a"
22425+ 662: ASM_NOP2
22426+ .popsection
22427+ .pushsection .altinstructions, "a"
22428+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22429+ .popsection
22430+ GET_CR3_INTO_RDI
22431+ cmp $1,%dil
22432+ jnz 4f
22433+ sub $4097,%rdi
22434+ bts $63,%rdi
22435+ SET_RDI_INTO_CR3
22436+ jmp 3f
22437+111:
22438+
22439+ GET_CR3_INTO_RDI
22440+ mov %rdi,%rbx
22441+ add $__START_KERNEL_map,%rbx
22442+ sub phys_base(%rip),%rbx
22443+
22444+#ifdef CONFIG_PARAVIRT
22445+ cmpl $0, pv_info+PARAVIRT_enabled
22446+ jz 1f
22447+ pushq %rdi
22448+ i = 0
22449+ .rept USER_PGD_PTRS
22450+ mov i*8(%rbx),%rsi
22451+ mov $0,%sil
22452+ lea i*8(%rbx),%rdi
22453+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22454+ i = i + 1
22455+ .endr
22456+ popq %rdi
22457+ jmp 2f
22458+1:
22459+#endif
22460+
22461+ i = 0
22462+ .rept USER_PGD_PTRS
22463+ movb $0,i*8(%rbx)
22464+ i = i + 1
22465+ .endr
22466+
22467+2: SET_RDI_INTO_CR3
22468+
22469+#ifdef CONFIG_PAX_KERNEXEC
22470+ GET_CR0_INTO_RDI
22471+ bts $16,%rdi
22472+ SET_RDI_INTO_CR0
22473+#endif
22474+
22475+3:
22476+
22477+#ifdef CONFIG_PARAVIRT
22478+ PV_RESTORE_REGS(CLBR_RDI)
22479+#endif
22480+
22481+ popq %rbx
22482+ popq %rdi
22483+ pax_force_retaddr
22484+ retq
22485+4: ud2
22486+ENDPROC(pax_enter_kernel_user)
22487+
22488+ENTRY(pax_exit_kernel_user)
22489+ pushq %rdi
22490+ pushq %rbx
22491+
22492+#ifdef CONFIG_PARAVIRT
22493+ PV_SAVE_REGS(CLBR_RDI)
22494+#endif
22495+
22496+ GET_CR3_INTO_RDI
22497+ 661: jmp 1f
22498+ .pushsection .altinstr_replacement, "a"
22499+ 662: ASM_NOP2
22500+ .popsection
22501+ .pushsection .altinstructions, "a"
22502+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22503+ .popsection
22504+ cmp $0,%dil
22505+ jnz 3f
22506+ add $4097,%rdi
22507+ bts $63,%rdi
22508+ SET_RDI_INTO_CR3
22509+ jmp 2f
22510+1:
22511+
22512+ mov %rdi,%rbx
22513+
22514+#ifdef CONFIG_PAX_KERNEXEC
22515+ GET_CR0_INTO_RDI
22516+ btr $16,%rdi
22517+ jnc 3f
22518+ SET_RDI_INTO_CR0
22519+#endif
22520+
22521+ add $__START_KERNEL_map,%rbx
22522+ sub phys_base(%rip),%rbx
22523+
22524+#ifdef CONFIG_PARAVIRT
22525+ cmpl $0, pv_info+PARAVIRT_enabled
22526+ jz 1f
22527+ i = 0
22528+ .rept USER_PGD_PTRS
22529+ mov i*8(%rbx),%rsi
22530+ mov $0x67,%sil
22531+ lea i*8(%rbx),%rdi
22532+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22533+ i = i + 1
22534+ .endr
22535+ jmp 2f
22536+1:
22537+#endif
22538+
22539+ i = 0
22540+ .rept USER_PGD_PTRS
22541+ movb $0x67,i*8(%rbx)
22542+ i = i + 1
22543+ .endr
22544+2:
22545+
22546+#ifdef CONFIG_PARAVIRT
22547+ PV_RESTORE_REGS(CLBR_RDI)
22548+#endif
22549+
22550+ popq %rbx
22551+ popq %rdi
22552+ pax_force_retaddr
22553+ retq
22554+3: ud2
22555+ENDPROC(pax_exit_kernel_user)
22556+#endif
22557+
22558+ .macro pax_enter_kernel_nmi
22559+ pax_set_fptr_mask
22560+
22561+#ifdef CONFIG_PAX_KERNEXEC
22562+ GET_CR0_INTO_RDI
22563+ bts $16,%rdi
22564+ jc 110f
22565+ SET_RDI_INTO_CR0
22566+ or $2,%ebx
22567+110:
22568+#endif
22569+
22570+#ifdef CONFIG_PAX_MEMORY_UDEREF
22571+ 661: jmp 111f
22572+ .pushsection .altinstr_replacement, "a"
22573+ 662: ASM_NOP2
22574+ .popsection
22575+ .pushsection .altinstructions, "a"
22576+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22577+ .popsection
22578+ GET_CR3_INTO_RDI
22579+ cmp $0,%dil
22580+ jz 111f
22581+ sub $4097,%rdi
22582+ or $4,%ebx
22583+ bts $63,%rdi
22584+ SET_RDI_INTO_CR3
22585+ mov $__UDEREF_KERNEL_DS,%edi
22586+ mov %edi,%ss
22587+111:
22588+#endif
22589+ .endm
22590+
22591+ .macro pax_exit_kernel_nmi
22592+#ifdef CONFIG_PAX_KERNEXEC
22593+ btr $1,%ebx
22594+ jnc 110f
22595+ GET_CR0_INTO_RDI
22596+ btr $16,%rdi
22597+ SET_RDI_INTO_CR0
22598+110:
22599+#endif
22600+
22601+#ifdef CONFIG_PAX_MEMORY_UDEREF
22602+ btr $2,%ebx
22603+ jnc 111f
22604+ GET_CR3_INTO_RDI
22605+ add $4097,%rdi
22606+ bts $63,%rdi
22607+ SET_RDI_INTO_CR3
22608+ mov $__KERNEL_DS,%edi
22609+ mov %edi,%ss
22610+111:
22611+#endif
22612+ .endm
22613+
22614+ .macro pax_erase_kstack
22615+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22616+ call pax_erase_kstack
22617+#endif
22618+ .endm
22619+
22620+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22621+ENTRY(pax_erase_kstack)
22622+ pushq %rdi
22623+ pushq %rcx
22624+ pushq %rax
22625+ pushq %r11
22626+
22627+ GET_THREAD_INFO(%r11)
22628+ mov TI_lowest_stack(%r11), %rdi
22629+ mov $-0xBEEF, %rax
22630+ std
22631+
22632+1: mov %edi, %ecx
22633+ and $THREAD_SIZE_asm - 1, %ecx
22634+ shr $3, %ecx
22635+ repne scasq
22636+ jecxz 2f
22637+
22638+ cmp $2*8, %ecx
22639+ jc 2f
22640+
22641+ mov $2*8, %ecx
22642+ repe scasq
22643+ jecxz 2f
22644+ jne 1b
22645+
22646+2: cld
22647+ mov %esp, %ecx
22648+ sub %edi, %ecx
22649+
22650+ cmp $THREAD_SIZE_asm, %rcx
22651+ jb 3f
22652+ ud2
22653+3:
22654+
22655+ shr $3, %ecx
22656+ rep stosq
22657+
22658+ mov TI_task_thread_sp0(%r11), %rdi
22659+ sub $256, %rdi
22660+ mov %rdi, TI_lowest_stack(%r11)
22661+
22662+ popq %r11
22663+ popq %rax
22664+ popq %rcx
22665+ popq %rdi
22666+ pax_force_retaddr
22667+ ret
22668+ENDPROC(pax_erase_kstack)
22669+#endif
22670
22671 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
22672 #ifdef CONFIG_TRACE_IRQFLAGS
22673@@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
22674 .endm
22675
22676 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
22677- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
22678+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
22679 jnc 1f
22680 TRACE_IRQS_ON_DEBUG
22681 1:
22682@@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
22683 movq \tmp,R11+\offset(%rsp)
22684 .endm
22685
22686- .macro FAKE_STACK_FRAME child_rip
22687- /* push in order ss, rsp, eflags, cs, rip */
22688- xorl %eax, %eax
22689- pushq_cfi $__KERNEL_DS /* ss */
22690- /*CFI_REL_OFFSET ss,0*/
22691- pushq_cfi %rax /* rsp */
22692- CFI_REL_OFFSET rsp,0
22693- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
22694- /*CFI_REL_OFFSET rflags,0*/
22695- pushq_cfi $__KERNEL_CS /* cs */
22696- /*CFI_REL_OFFSET cs,0*/
22697- pushq_cfi \child_rip /* rip */
22698- CFI_REL_OFFSET rip,0
22699- pushq_cfi %rax /* orig rax */
22700- .endm
22701-
22702- .macro UNFAKE_STACK_FRAME
22703- addq $8*6, %rsp
22704- CFI_ADJUST_CFA_OFFSET -(6*8)
22705- .endm
22706-
22707 /*
22708 * initial frame state for interrupts (and exceptions without error code)
22709 */
22710@@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
22711 /* save partial stack frame */
22712 .macro SAVE_ARGS_IRQ
22713 cld
22714- /* start from rbp in pt_regs and jump over */
22715- movq_cfi rdi, (RDI-RBP)
22716- movq_cfi rsi, (RSI-RBP)
22717- movq_cfi rdx, (RDX-RBP)
22718- movq_cfi rcx, (RCX-RBP)
22719- movq_cfi rax, (RAX-RBP)
22720- movq_cfi r8, (R8-RBP)
22721- movq_cfi r9, (R9-RBP)
22722- movq_cfi r10, (R10-RBP)
22723- movq_cfi r11, (R11-RBP)
22724+ /* start from r15 in pt_regs and jump over */
22725+ movq_cfi rdi, RDI
22726+ movq_cfi rsi, RSI
22727+ movq_cfi rdx, RDX
22728+ movq_cfi rcx, RCX
22729+ movq_cfi rax, RAX
22730+ movq_cfi r8, R8
22731+ movq_cfi r9, R9
22732+ movq_cfi r10, R10
22733+ movq_cfi r11, R11
22734+ movq_cfi r12, R12
22735
22736 /* Save rbp so that we can unwind from get_irq_regs() */
22737- movq_cfi rbp, 0
22738+ movq_cfi rbp, RBP
22739
22740 /* Save previous stack value */
22741 movq %rsp, %rsi
22742
22743- leaq -RBP(%rsp),%rdi /* arg1 for handler */
22744- testl $3, CS-RBP(%rsi)
22745+ movq %rsp,%rdi /* arg1 for handler */
22746+ testb $3, CS(%rsi)
22747 je 1f
22748 SWAPGS
22749 /*
22750@@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
22751 0x06 /* DW_OP_deref */, \
22752 0x08 /* DW_OP_const1u */, SS+8-RBP, \
22753 0x22 /* DW_OP_plus */
22754+
22755+#ifdef CONFIG_PAX_MEMORY_UDEREF
22756+ testb $3, CS(%rdi)
22757+ jnz 1f
22758+ pax_enter_kernel
22759+ jmp 2f
22760+1: pax_enter_kernel_user
22761+2:
22762+#else
22763+ pax_enter_kernel
22764+#endif
22765+
22766 /* We entered an interrupt context - irqs are off: */
22767 TRACE_IRQS_OFF
22768 .endm
22769@@ -514,9 +939,52 @@ ENTRY(save_paranoid)
22770 js 1f /* negative -> in kernel */
22771 SWAPGS
22772 xorl %ebx,%ebx
22773-1: ret
22774+1:
22775+#ifdef CONFIG_PAX_MEMORY_UDEREF
22776+ testb $3, CS+8(%rsp)
22777+ jnz 1f
22778+ pax_enter_kernel
22779+ jmp 2f
22780+1: pax_enter_kernel_user
22781+2:
22782+#else
22783+ pax_enter_kernel
22784+#endif
22785+ pax_force_retaddr
22786+ ret
22787 CFI_ENDPROC
22788-END(save_paranoid)
22789+ENDPROC(save_paranoid)
22790+
22791+ENTRY(save_paranoid_nmi)
22792+ XCPT_FRAME 1 RDI+8
22793+ cld
22794+ movq_cfi rdi, RDI+8
22795+ movq_cfi rsi, RSI+8
22796+ movq_cfi rdx, RDX+8
22797+ movq_cfi rcx, RCX+8
22798+ movq_cfi rax, RAX+8
22799+ movq_cfi r8, R8+8
22800+ movq_cfi r9, R9+8
22801+ movq_cfi r10, R10+8
22802+ movq_cfi r11, R11+8
22803+ movq_cfi rbx, RBX+8
22804+ movq_cfi rbp, RBP+8
22805+ movq_cfi r12, R12+8
22806+ movq_cfi r13, R13+8
22807+ movq_cfi r14, R14+8
22808+ movq_cfi r15, R15+8
22809+ movl $1,%ebx
22810+ movl $MSR_GS_BASE,%ecx
22811+ rdmsr
22812+ testl %edx,%edx
22813+ js 1f /* negative -> in kernel */
22814+ SWAPGS
22815+ xorl %ebx,%ebx
22816+1: pax_enter_kernel_nmi
22817+ pax_force_retaddr
22818+ ret
22819+ CFI_ENDPROC
22820+ENDPROC(save_paranoid_nmi)
22821 .popsection
22822
22823 /*
22824@@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
22825
22826 RESTORE_REST
22827
22828- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
22829+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
22830 jz 1f
22831
22832 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
22833@@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
22834 jmp ret_from_sys_call # go to the SYSRET fastpath
22835
22836 1:
22837- subq $REST_SKIP, %rsp # leave space for volatiles
22838- CFI_ADJUST_CFA_OFFSET REST_SKIP
22839 movq %rbp, %rdi
22840 call *%rbx
22841 movl $0, RAX(%rsp)
22842 RESTORE_REST
22843 jmp int_ret_from_sys_call
22844 CFI_ENDPROC
22845-END(ret_from_fork)
22846+ENDPROC(ret_from_fork)
22847
22848 /*
22849 * System call entry. Up to 6 arguments in registers are supported.
22850@@ -593,7 +1059,7 @@ END(ret_from_fork)
22851 ENTRY(system_call)
22852 CFI_STARTPROC simple
22853 CFI_SIGNAL_FRAME
22854- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
22855+ CFI_DEF_CFA rsp,0
22856 CFI_REGISTER rip,rcx
22857 /*CFI_REGISTER rflags,r11*/
22858 SWAPGS_UNSAFE_STACK
22859@@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
22860
22861 movq %rsp,PER_CPU_VAR(old_rsp)
22862 movq PER_CPU_VAR(kernel_stack),%rsp
22863+ SAVE_ARGS 8*6,0
22864+ pax_enter_kernel_user
22865+
22866+#ifdef CONFIG_PAX_RANDKSTACK
22867+ pax_erase_kstack
22868+#endif
22869+
22870 /*
22871 * No need to follow this irqs off/on section - it's straight
22872 * and short:
22873 */
22874 ENABLE_INTERRUPTS(CLBR_NONE)
22875- SAVE_ARGS 8,0
22876 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
22877 movq %rcx,RIP-ARGOFFSET(%rsp)
22878 CFI_REL_OFFSET rip,RIP-ARGOFFSET
22879- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
22880+ GET_THREAD_INFO(%rcx)
22881+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
22882 jnz tracesys
22883 system_call_fastpath:
22884 #if __SYSCALL_MASK == ~0
22885@@ -639,10 +1112,13 @@ sysret_check:
22886 LOCKDEP_SYS_EXIT
22887 DISABLE_INTERRUPTS(CLBR_NONE)
22888 TRACE_IRQS_OFF
22889- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
22890+ GET_THREAD_INFO(%rcx)
22891+ movl TI_flags(%rcx),%edx
22892 andl %edi,%edx
22893 jnz sysret_careful
22894 CFI_REMEMBER_STATE
22895+ pax_exit_kernel_user
22896+ pax_erase_kstack
22897 /*
22898 * sysretq will re-enable interrupts:
22899 */
22900@@ -701,6 +1177,9 @@ auditsys:
22901 movq %rax,%rsi /* 2nd arg: syscall number */
22902 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
22903 call __audit_syscall_entry
22904+
22905+ pax_erase_kstack
22906+
22907 LOAD_ARGS 0 /* reload call-clobbered registers */
22908 jmp system_call_fastpath
22909
22910@@ -722,7 +1201,7 @@ sysret_audit:
22911 /* Do syscall tracing */
22912 tracesys:
22913 #ifdef CONFIG_AUDITSYSCALL
22914- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
22915+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
22916 jz auditsys
22917 #endif
22918 SAVE_REST
22919@@ -730,12 +1209,15 @@ tracesys:
22920 FIXUP_TOP_OF_STACK %rdi
22921 movq %rsp,%rdi
22922 call syscall_trace_enter
22923+
22924+ pax_erase_kstack
22925+
22926 /*
22927 * Reload arg registers from stack in case ptrace changed them.
22928 * We don't reload %rax because syscall_trace_enter() returned
22929 * the value it wants us to use in the table lookup.
22930 */
22931- LOAD_ARGS ARGOFFSET, 1
22932+ LOAD_ARGS 1
22933 RESTORE_REST
22934 #if __SYSCALL_MASK == ~0
22935 cmpq $__NR_syscall_max,%rax
22936@@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
22937 andl %edi,%edx
22938 jnz int_careful
22939 andl $~TS_COMPAT,TI_status(%rcx)
22940- jmp retint_swapgs
22941+ pax_exit_kernel_user
22942+ pax_erase_kstack
22943+ jmp retint_swapgs_pax
22944
22945 /* Either reschedule or signal or syscall exit tracking needed. */
22946 /* First do a reschedule test. */
22947@@ -811,7 +1295,7 @@ int_restore_rest:
22948 TRACE_IRQS_OFF
22949 jmp int_with_check
22950 CFI_ENDPROC
22951-END(system_call)
22952+ENDPROC(system_call)
22953
22954 .macro FORK_LIKE func
22955 ENTRY(stub_\func)
22956@@ -824,9 +1308,10 @@ ENTRY(stub_\func)
22957 DEFAULT_FRAME 0 8 /* offset 8: return address */
22958 call sys_\func
22959 RESTORE_TOP_OF_STACK %r11, 8
22960- ret $REST_SKIP /* pop extended registers */
22961+ pax_force_retaddr
22962+ ret
22963 CFI_ENDPROC
22964-END(stub_\func)
22965+ENDPROC(stub_\func)
22966 .endm
22967
22968 .macro FIXED_FRAME label,func
22969@@ -836,9 +1321,10 @@ ENTRY(\label)
22970 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
22971 call \func
22972 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
22973+ pax_force_retaddr
22974 ret
22975 CFI_ENDPROC
22976-END(\label)
22977+ENDPROC(\label)
22978 .endm
22979
22980 FORK_LIKE clone
22981@@ -846,19 +1332,6 @@ END(\label)
22982 FORK_LIKE vfork
22983 FIXED_FRAME stub_iopl, sys_iopl
22984
22985-ENTRY(ptregscall_common)
22986- DEFAULT_FRAME 1 8 /* offset 8: return address */
22987- RESTORE_TOP_OF_STACK %r11, 8
22988- movq_cfi_restore R15+8, r15
22989- movq_cfi_restore R14+8, r14
22990- movq_cfi_restore R13+8, r13
22991- movq_cfi_restore R12+8, r12
22992- movq_cfi_restore RBP+8, rbp
22993- movq_cfi_restore RBX+8, rbx
22994- ret $REST_SKIP /* pop extended registers */
22995- CFI_ENDPROC
22996-END(ptregscall_common)
22997-
22998 ENTRY(stub_execve)
22999 CFI_STARTPROC
23000 addq $8, %rsp
23001@@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23002 RESTORE_REST
23003 jmp int_ret_from_sys_call
23004 CFI_ENDPROC
23005-END(stub_execve)
23006+ENDPROC(stub_execve)
23007
23008 /*
23009 * sigreturn is special because it needs to restore all registers on return.
23010@@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23011 RESTORE_REST
23012 jmp int_ret_from_sys_call
23013 CFI_ENDPROC
23014-END(stub_rt_sigreturn)
23015+ENDPROC(stub_rt_sigreturn)
23016
23017 #ifdef CONFIG_X86_X32_ABI
23018 ENTRY(stub_x32_rt_sigreturn)
23019@@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23020 RESTORE_REST
23021 jmp int_ret_from_sys_call
23022 CFI_ENDPROC
23023-END(stub_x32_rt_sigreturn)
23024+ENDPROC(stub_x32_rt_sigreturn)
23025
23026 ENTRY(stub_x32_execve)
23027 CFI_STARTPROC
23028@@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23029 RESTORE_REST
23030 jmp int_ret_from_sys_call
23031 CFI_ENDPROC
23032-END(stub_x32_execve)
23033+ENDPROC(stub_x32_execve)
23034
23035 #endif
23036
23037@@ -952,7 +1425,7 @@ vector=vector+1
23038 2: jmp common_interrupt
23039 .endr
23040 CFI_ENDPROC
23041-END(irq_entries_start)
23042+ENDPROC(irq_entries_start)
23043
23044 .previous
23045 END(interrupt)
23046@@ -969,8 +1442,8 @@ END(interrupt)
23047 /* 0(%rsp): ~(interrupt number) */
23048 .macro interrupt func
23049 /* reserve pt_regs for scratch regs and rbp */
23050- subq $ORIG_RAX-RBP, %rsp
23051- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23052+ subq $ORIG_RAX, %rsp
23053+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
23054 SAVE_ARGS_IRQ
23055 call \func
23056 .endm
23057@@ -997,14 +1470,14 @@ ret_from_intr:
23058
23059 /* Restore saved previous stack */
23060 popq %rsi
23061- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23062- leaq ARGOFFSET-RBP(%rsi), %rsp
23063+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23064+ movq %rsi, %rsp
23065 CFI_DEF_CFA_REGISTER rsp
23066- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23067+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23068
23069 exit_intr:
23070 GET_THREAD_INFO(%rcx)
23071- testl $3,CS-ARGOFFSET(%rsp)
23072+ testb $3,CS-ARGOFFSET(%rsp)
23073 je retint_kernel
23074
23075 /* Interrupt came from user space */
23076@@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
23077 * The iretq could re-enable interrupts:
23078 */
23079 DISABLE_INTERRUPTS(CLBR_ANY)
23080+ pax_exit_kernel_user
23081+retint_swapgs_pax:
23082 TRACE_IRQS_IRETQ
23083 SWAPGS
23084 jmp restore_args
23085
23086 retint_restore_args: /* return to kernel space */
23087 DISABLE_INTERRUPTS(CLBR_ANY)
23088+ pax_exit_kernel
23089+ pax_force_retaddr (RIP-ARGOFFSET)
23090 /*
23091 * The iretq could re-enable interrupts:
23092 */
23093@@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
23094 #endif
23095
23096 CFI_ENDPROC
23097-END(common_interrupt)
23098+ENDPROC(common_interrupt)
23099 /*
23100 * End of kprobes section
23101 */
23102@@ -1130,7 +1607,7 @@ ENTRY(\sym)
23103 interrupt \do_sym
23104 jmp ret_from_intr
23105 CFI_ENDPROC
23106-END(\sym)
23107+ENDPROC(\sym)
23108 .endm
23109
23110 #ifdef CONFIG_TRACING
23111@@ -1218,7 +1695,7 @@ ENTRY(\sym)
23112 call \do_sym
23113 jmp error_exit /* %ebx: no swapgs flag */
23114 CFI_ENDPROC
23115-END(\sym)
23116+ENDPROC(\sym)
23117 .endm
23118
23119 .macro paranoidzeroentry sym do_sym
23120@@ -1236,10 +1713,10 @@ ENTRY(\sym)
23121 call \do_sym
23122 jmp paranoid_exit /* %ebx: no swapgs flag */
23123 CFI_ENDPROC
23124-END(\sym)
23125+ENDPROC(\sym)
23126 .endm
23127
23128-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23129+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23130 .macro paranoidzeroentry_ist sym do_sym ist
23131 ENTRY(\sym)
23132 INTR_FRAME
23133@@ -1252,12 +1729,18 @@ ENTRY(\sym)
23134 TRACE_IRQS_OFF_DEBUG
23135 movq %rsp,%rdi /* pt_regs pointer */
23136 xorl %esi,%esi /* no error code */
23137+#ifdef CONFIG_SMP
23138+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23139+ lea init_tss(%r13), %r13
23140+#else
23141+ lea init_tss(%rip), %r13
23142+#endif
23143 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23144 call \do_sym
23145 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23146 jmp paranoid_exit /* %ebx: no swapgs flag */
23147 CFI_ENDPROC
23148-END(\sym)
23149+ENDPROC(\sym)
23150 .endm
23151
23152 .macro errorentry sym do_sym
23153@@ -1275,7 +1758,7 @@ ENTRY(\sym)
23154 call \do_sym
23155 jmp error_exit /* %ebx: no swapgs flag */
23156 CFI_ENDPROC
23157-END(\sym)
23158+ENDPROC(\sym)
23159 .endm
23160
23161 #ifdef CONFIG_TRACING
23162@@ -1306,7 +1789,7 @@ ENTRY(\sym)
23163 call \do_sym
23164 jmp paranoid_exit /* %ebx: no swapgs flag */
23165 CFI_ENDPROC
23166-END(\sym)
23167+ENDPROC(\sym)
23168 .endm
23169
23170 zeroentry divide_error do_divide_error
23171@@ -1336,9 +1819,10 @@ gs_change:
23172 2: mfence /* workaround */
23173 SWAPGS
23174 popfq_cfi
23175+ pax_force_retaddr
23176 ret
23177 CFI_ENDPROC
23178-END(native_load_gs_index)
23179+ENDPROC(native_load_gs_index)
23180
23181 _ASM_EXTABLE(gs_change,bad_gs)
23182 .section .fixup,"ax"
23183@@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
23184 CFI_DEF_CFA_REGISTER rsp
23185 CFI_ADJUST_CFA_OFFSET -8
23186 decl PER_CPU_VAR(irq_count)
23187+ pax_force_retaddr
23188 ret
23189 CFI_ENDPROC
23190-END(do_softirq_own_stack)
23191+ENDPROC(do_softirq_own_stack)
23192
23193 #ifdef CONFIG_XEN
23194 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23195@@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23196 decl PER_CPU_VAR(irq_count)
23197 jmp error_exit
23198 CFI_ENDPROC
23199-END(xen_do_hypervisor_callback)
23200+ENDPROC(xen_do_hypervisor_callback)
23201
23202 /*
23203 * Hypervisor uses this for application faults while it executes.
23204@@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
23205 SAVE_ALL
23206 jmp error_exit
23207 CFI_ENDPROC
23208-END(xen_failsafe_callback)
23209+ENDPROC(xen_failsafe_callback)
23210
23211 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23212 xen_hvm_callback_vector xen_evtchn_do_upcall
23213@@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
23214 DEFAULT_FRAME
23215 DISABLE_INTERRUPTS(CLBR_NONE)
23216 TRACE_IRQS_OFF_DEBUG
23217- testl %ebx,%ebx /* swapgs needed? */
23218+ testl $1,%ebx /* swapgs needed? */
23219 jnz paranoid_restore
23220- testl $3,CS(%rsp)
23221+ testb $3,CS(%rsp)
23222 jnz paranoid_userspace
23223+#ifdef CONFIG_PAX_MEMORY_UDEREF
23224+ pax_exit_kernel
23225+ TRACE_IRQS_IRETQ 0
23226+ SWAPGS_UNSAFE_STACK
23227+ RESTORE_ALL 8
23228+ pax_force_retaddr_bts
23229+ jmp irq_return
23230+#endif
23231 paranoid_swapgs:
23232+#ifdef CONFIG_PAX_MEMORY_UDEREF
23233+ pax_exit_kernel_user
23234+#else
23235+ pax_exit_kernel
23236+#endif
23237 TRACE_IRQS_IRETQ 0
23238 SWAPGS_UNSAFE_STACK
23239 RESTORE_ALL 8
23240 jmp irq_return
23241 paranoid_restore:
23242+ pax_exit_kernel
23243 TRACE_IRQS_IRETQ_DEBUG 0
23244 RESTORE_ALL 8
23245+ pax_force_retaddr_bts
23246 jmp irq_return
23247 paranoid_userspace:
23248 GET_THREAD_INFO(%rcx)
23249@@ -1557,7 +2057,7 @@ paranoid_schedule:
23250 TRACE_IRQS_OFF
23251 jmp paranoid_userspace
23252 CFI_ENDPROC
23253-END(paranoid_exit)
23254+ENDPROC(paranoid_exit)
23255
23256 /*
23257 * Exception entry point. This expects an error code/orig_rax on the stack.
23258@@ -1584,12 +2084,23 @@ ENTRY(error_entry)
23259 movq_cfi r14, R14+8
23260 movq_cfi r15, R15+8
23261 xorl %ebx,%ebx
23262- testl $3,CS+8(%rsp)
23263+ testb $3,CS+8(%rsp)
23264 je error_kernelspace
23265 error_swapgs:
23266 SWAPGS
23267 error_sti:
23268+#ifdef CONFIG_PAX_MEMORY_UDEREF
23269+ testb $3, CS+8(%rsp)
23270+ jnz 1f
23271+ pax_enter_kernel
23272+ jmp 2f
23273+1: pax_enter_kernel_user
23274+2:
23275+#else
23276+ pax_enter_kernel
23277+#endif
23278 TRACE_IRQS_OFF
23279+ pax_force_retaddr
23280 ret
23281
23282 /*
23283@@ -1616,7 +2127,7 @@ bstep_iret:
23284 movq %rcx,RIP+8(%rsp)
23285 jmp error_swapgs
23286 CFI_ENDPROC
23287-END(error_entry)
23288+ENDPROC(error_entry)
23289
23290
23291 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23292@@ -1627,7 +2138,7 @@ ENTRY(error_exit)
23293 DISABLE_INTERRUPTS(CLBR_NONE)
23294 TRACE_IRQS_OFF
23295 GET_THREAD_INFO(%rcx)
23296- testl %eax,%eax
23297+ testl $1,%eax
23298 jne retint_kernel
23299 LOCKDEP_SYS_EXIT_IRQ
23300 movl TI_flags(%rcx),%edx
23301@@ -1636,7 +2147,7 @@ ENTRY(error_exit)
23302 jnz retint_careful
23303 jmp retint_swapgs
23304 CFI_ENDPROC
23305-END(error_exit)
23306+ENDPROC(error_exit)
23307
23308 /*
23309 * Test if a given stack is an NMI stack or not.
23310@@ -1694,9 +2205,11 @@ ENTRY(nmi)
23311 * If %cs was not the kernel segment, then the NMI triggered in user
23312 * space, which means it is definitely not nested.
23313 */
23314+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23315+ je 1f
23316 cmpl $__KERNEL_CS, 16(%rsp)
23317 jne first_nmi
23318-
23319+1:
23320 /*
23321 * Check the special variable on the stack to see if NMIs are
23322 * executing.
23323@@ -1730,8 +2243,7 @@ nested_nmi:
23324
23325 1:
23326 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23327- leaq -1*8(%rsp), %rdx
23328- movq %rdx, %rsp
23329+ subq $8, %rsp
23330 CFI_ADJUST_CFA_OFFSET 1*8
23331 leaq -10*8(%rsp), %rdx
23332 pushq_cfi $__KERNEL_DS
23333@@ -1749,6 +2261,7 @@ nested_nmi_out:
23334 CFI_RESTORE rdx
23335
23336 /* No need to check faults here */
23337+# pax_force_retaddr_bts
23338 INTERRUPT_RETURN
23339
23340 CFI_RESTORE_STATE
23341@@ -1845,13 +2358,13 @@ end_repeat_nmi:
23342 subq $ORIG_RAX-R15, %rsp
23343 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23344 /*
23345- * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
23346+ * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
23347 * as we should not be calling schedule in NMI context.
23348 * Even with normal interrupts enabled. An NMI should not be
23349 * setting NEED_RESCHED or anything that normal interrupts and
23350 * exceptions might do.
23351 */
23352- call save_paranoid
23353+ call save_paranoid_nmi
23354 DEFAULT_FRAME 0
23355
23356 /*
23357@@ -1861,9 +2374,9 @@ end_repeat_nmi:
23358 * NMI itself takes a page fault, the page fault that was preempted
23359 * will read the information from the NMI page fault and not the
23360 * origin fault. Save it off and restore it if it changes.
23361- * Use the r12 callee-saved register.
23362+ * Use the r13 callee-saved register.
23363 */
23364- movq %cr2, %r12
23365+ movq %cr2, %r13
23366
23367 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
23368 movq %rsp,%rdi
23369@@ -1872,31 +2385,36 @@ end_repeat_nmi:
23370
23371 /* Did the NMI take a page fault? Restore cr2 if it did */
23372 movq %cr2, %rcx
23373- cmpq %rcx, %r12
23374+ cmpq %rcx, %r13
23375 je 1f
23376- movq %r12, %cr2
23377+ movq %r13, %cr2
23378 1:
23379
23380- testl %ebx,%ebx /* swapgs needed? */
23381+ testl $1,%ebx /* swapgs needed? */
23382 jnz nmi_restore
23383 nmi_swapgs:
23384 SWAPGS_UNSAFE_STACK
23385 nmi_restore:
23386+ pax_exit_kernel_nmi
23387 /* Pop the extra iret frame at once */
23388 RESTORE_ALL 6*8
23389+ testb $3, 8(%rsp)
23390+ jnz 1f
23391+ pax_force_retaddr_bts
23392+1:
23393
23394 /* Clear the NMI executing stack variable */
23395 movq $0, 5*8(%rsp)
23396 jmp irq_return
23397 CFI_ENDPROC
23398-END(nmi)
23399+ENDPROC(nmi)
23400
23401 ENTRY(ignore_sysret)
23402 CFI_STARTPROC
23403 mov $-ENOSYS,%eax
23404 sysret
23405 CFI_ENDPROC
23406-END(ignore_sysret)
23407+ENDPROC(ignore_sysret)
23408
23409 /*
23410 * End of kprobes section
23411diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
23412index d4bdd25..912664c 100644
23413--- a/arch/x86/kernel/ftrace.c
23414+++ b/arch/x86/kernel/ftrace.c
23415@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
23416 {
23417 unsigned char replaced[MCOUNT_INSN_SIZE];
23418
23419+ ip = ktla_ktva(ip);
23420+
23421 /*
23422 * Note: Due to modules and __init, code can
23423 * disappear and change, we need to protect against faulting
23424@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
23425 unsigned char old[MCOUNT_INSN_SIZE], *new;
23426 int ret;
23427
23428- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
23429+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
23430 new = ftrace_call_replace(ip, (unsigned long)func);
23431
23432 /* See comment above by declaration of modifying_ftrace_code */
23433@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
23434 /* Also update the regs callback function */
23435 if (!ret) {
23436 ip = (unsigned long)(&ftrace_regs_call);
23437- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
23438+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
23439 new = ftrace_call_replace(ip, (unsigned long)func);
23440 ret = ftrace_modify_code(ip, old, new);
23441 }
23442@@ -291,7 +293,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
23443 * kernel identity mapping to modify code.
23444 */
23445 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
23446- ip = (unsigned long)__va(__pa_symbol(ip));
23447+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
23448
23449 return probe_kernel_write((void *)ip, val, size);
23450 }
23451@@ -301,7 +303,7 @@ static int add_break(unsigned long ip, const char *old)
23452 unsigned char replaced[MCOUNT_INSN_SIZE];
23453 unsigned char brk = BREAKPOINT_INSTRUCTION;
23454
23455- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
23456+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
23457 return -EFAULT;
23458
23459 /* Make sure it is what we expect it to be */
23460@@ -649,7 +651,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
23461 return ret;
23462
23463 fail_update:
23464- probe_kernel_write((void *)ip, &old_code[0], 1);
23465+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
23466 goto out;
23467 }
23468
23469@@ -682,6 +684,8 @@ static int ftrace_mod_jmp(unsigned long ip,
23470 {
23471 unsigned char code[MCOUNT_INSN_SIZE];
23472
23473+ ip = ktla_ktva(ip);
23474+
23475 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
23476 return -EFAULT;
23477
23478diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
23479index 85126cc..1bbce17 100644
23480--- a/arch/x86/kernel/head64.c
23481+++ b/arch/x86/kernel/head64.c
23482@@ -67,12 +67,12 @@ again:
23483 pgd = *pgd_p;
23484
23485 /*
23486- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
23487- * critical -- __PAGE_OFFSET would point us back into the dynamic
23488+ * The use of __early_va rather than __va here is critical:
23489+ * __va would point us back into the dynamic
23490 * range and we might end up looping forever...
23491 */
23492 if (pgd)
23493- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23494+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
23495 else {
23496 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23497 reset_early_page_tables();
23498@@ -82,13 +82,13 @@ again:
23499 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
23500 for (i = 0; i < PTRS_PER_PUD; i++)
23501 pud_p[i] = 0;
23502- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
23503+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
23504 }
23505 pud_p += pud_index(address);
23506 pud = *pud_p;
23507
23508 if (pud)
23509- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23510+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
23511 else {
23512 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23513 reset_early_page_tables();
23514@@ -98,7 +98,7 @@ again:
23515 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
23516 for (i = 0; i < PTRS_PER_PMD; i++)
23517 pmd_p[i] = 0;
23518- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
23519+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
23520 }
23521 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
23522 pmd_p[pmd_index(address)] = pmd;
23523@@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
23524 if (console_loglevel == 10)
23525 early_printk("Kernel alive\n");
23526
23527- clear_page(init_level4_pgt);
23528 /* set init_level4_pgt kernel high mapping*/
23529 init_level4_pgt[511] = early_level4_pgt[511];
23530
23531diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
23532index 81ba276..30c5411 100644
23533--- a/arch/x86/kernel/head_32.S
23534+++ b/arch/x86/kernel/head_32.S
23535@@ -26,6 +26,12 @@
23536 /* Physical address */
23537 #define pa(X) ((X) - __PAGE_OFFSET)
23538
23539+#ifdef CONFIG_PAX_KERNEXEC
23540+#define ta(X) (X)
23541+#else
23542+#define ta(X) ((X) - __PAGE_OFFSET)
23543+#endif
23544+
23545 /*
23546 * References to members of the new_cpu_data structure.
23547 */
23548@@ -55,11 +61,7 @@
23549 * and small than max_low_pfn, otherwise will waste some page table entries
23550 */
23551
23552-#if PTRS_PER_PMD > 1
23553-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
23554-#else
23555-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
23556-#endif
23557+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
23558
23559 /* Number of possible pages in the lowmem region */
23560 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
23561@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
23562 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
23563
23564 /*
23565+ * Real beginning of normal "text" segment
23566+ */
23567+ENTRY(stext)
23568+ENTRY(_stext)
23569+
23570+/*
23571 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
23572 * %esi points to the real-mode code as a 32-bit pointer.
23573 * CS and DS must be 4 GB flat segments, but we don't depend on
23574@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
23575 * can.
23576 */
23577 __HEAD
23578+
23579+#ifdef CONFIG_PAX_KERNEXEC
23580+ jmp startup_32
23581+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
23582+.fill PAGE_SIZE-5,1,0xcc
23583+#endif
23584+
23585 ENTRY(startup_32)
23586 movl pa(stack_start),%ecx
23587
23588@@ -106,6 +121,59 @@ ENTRY(startup_32)
23589 2:
23590 leal -__PAGE_OFFSET(%ecx),%esp
23591
23592+#ifdef CONFIG_SMP
23593+ movl $pa(cpu_gdt_table),%edi
23594+ movl $__per_cpu_load,%eax
23595+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
23596+ rorl $16,%eax
23597+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
23598+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
23599+ movl $__per_cpu_end - 1,%eax
23600+ subl $__per_cpu_start,%eax
23601+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
23602+#endif
23603+
23604+#ifdef CONFIG_PAX_MEMORY_UDEREF
23605+ movl $NR_CPUS,%ecx
23606+ movl $pa(cpu_gdt_table),%edi
23607+1:
23608+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
23609+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
23610+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
23611+ addl $PAGE_SIZE_asm,%edi
23612+ loop 1b
23613+#endif
23614+
23615+#ifdef CONFIG_PAX_KERNEXEC
23616+ movl $pa(boot_gdt),%edi
23617+ movl $__LOAD_PHYSICAL_ADDR,%eax
23618+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
23619+ rorl $16,%eax
23620+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
23621+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
23622+ rorl $16,%eax
23623+
23624+ ljmp $(__BOOT_CS),$1f
23625+1:
23626+
23627+ movl $NR_CPUS,%ecx
23628+ movl $pa(cpu_gdt_table),%edi
23629+ addl $__PAGE_OFFSET,%eax
23630+1:
23631+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
23632+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
23633+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
23634+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
23635+ rorl $16,%eax
23636+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
23637+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
23638+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
23639+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
23640+ rorl $16,%eax
23641+ addl $PAGE_SIZE_asm,%edi
23642+ loop 1b
23643+#endif
23644+
23645 /*
23646 * Clear BSS first so that there are no surprises...
23647 */
23648@@ -201,8 +269,11 @@ ENTRY(startup_32)
23649 movl %eax, pa(max_pfn_mapped)
23650
23651 /* Do early initialization of the fixmap area */
23652- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
23653- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
23654+#ifdef CONFIG_COMPAT_VDSO
23655+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
23656+#else
23657+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
23658+#endif
23659 #else /* Not PAE */
23660
23661 page_pde_offset = (__PAGE_OFFSET >> 20);
23662@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
23663 movl %eax, pa(max_pfn_mapped)
23664
23665 /* Do early initialization of the fixmap area */
23666- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
23667- movl %eax,pa(initial_page_table+0xffc)
23668+#ifdef CONFIG_COMPAT_VDSO
23669+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
23670+#else
23671+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
23672+#endif
23673 #endif
23674
23675 #ifdef CONFIG_PARAVIRT
23676@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
23677 cmpl $num_subarch_entries, %eax
23678 jae bad_subarch
23679
23680- movl pa(subarch_entries)(,%eax,4), %eax
23681- subl $__PAGE_OFFSET, %eax
23682- jmp *%eax
23683+ jmp *pa(subarch_entries)(,%eax,4)
23684
23685 bad_subarch:
23686 WEAK(lguest_entry)
23687@@ -261,10 +333,10 @@ WEAK(xen_entry)
23688 __INITDATA
23689
23690 subarch_entries:
23691- .long default_entry /* normal x86/PC */
23692- .long lguest_entry /* lguest hypervisor */
23693- .long xen_entry /* Xen hypervisor */
23694- .long default_entry /* Moorestown MID */
23695+ .long ta(default_entry) /* normal x86/PC */
23696+ .long ta(lguest_entry) /* lguest hypervisor */
23697+ .long ta(xen_entry) /* Xen hypervisor */
23698+ .long ta(default_entry) /* Moorestown MID */
23699 num_subarch_entries = (. - subarch_entries) / 4
23700 .previous
23701 #else
23702@@ -354,6 +426,7 @@ default_entry:
23703 movl pa(mmu_cr4_features),%eax
23704 movl %eax,%cr4
23705
23706+#ifdef CONFIG_X86_PAE
23707 testb $X86_CR4_PAE, %al # check if PAE is enabled
23708 jz enable_paging
23709
23710@@ -382,6 +455,9 @@ default_entry:
23711 /* Make changes effective */
23712 wrmsr
23713
23714+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
23715+#endif
23716+
23717 enable_paging:
23718
23719 /*
23720@@ -449,14 +525,20 @@ is486:
23721 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
23722 movl %eax,%ss # after changing gdt.
23723
23724- movl $(__USER_DS),%eax # DS/ES contains default USER segment
23725+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
23726 movl %eax,%ds
23727 movl %eax,%es
23728
23729 movl $(__KERNEL_PERCPU), %eax
23730 movl %eax,%fs # set this cpu's percpu
23731
23732+#ifdef CONFIG_CC_STACKPROTECTOR
23733 movl $(__KERNEL_STACK_CANARY),%eax
23734+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
23735+ movl $(__USER_DS),%eax
23736+#else
23737+ xorl %eax,%eax
23738+#endif
23739 movl %eax,%gs
23740
23741 xorl %eax,%eax # Clear LDT
23742@@ -512,8 +594,11 @@ setup_once:
23743 * relocation. Manually set base address in stack canary
23744 * segment descriptor.
23745 */
23746- movl $gdt_page,%eax
23747+ movl $cpu_gdt_table,%eax
23748 movl $stack_canary,%ecx
23749+#ifdef CONFIG_SMP
23750+ addl $__per_cpu_load,%ecx
23751+#endif
23752 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
23753 shrl $16, %ecx
23754 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
23755@@ -544,7 +629,7 @@ ENDPROC(early_idt_handlers)
23756 /* This is global to keep gas from relaxing the jumps */
23757 ENTRY(early_idt_handler)
23758 cld
23759- cmpl $2,%ss:early_recursion_flag
23760+ cmpl $1,%ss:early_recursion_flag
23761 je hlt_loop
23762 incl %ss:early_recursion_flag
23763
23764@@ -582,8 +667,8 @@ ENTRY(early_idt_handler)
23765 pushl (20+6*4)(%esp) /* trapno */
23766 pushl $fault_msg
23767 call printk
23768-#endif
23769 call dump_stack
23770+#endif
23771 hlt_loop:
23772 hlt
23773 jmp hlt_loop
23774@@ -602,8 +687,11 @@ ENDPROC(early_idt_handler)
23775 /* This is the default interrupt "handler" :-) */
23776 ALIGN
23777 ignore_int:
23778- cld
23779 #ifdef CONFIG_PRINTK
23780+ cmpl $2,%ss:early_recursion_flag
23781+ je hlt_loop
23782+ incl %ss:early_recursion_flag
23783+ cld
23784 pushl %eax
23785 pushl %ecx
23786 pushl %edx
23787@@ -612,9 +700,6 @@ ignore_int:
23788 movl $(__KERNEL_DS),%eax
23789 movl %eax,%ds
23790 movl %eax,%es
23791- cmpl $2,early_recursion_flag
23792- je hlt_loop
23793- incl early_recursion_flag
23794 pushl 16(%esp)
23795 pushl 24(%esp)
23796 pushl 32(%esp)
23797@@ -648,29 +733,34 @@ ENTRY(setup_once_ref)
23798 /*
23799 * BSS section
23800 */
23801-__PAGE_ALIGNED_BSS
23802- .align PAGE_SIZE
23803 #ifdef CONFIG_X86_PAE
23804+.section .initial_pg_pmd,"a",@progbits
23805 initial_pg_pmd:
23806 .fill 1024*KPMDS,4,0
23807 #else
23808+.section .initial_page_table,"a",@progbits
23809 ENTRY(initial_page_table)
23810 .fill 1024,4,0
23811 #endif
23812+.section .initial_pg_fixmap,"a",@progbits
23813 initial_pg_fixmap:
23814 .fill 1024,4,0
23815+.section .empty_zero_page,"a",@progbits
23816 ENTRY(empty_zero_page)
23817 .fill 4096,1,0
23818+.section .swapper_pg_dir,"a",@progbits
23819 ENTRY(swapper_pg_dir)
23820+#ifdef CONFIG_X86_PAE
23821+ .fill 4,8,0
23822+#else
23823 .fill 1024,4,0
23824+#endif
23825
23826 /*
23827 * This starts the data section.
23828 */
23829 #ifdef CONFIG_X86_PAE
23830-__PAGE_ALIGNED_DATA
23831- /* Page-aligned for the benefit of paravirt? */
23832- .align PAGE_SIZE
23833+.section .initial_page_table,"a",@progbits
23834 ENTRY(initial_page_table)
23835 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
23836 # if KPMDS == 3
23837@@ -689,12 +779,20 @@ ENTRY(initial_page_table)
23838 # error "Kernel PMDs should be 1, 2 or 3"
23839 # endif
23840 .align PAGE_SIZE /* needs to be page-sized too */
23841+
23842+#ifdef CONFIG_PAX_PER_CPU_PGD
23843+ENTRY(cpu_pgd)
23844+ .rept 2*NR_CPUS
23845+ .fill 4,8,0
23846+ .endr
23847+#endif
23848+
23849 #endif
23850
23851 .data
23852 .balign 4
23853 ENTRY(stack_start)
23854- .long init_thread_union+THREAD_SIZE
23855+ .long init_thread_union+THREAD_SIZE-8
23856
23857 __INITRODATA
23858 int_msg:
23859@@ -722,7 +820,7 @@ fault_msg:
23860 * segment size, and 32-bit linear address value:
23861 */
23862
23863- .data
23864+.section .rodata,"a",@progbits
23865 .globl boot_gdt_descr
23866 .globl idt_descr
23867
23868@@ -731,7 +829,7 @@ fault_msg:
23869 .word 0 # 32 bit align gdt_desc.address
23870 boot_gdt_descr:
23871 .word __BOOT_DS+7
23872- .long boot_gdt - __PAGE_OFFSET
23873+ .long pa(boot_gdt)
23874
23875 .word 0 # 32-bit align idt_desc.address
23876 idt_descr:
23877@@ -742,7 +840,7 @@ idt_descr:
23878 .word 0 # 32 bit align gdt_desc.address
23879 ENTRY(early_gdt_descr)
23880 .word GDT_ENTRIES*8-1
23881- .long gdt_page /* Overwritten for secondary CPUs */
23882+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
23883
23884 /*
23885 * The boot_gdt must mirror the equivalent in setup.S and is
23886@@ -751,5 +849,65 @@ ENTRY(early_gdt_descr)
23887 .align L1_CACHE_BYTES
23888 ENTRY(boot_gdt)
23889 .fill GDT_ENTRY_BOOT_CS,8,0
23890- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
23891- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
23892+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
23893+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
23894+
23895+ .align PAGE_SIZE_asm
23896+ENTRY(cpu_gdt_table)
23897+ .rept NR_CPUS
23898+ .quad 0x0000000000000000 /* NULL descriptor */
23899+ .quad 0x0000000000000000 /* 0x0b reserved */
23900+ .quad 0x0000000000000000 /* 0x13 reserved */
23901+ .quad 0x0000000000000000 /* 0x1b reserved */
23902+
23903+#ifdef CONFIG_PAX_KERNEXEC
23904+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
23905+#else
23906+ .quad 0x0000000000000000 /* 0x20 unused */
23907+#endif
23908+
23909+ .quad 0x0000000000000000 /* 0x28 unused */
23910+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
23911+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
23912+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
23913+ .quad 0x0000000000000000 /* 0x4b reserved */
23914+ .quad 0x0000000000000000 /* 0x53 reserved */
23915+ .quad 0x0000000000000000 /* 0x5b reserved */
23916+
23917+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
23918+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
23919+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
23920+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
23921+
23922+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
23923+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
23924+
23925+ /*
23926+ * Segments used for calling PnP BIOS have byte granularity.
23927+ * The code segments and data segments have fixed 64k limits,
23928+ * the transfer segment sizes are set at run time.
23929+ */
23930+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
23931+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
23932+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
23933+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
23934+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
23935+
23936+ /*
23937+ * The APM segments have byte granularity and their bases
23938+ * are set at run time. All have 64k limits.
23939+ */
23940+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
23941+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
23942+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
23943+
23944+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
23945+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
23946+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
23947+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
23948+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
23949+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
23950+
23951+ /* Be sure this is zeroed to avoid false validations in Xen */
23952+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
23953+ .endr
23954diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
23955index e1aabdb..fee4fee 100644
23956--- a/arch/x86/kernel/head_64.S
23957+++ b/arch/x86/kernel/head_64.S
23958@@ -20,6 +20,8 @@
23959 #include <asm/processor-flags.h>
23960 #include <asm/percpu.h>
23961 #include <asm/nops.h>
23962+#include <asm/cpufeature.h>
23963+#include <asm/alternative-asm.h>
23964
23965 #ifdef CONFIG_PARAVIRT
23966 #include <asm/asm-offsets.h>
23967@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
23968 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
23969 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
23970 L3_START_KERNEL = pud_index(__START_KERNEL_map)
23971+L4_VMALLOC_START = pgd_index(VMALLOC_START)
23972+L3_VMALLOC_START = pud_index(VMALLOC_START)
23973+L4_VMALLOC_END = pgd_index(VMALLOC_END)
23974+L3_VMALLOC_END = pud_index(VMALLOC_END)
23975+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
23976+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
23977
23978 .text
23979 __HEAD
23980@@ -89,11 +97,24 @@ startup_64:
23981 * Fixup the physical addresses in the page table
23982 */
23983 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
23984+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
23985+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
23986+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
23987+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
23988+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
23989
23990- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
23991- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
23992+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
23993+#ifndef CONFIG_XEN
23994+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
23995+#endif
23996+
23997+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
23998+
23999+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24000+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24001
24002 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24003+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24004
24005 /*
24006 * Set up the identity mapping for the switchover. These
24007@@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24008 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24009 1:
24010
24011- /* Enable PAE mode and PGE */
24012- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24013+ /* Enable PAE mode and PSE/PGE */
24014+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24015 movq %rcx, %cr4
24016
24017 /* Setup early boot stage 4 level pagetables. */
24018@@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24019 movl $MSR_EFER, %ecx
24020 rdmsr
24021 btsl $_EFER_SCE, %eax /* Enable System Call */
24022- btl $20,%edi /* No Execute supported? */
24023+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24024 jnc 1f
24025 btsl $_EFER_NX, %eax
24026 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24027+#ifndef CONFIG_EFI
24028+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24029+#endif
24030+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24031+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24032+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24033+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24034+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24035+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24036 1: wrmsr /* Make changes effective */
24037
24038 /* Setup cr0 */
24039@@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24040 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24041 * address given in m16:64.
24042 */
24043+ pax_set_fptr_mask
24044 movq initial_code(%rip),%rax
24045 pushq $0 # fake return address to stop unwinder
24046 pushq $__KERNEL_CS # set correct cs
24047@@ -388,7 +419,7 @@ ENTRY(early_idt_handler)
24048 call dump_stack
24049 #ifdef CONFIG_KALLSYMS
24050 leaq early_idt_ripmsg(%rip),%rdi
24051- movq 40(%rsp),%rsi # %rip again
24052+ movq 88(%rsp),%rsi # %rip again
24053 call __print_symbol
24054 #endif
24055 #endif /* EARLY_PRINTK */
24056@@ -416,6 +447,7 @@ ENDPROC(early_idt_handler)
24057 early_recursion_flag:
24058 .long 0
24059
24060+ .section .rodata,"a",@progbits
24061 #ifdef CONFIG_EARLY_PRINTK
24062 early_idt_msg:
24063 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24064@@ -443,29 +475,52 @@ NEXT_PAGE(early_level4_pgt)
24065 NEXT_PAGE(early_dynamic_pgts)
24066 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24067
24068- .data
24069+ .section .rodata,"a",@progbits
24070
24071-#ifndef CONFIG_XEN
24072 NEXT_PAGE(init_level4_pgt)
24073- .fill 512,8,0
24074-#else
24075-NEXT_PAGE(init_level4_pgt)
24076- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24077 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24078 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24079+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
24080+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24081+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
24082+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24083+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24084+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24085 .org init_level4_pgt + L4_START_KERNEL*8, 0
24086 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24087 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24088
24089+#ifdef CONFIG_PAX_PER_CPU_PGD
24090+NEXT_PAGE(cpu_pgd)
24091+ .rept 2*NR_CPUS
24092+ .fill 512,8,0
24093+ .endr
24094+#endif
24095+
24096 NEXT_PAGE(level3_ident_pgt)
24097 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24098+#ifdef CONFIG_XEN
24099 .fill 511, 8, 0
24100+#else
24101+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24102+ .fill 510,8,0
24103+#endif
24104+
24105+NEXT_PAGE(level3_vmalloc_start_pgt)
24106+ .fill 512,8,0
24107+
24108+NEXT_PAGE(level3_vmalloc_end_pgt)
24109+ .fill 512,8,0
24110+
24111+NEXT_PAGE(level3_vmemmap_pgt)
24112+ .fill L3_VMEMMAP_START,8,0
24113+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24114+
24115 NEXT_PAGE(level2_ident_pgt)
24116- /* Since I easily can, map the first 1G.
24117+ /* Since I easily can, map the first 2G.
24118 * Don't set NX because code runs from these pages.
24119 */
24120- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24121-#endif
24122+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24123
24124 NEXT_PAGE(level3_kernel_pgt)
24125 .fill L3_START_KERNEL,8,0
24126@@ -473,6 +528,9 @@ NEXT_PAGE(level3_kernel_pgt)
24127 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24128 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24129
24130+NEXT_PAGE(level2_vmemmap_pgt)
24131+ .fill 512,8,0
24132+
24133 NEXT_PAGE(level2_kernel_pgt)
24134 /*
24135 * 512 MB kernel mapping. We spend a full page on this pagetable
24136@@ -490,28 +548,64 @@ NEXT_PAGE(level2_kernel_pgt)
24137 NEXT_PAGE(level2_fixmap_pgt)
24138 .fill 506,8,0
24139 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24140- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24141- .fill 5,8,0
24142+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24143+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24144+ .fill 4,8,0
24145
24146 NEXT_PAGE(level1_fixmap_pgt)
24147 .fill 512,8,0
24148
24149+NEXT_PAGE(level1_vsyscall_pgt)
24150+ .fill 512,8,0
24151+
24152 #undef PMDS
24153
24154- .data
24155+ .align PAGE_SIZE
24156+ENTRY(cpu_gdt_table)
24157+ .rept NR_CPUS
24158+ .quad 0x0000000000000000 /* NULL descriptor */
24159+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24160+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
24161+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
24162+ .quad 0x00cffb000000ffff /* __USER32_CS */
24163+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24164+ .quad 0x00affb000000ffff /* __USER_CS */
24165+
24166+#ifdef CONFIG_PAX_KERNEXEC
24167+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24168+#else
24169+ .quad 0x0 /* unused */
24170+#endif
24171+
24172+ .quad 0,0 /* TSS */
24173+ .quad 0,0 /* LDT */
24174+ .quad 0,0,0 /* three TLS descriptors */
24175+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
24176+ /* asm/segment.h:GDT_ENTRIES must match this */
24177+
24178+#ifdef CONFIG_PAX_MEMORY_UDEREF
24179+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24180+#else
24181+ .quad 0x0 /* unused */
24182+#endif
24183+
24184+ /* zero the remaining page */
24185+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24186+ .endr
24187+
24188 .align 16
24189 .globl early_gdt_descr
24190 early_gdt_descr:
24191 .word GDT_ENTRIES*8-1
24192 early_gdt_descr_base:
24193- .quad INIT_PER_CPU_VAR(gdt_page)
24194+ .quad cpu_gdt_table
24195
24196 ENTRY(phys_base)
24197 /* This must match the first entry in level2_kernel_pgt */
24198 .quad 0x0000000000000000
24199
24200 #include "../../x86/xen/xen-head.S"
24201-
24202- __PAGE_ALIGNED_BSS
24203+
24204+ .section .rodata,"a",@progbits
24205 NEXT_PAGE(empty_zero_page)
24206 .skip PAGE_SIZE
24207diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24208index 05fd74f..c3548b1 100644
24209--- a/arch/x86/kernel/i386_ksyms_32.c
24210+++ b/arch/x86/kernel/i386_ksyms_32.c
24211@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24212 EXPORT_SYMBOL(cmpxchg8b_emu);
24213 #endif
24214
24215+EXPORT_SYMBOL_GPL(cpu_gdt_table);
24216+
24217 /* Networking helper routines. */
24218 EXPORT_SYMBOL(csum_partial_copy_generic);
24219+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24220+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24221
24222 EXPORT_SYMBOL(__get_user_1);
24223 EXPORT_SYMBOL(__get_user_2);
24224@@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24225 EXPORT_SYMBOL(___preempt_schedule_context);
24226 #endif
24227 #endif
24228+
24229+#ifdef CONFIG_PAX_KERNEXEC
24230+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24231+#endif
24232+
24233+#ifdef CONFIG_PAX_PER_CPU_PGD
24234+EXPORT_SYMBOL(cpu_pgd);
24235+#endif
24236diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24237index e8368c6..9c1a712 100644
24238--- a/arch/x86/kernel/i387.c
24239+++ b/arch/x86/kernel/i387.c
24240@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24241 static inline bool interrupted_user_mode(void)
24242 {
24243 struct pt_regs *regs = get_irq_regs();
24244- return regs && user_mode_vm(regs);
24245+ return regs && user_mode(regs);
24246 }
24247
24248 /*
24249diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24250index 2e977b5..5f2c273 100644
24251--- a/arch/x86/kernel/i8259.c
24252+++ b/arch/x86/kernel/i8259.c
24253@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24254 static void make_8259A_irq(unsigned int irq)
24255 {
24256 disable_irq_nosync(irq);
24257- io_apic_irqs &= ~(1<<irq);
24258+ io_apic_irqs &= ~(1UL<<irq);
24259 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24260 i8259A_chip.name);
24261 enable_irq(irq);
24262@@ -209,7 +209,7 @@ spurious_8259A_irq:
24263 "spurious 8259A interrupt: IRQ%d.\n", irq);
24264 spurious_irq_mask |= irqmask;
24265 }
24266- atomic_inc(&irq_err_count);
24267+ atomic_inc_unchecked(&irq_err_count);
24268 /*
24269 * Theoretically we do not have to handle this IRQ,
24270 * but in Linux this does not cause problems and is
24271@@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24272 /* (slave's support for AEOI in flat mode is to be investigated) */
24273 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24274
24275+ pax_open_kernel();
24276 if (auto_eoi)
24277 /*
24278 * In AEOI mode we just have to mask the interrupt
24279 * when acking.
24280 */
24281- i8259A_chip.irq_mask_ack = disable_8259A_irq;
24282+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24283 else
24284- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24285+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24286+ pax_close_kernel();
24287
24288 udelay(100); /* wait for 8259A to initialize */
24289
24290diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24291index a979b5b..1d6db75 100644
24292--- a/arch/x86/kernel/io_delay.c
24293+++ b/arch/x86/kernel/io_delay.c
24294@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24295 * Quirk table for systems that misbehave (lock up, etc.) if port
24296 * 0x80 is used:
24297 */
24298-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24299+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24300 {
24301 .callback = dmi_io_delay_0xed_port,
24302 .ident = "Compaq Presario V6000",
24303diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24304index 4ddaf66..49d5c18 100644
24305--- a/arch/x86/kernel/ioport.c
24306+++ b/arch/x86/kernel/ioport.c
24307@@ -6,6 +6,7 @@
24308 #include <linux/sched.h>
24309 #include <linux/kernel.h>
24310 #include <linux/capability.h>
24311+#include <linux/security.h>
24312 #include <linux/errno.h>
24313 #include <linux/types.h>
24314 #include <linux/ioport.h>
24315@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24316 return -EINVAL;
24317 if (turn_on && !capable(CAP_SYS_RAWIO))
24318 return -EPERM;
24319+#ifdef CONFIG_GRKERNSEC_IO
24320+ if (turn_on && grsec_disable_privio) {
24321+ gr_handle_ioperm();
24322+ return -ENODEV;
24323+ }
24324+#endif
24325
24326 /*
24327 * If it's the first ioperm() call in this thread's lifetime, set the
24328@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24329 * because the ->io_bitmap_max value must match the bitmap
24330 * contents:
24331 */
24332- tss = &per_cpu(init_tss, get_cpu());
24333+ tss = init_tss + get_cpu();
24334
24335 if (turn_on)
24336 bitmap_clear(t->io_bitmap_ptr, from, num);
24337@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24338 if (level > old) {
24339 if (!capable(CAP_SYS_RAWIO))
24340 return -EPERM;
24341+#ifdef CONFIG_GRKERNSEC_IO
24342+ if (grsec_disable_privio) {
24343+ gr_handle_iopl();
24344+ return -ENODEV;
24345+ }
24346+#endif
24347 }
24348 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24349 t->iopl = level << 12;
24350diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24351index 22d0687..e07b2a5 100644
24352--- a/arch/x86/kernel/irq.c
24353+++ b/arch/x86/kernel/irq.c
24354@@ -21,7 +21,7 @@
24355 #define CREATE_TRACE_POINTS
24356 #include <asm/trace/irq_vectors.h>
24357
24358-atomic_t irq_err_count;
24359+atomic_unchecked_t irq_err_count;
24360
24361 /* Function pointer for generic interrupt vector handling */
24362 void (*x86_platform_ipi_callback)(void) = NULL;
24363@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24364 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
24365 seq_printf(p, " Machine check polls\n");
24366 #endif
24367- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24368+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24369 #if defined(CONFIG_X86_IO_APIC)
24370- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24371+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24372 #endif
24373 return 0;
24374 }
24375@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24376
24377 u64 arch_irq_stat(void)
24378 {
24379- u64 sum = atomic_read(&irq_err_count);
24380+ u64 sum = atomic_read_unchecked(&irq_err_count);
24381 return sum;
24382 }
24383
24384diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
24385index d7fcbed..1f747f7 100644
24386--- a/arch/x86/kernel/irq_32.c
24387+++ b/arch/x86/kernel/irq_32.c
24388@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
24389 __asm__ __volatile__("andl %%esp,%0" :
24390 "=r" (sp) : "0" (THREAD_SIZE - 1));
24391
24392- return sp < (sizeof(struct thread_info) + STACK_WARN);
24393+ return sp < STACK_WARN;
24394 }
24395
24396 static void print_stack_overflow(void)
24397@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
24398 * per-CPU IRQ handling contexts (thread information and stack)
24399 */
24400 union irq_ctx {
24401- struct thread_info tinfo;
24402- u32 stack[THREAD_SIZE/sizeof(u32)];
24403+ unsigned long previous_esp;
24404+ u32 stack[THREAD_SIZE/sizeof(u32)];
24405 } __attribute__((aligned(THREAD_SIZE)));
24406
24407 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
24408@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
24409 static inline int
24410 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24411 {
24412- union irq_ctx *curctx, *irqctx;
24413+ union irq_ctx *irqctx;
24414 u32 *isp, arg1, arg2;
24415
24416- curctx = (union irq_ctx *) current_thread_info();
24417 irqctx = __this_cpu_read(hardirq_ctx);
24418
24419 /*
24420@@ -92,13 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24421 * handler) we can't do that and just have to keep using the
24422 * current stack (which is the irq stack already after all)
24423 */
24424- if (unlikely(curctx == irqctx))
24425+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
24426 return 0;
24427
24428 /* build the stack frame on the IRQ stack */
24429- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24430- irqctx->tinfo.task = curctx->tinfo.task;
24431- irqctx->tinfo.previous_esp = current_stack_pointer;
24432+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24433+ irqctx->previous_esp = current_stack_pointer;
24434+
24435+#ifdef CONFIG_PAX_MEMORY_UDEREF
24436+ __set_fs(MAKE_MM_SEG(0));
24437+#endif
24438
24439 if (unlikely(overflow))
24440 call_on_stack(print_stack_overflow, isp);
24441@@ -110,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24442 : "0" (irq), "1" (desc), "2" (isp),
24443 "D" (desc->handle_irq)
24444 : "memory", "cc", "ecx");
24445+
24446+#ifdef CONFIG_PAX_MEMORY_UDEREF
24447+ __set_fs(current_thread_info()->addr_limit);
24448+#endif
24449+
24450 return 1;
24451 }
24452
24453@@ -118,48 +125,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24454 */
24455 void irq_ctx_init(int cpu)
24456 {
24457- union irq_ctx *irqctx;
24458-
24459 if (per_cpu(hardirq_ctx, cpu))
24460 return;
24461
24462- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24463- THREADINFO_GFP,
24464- THREAD_SIZE_ORDER));
24465- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24466- irqctx->tinfo.cpu = cpu;
24467- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24468-
24469- per_cpu(hardirq_ctx, cpu) = irqctx;
24470-
24471- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24472- THREADINFO_GFP,
24473- THREAD_SIZE_ORDER));
24474- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24475- irqctx->tinfo.cpu = cpu;
24476- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24477-
24478- per_cpu(softirq_ctx, cpu) = irqctx;
24479-
24480- printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
24481- cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
24482+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24483+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24484 }
24485
24486 void do_softirq_own_stack(void)
24487 {
24488- struct thread_info *curctx;
24489 union irq_ctx *irqctx;
24490 u32 *isp;
24491
24492- curctx = current_thread_info();
24493 irqctx = __this_cpu_read(softirq_ctx);
24494- irqctx->tinfo.task = curctx->task;
24495- irqctx->tinfo.previous_esp = current_stack_pointer;
24496+ irqctx->previous_esp = current_stack_pointer;
24497
24498 /* build the stack frame on the softirq stack */
24499- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24500+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24501+
24502+#ifdef CONFIG_PAX_MEMORY_UDEREF
24503+ __set_fs(MAKE_MM_SEG(0));
24504+#endif
24505
24506 call_on_stack(__do_softirq, isp);
24507+
24508+#ifdef CONFIG_PAX_MEMORY_UDEREF
24509+ __set_fs(current_thread_info()->addr_limit);
24510+#endif
24511+
24512 }
24513
24514 bool handle_irq(unsigned irq, struct pt_regs *regs)
24515@@ -173,7 +166,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
24516 if (unlikely(!desc))
24517 return false;
24518
24519- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
24520+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
24521 if (unlikely(overflow))
24522 print_stack_overflow();
24523 desc->handle_irq(irq, desc);
24524diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
24525index 4d1c746..232961d 100644
24526--- a/arch/x86/kernel/irq_64.c
24527+++ b/arch/x86/kernel/irq_64.c
24528@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
24529 u64 estack_top, estack_bottom;
24530 u64 curbase = (u64)task_stack_page(current);
24531
24532- if (user_mode_vm(regs))
24533+ if (user_mode(regs))
24534 return;
24535
24536 if (regs->sp >= curbase + sizeof(struct thread_info) +
24537diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
24538index 26d5a55..a01160a 100644
24539--- a/arch/x86/kernel/jump_label.c
24540+++ b/arch/x86/kernel/jump_label.c
24541@@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
24542 * Jump label is enabled for the first time.
24543 * So we expect a default_nop...
24544 */
24545- if (unlikely(memcmp((void *)entry->code, default_nop, 5)
24546+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
24547 != 0))
24548 bug_at((void *)entry->code, __LINE__);
24549 } else {
24550@@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
24551 * ...otherwise expect an ideal_nop. Otherwise
24552 * something went horribly wrong.
24553 */
24554- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
24555+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
24556 != 0))
24557 bug_at((void *)entry->code, __LINE__);
24558 }
24559@@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
24560 * are converting the default nop to the ideal nop.
24561 */
24562 if (init) {
24563- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
24564+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
24565 bug_at((void *)entry->code, __LINE__);
24566 } else {
24567 code.jump = 0xe9;
24568 code.offset = entry->target -
24569 (entry->code + JUMP_LABEL_NOP_SIZE);
24570- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
24571+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
24572 bug_at((void *)entry->code, __LINE__);
24573 }
24574 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
24575diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
24576index 836f832..a8bda67 100644
24577--- a/arch/x86/kernel/kgdb.c
24578+++ b/arch/x86/kernel/kgdb.c
24579@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
24580 #ifdef CONFIG_X86_32
24581 switch (regno) {
24582 case GDB_SS:
24583- if (!user_mode_vm(regs))
24584+ if (!user_mode(regs))
24585 *(unsigned long *)mem = __KERNEL_DS;
24586 break;
24587 case GDB_SP:
24588- if (!user_mode_vm(regs))
24589+ if (!user_mode(regs))
24590 *(unsigned long *)mem = kernel_stack_pointer(regs);
24591 break;
24592 case GDB_GS:
24593@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
24594 bp->attr.bp_addr = breakinfo[breakno].addr;
24595 bp->attr.bp_len = breakinfo[breakno].len;
24596 bp->attr.bp_type = breakinfo[breakno].type;
24597- info->address = breakinfo[breakno].addr;
24598+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
24599+ info->address = ktla_ktva(breakinfo[breakno].addr);
24600+ else
24601+ info->address = breakinfo[breakno].addr;
24602 info->len = breakinfo[breakno].len;
24603 info->type = breakinfo[breakno].type;
24604 val = arch_install_hw_breakpoint(bp);
24605@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
24606 case 'k':
24607 /* clear the trace bit */
24608 linux_regs->flags &= ~X86_EFLAGS_TF;
24609- atomic_set(&kgdb_cpu_doing_single_step, -1);
24610+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
24611
24612 /* set the trace bit if we're stepping */
24613 if (remcomInBuffer[0] == 's') {
24614 linux_regs->flags |= X86_EFLAGS_TF;
24615- atomic_set(&kgdb_cpu_doing_single_step,
24616+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
24617 raw_smp_processor_id());
24618 }
24619
24620@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
24621
24622 switch (cmd) {
24623 case DIE_DEBUG:
24624- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
24625+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
24626 if (user_mode(regs))
24627 return single_step_cont(regs, args);
24628 break;
24629@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
24630 #endif /* CONFIG_DEBUG_RODATA */
24631
24632 bpt->type = BP_BREAKPOINT;
24633- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
24634+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
24635 BREAK_INSTR_SIZE);
24636 if (err)
24637 return err;
24638- err = probe_kernel_write((char *)bpt->bpt_addr,
24639+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
24640 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
24641 #ifdef CONFIG_DEBUG_RODATA
24642 if (!err)
24643@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
24644 return -EBUSY;
24645 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
24646 BREAK_INSTR_SIZE);
24647- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
24648+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
24649 if (err)
24650 return err;
24651 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
24652@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
24653 if (mutex_is_locked(&text_mutex))
24654 goto knl_write;
24655 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
24656- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
24657+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
24658 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
24659 goto knl_write;
24660 return err;
24661 knl_write:
24662 #endif /* CONFIG_DEBUG_RODATA */
24663- return probe_kernel_write((char *)bpt->bpt_addr,
24664+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
24665 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
24666 }
24667
24668diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
24669index 79a3f96..6ba030a 100644
24670--- a/arch/x86/kernel/kprobes/core.c
24671+++ b/arch/x86/kernel/kprobes/core.c
24672@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
24673 s32 raddr;
24674 } __packed *insn;
24675
24676- insn = (struct __arch_relative_insn *)from;
24677+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
24678+
24679+ pax_open_kernel();
24680 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
24681 insn->op = op;
24682+ pax_close_kernel();
24683 }
24684
24685 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
24686@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
24687 kprobe_opcode_t opcode;
24688 kprobe_opcode_t *orig_opcodes = opcodes;
24689
24690- if (search_exception_tables((unsigned long)opcodes))
24691+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
24692 return 0; /* Page fault may occur on this address. */
24693
24694 retry:
24695@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
24696 * for the first byte, we can recover the original instruction
24697 * from it and kp->opcode.
24698 */
24699- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
24700+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
24701 buf[0] = kp->opcode;
24702- return (unsigned long)buf;
24703+ return ktva_ktla((unsigned long)buf);
24704 }
24705
24706 /*
24707@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
24708 /* Another subsystem puts a breakpoint, failed to recover */
24709 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
24710 return 0;
24711+ pax_open_kernel();
24712 memcpy(dest, insn.kaddr, insn.length);
24713+ pax_close_kernel();
24714
24715 #ifdef CONFIG_X86_64
24716 if (insn_rip_relative(&insn)) {
24717@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
24718 return 0;
24719 }
24720 disp = (u8 *) dest + insn_offset_displacement(&insn);
24721+ pax_open_kernel();
24722 *(s32 *) disp = (s32) newdisp;
24723+ pax_close_kernel();
24724 }
24725 #endif
24726 return insn.length;
24727@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
24728 * nor set current_kprobe, because it doesn't use single
24729 * stepping.
24730 */
24731- regs->ip = (unsigned long)p->ainsn.insn;
24732+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
24733 preempt_enable_no_resched();
24734 return;
24735 }
24736@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
24737 regs->flags &= ~X86_EFLAGS_IF;
24738 /* single step inline if the instruction is an int3 */
24739 if (p->opcode == BREAKPOINT_INSTRUCTION)
24740- regs->ip = (unsigned long)p->addr;
24741+ regs->ip = ktla_ktva((unsigned long)p->addr);
24742 else
24743- regs->ip = (unsigned long)p->ainsn.insn;
24744+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
24745 }
24746
24747 /*
24748@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
24749 setup_singlestep(p, regs, kcb, 0);
24750 return 1;
24751 }
24752- } else if (*addr != BREAKPOINT_INSTRUCTION) {
24753+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
24754 /*
24755 * The breakpoint instruction was removed right
24756 * after we hit it. Another cpu has removed
24757@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
24758 " movq %rax, 152(%rsp)\n"
24759 RESTORE_REGS_STRING
24760 " popfq\n"
24761+#ifdef KERNEXEC_PLUGIN
24762+ " btsq $63,(%rsp)\n"
24763+#endif
24764 #else
24765 " pushf\n"
24766 SAVE_REGS_STRING
24767@@ -779,7 +789,7 @@ static void __kprobes
24768 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
24769 {
24770 unsigned long *tos = stack_addr(regs);
24771- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
24772+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
24773 unsigned long orig_ip = (unsigned long)p->addr;
24774 kprobe_opcode_t *insn = p->ainsn.insn;
24775
24776@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
24777 struct die_args *args = data;
24778 int ret = NOTIFY_DONE;
24779
24780- if (args->regs && user_mode_vm(args->regs))
24781+ if (args->regs && user_mode(args->regs))
24782 return ret;
24783
24784 switch (val) {
24785diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
24786index 898160b..758cde8 100644
24787--- a/arch/x86/kernel/kprobes/opt.c
24788+++ b/arch/x86/kernel/kprobes/opt.c
24789@@ -79,6 +79,7 @@ found:
24790 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
24791 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
24792 {
24793+ pax_open_kernel();
24794 #ifdef CONFIG_X86_64
24795 *addr++ = 0x48;
24796 *addr++ = 0xbf;
24797@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
24798 *addr++ = 0xb8;
24799 #endif
24800 *(unsigned long *)addr = val;
24801+ pax_close_kernel();
24802 }
24803
24804 asm (
24805@@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
24806 * Verify if the address gap is in 2GB range, because this uses
24807 * a relative jump.
24808 */
24809- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
24810+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
24811 if (abs(rel) > 0x7fffffff)
24812 return -ERANGE;
24813
24814@@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
24815 op->optinsn.size = ret;
24816
24817 /* Copy arch-dep-instance from template */
24818- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
24819+ pax_open_kernel();
24820+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
24821+ pax_close_kernel();
24822
24823 /* Set probe information */
24824 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
24825
24826 /* Set probe function call */
24827- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
24828+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
24829
24830 /* Set returning jmp instruction at the tail of out-of-line buffer */
24831- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
24832+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
24833 (u8 *)op->kp.addr + op->optinsn.size);
24834
24835 flush_icache_range((unsigned long) buf,
24836@@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
24837 WARN_ON(kprobe_disabled(&op->kp));
24838
24839 /* Backup instructions which will be replaced by jump address */
24840- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
24841+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
24842 RELATIVE_ADDR_SIZE);
24843
24844 insn_buf[0] = RELATIVEJUMP_OPCODE;
24845@@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
24846 /* This kprobe is really able to run optimized path. */
24847 op = container_of(p, struct optimized_kprobe, kp);
24848 /* Detour through copied instructions */
24849- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
24850+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
24851 if (!reenter)
24852 reset_current_kprobe();
24853 preempt_enable_no_resched();
24854diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
24855index ebc9873..1b9724b 100644
24856--- a/arch/x86/kernel/ldt.c
24857+++ b/arch/x86/kernel/ldt.c
24858@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
24859 if (reload) {
24860 #ifdef CONFIG_SMP
24861 preempt_disable();
24862- load_LDT(pc);
24863+ load_LDT_nolock(pc);
24864 if (!cpumask_equal(mm_cpumask(current->mm),
24865 cpumask_of(smp_processor_id())))
24866 smp_call_function(flush_ldt, current->mm, 1);
24867 preempt_enable();
24868 #else
24869- load_LDT(pc);
24870+ load_LDT_nolock(pc);
24871 #endif
24872 }
24873 if (oldsize) {
24874@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
24875 return err;
24876
24877 for (i = 0; i < old->size; i++)
24878- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
24879+ write_ldt_entry(new->ldt, i, old->ldt + i);
24880 return 0;
24881 }
24882
24883@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
24884 retval = copy_ldt(&mm->context, &old_mm->context);
24885 mutex_unlock(&old_mm->context.lock);
24886 }
24887+
24888+ if (tsk == current) {
24889+ mm->context.vdso = 0;
24890+
24891+#ifdef CONFIG_X86_32
24892+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24893+ mm->context.user_cs_base = 0UL;
24894+ mm->context.user_cs_limit = ~0UL;
24895+
24896+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
24897+ cpus_clear(mm->context.cpu_user_cs_mask);
24898+#endif
24899+
24900+#endif
24901+#endif
24902+
24903+ }
24904+
24905 return retval;
24906 }
24907
24908@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
24909 }
24910 }
24911
24912+#ifdef CONFIG_PAX_SEGMEXEC
24913+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
24914+ error = -EINVAL;
24915+ goto out_unlock;
24916+ }
24917+#endif
24918+
24919 fill_ldt(&ldt, &ldt_info);
24920 if (oldmode)
24921 ldt.avl = 0;
24922diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
24923index 5b19e4d..6476a76 100644
24924--- a/arch/x86/kernel/machine_kexec_32.c
24925+++ b/arch/x86/kernel/machine_kexec_32.c
24926@@ -26,7 +26,7 @@
24927 #include <asm/cacheflush.h>
24928 #include <asm/debugreg.h>
24929
24930-static void set_idt(void *newidt, __u16 limit)
24931+static void set_idt(struct desc_struct *newidt, __u16 limit)
24932 {
24933 struct desc_ptr curidt;
24934
24935@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
24936 }
24937
24938
24939-static void set_gdt(void *newgdt, __u16 limit)
24940+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
24941 {
24942 struct desc_ptr curgdt;
24943
24944@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
24945 }
24946
24947 control_page = page_address(image->control_code_page);
24948- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
24949+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
24950
24951 relocate_kernel_ptr = control_page;
24952 page_list[PA_CONTROL_PAGE] = __pa(control_page);
24953diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
24954index 15c9876..0a43909 100644
24955--- a/arch/x86/kernel/microcode_core.c
24956+++ b/arch/x86/kernel/microcode_core.c
24957@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
24958 return NOTIFY_OK;
24959 }
24960
24961-static struct notifier_block __refdata mc_cpu_notifier = {
24962+static struct notifier_block mc_cpu_notifier = {
24963 .notifier_call = mc_cpu_callback,
24964 };
24965
24966diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
24967index 5fb2ceb..3ae90bb 100644
24968--- a/arch/x86/kernel/microcode_intel.c
24969+++ b/arch/x86/kernel/microcode_intel.c
24970@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
24971
24972 static int get_ucode_user(void *to, const void *from, size_t n)
24973 {
24974- return copy_from_user(to, from, n);
24975+ return copy_from_user(to, (const void __force_user *)from, n);
24976 }
24977
24978 static enum ucode_state
24979 request_microcode_user(int cpu, const void __user *buf, size_t size)
24980 {
24981- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
24982+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
24983 }
24984
24985 static void microcode_fini_cpu(int cpu)
24986diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
24987index 18be189..4a9fe40 100644
24988--- a/arch/x86/kernel/module.c
24989+++ b/arch/x86/kernel/module.c
24990@@ -43,15 +43,60 @@ do { \
24991 } while (0)
24992 #endif
24993
24994-void *module_alloc(unsigned long size)
24995+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
24996 {
24997- if (PAGE_ALIGN(size) > MODULES_LEN)
24998+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
24999 return NULL;
25000 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
25001- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
25002+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
25003 NUMA_NO_NODE, __builtin_return_address(0));
25004 }
25005
25006+void *module_alloc(unsigned long size)
25007+{
25008+
25009+#ifdef CONFIG_PAX_KERNEXEC
25010+ return __module_alloc(size, PAGE_KERNEL);
25011+#else
25012+ return __module_alloc(size, PAGE_KERNEL_EXEC);
25013+#endif
25014+
25015+}
25016+
25017+#ifdef CONFIG_PAX_KERNEXEC
25018+#ifdef CONFIG_X86_32
25019+void *module_alloc_exec(unsigned long size)
25020+{
25021+ struct vm_struct *area;
25022+
25023+ if (size == 0)
25024+ return NULL;
25025+
25026+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25027+ return area ? area->addr : NULL;
25028+}
25029+EXPORT_SYMBOL(module_alloc_exec);
25030+
25031+void module_free_exec(struct module *mod, void *module_region)
25032+{
25033+ vunmap(module_region);
25034+}
25035+EXPORT_SYMBOL(module_free_exec);
25036+#else
25037+void module_free_exec(struct module *mod, void *module_region)
25038+{
25039+ module_free(mod, module_region);
25040+}
25041+EXPORT_SYMBOL(module_free_exec);
25042+
25043+void *module_alloc_exec(unsigned long size)
25044+{
25045+ return __module_alloc(size, PAGE_KERNEL_RX);
25046+}
25047+EXPORT_SYMBOL(module_alloc_exec);
25048+#endif
25049+#endif
25050+
25051 #ifdef CONFIG_X86_32
25052 int apply_relocate(Elf32_Shdr *sechdrs,
25053 const char *strtab,
25054@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25055 unsigned int i;
25056 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25057 Elf32_Sym *sym;
25058- uint32_t *location;
25059+ uint32_t *plocation, location;
25060
25061 DEBUGP("Applying relocate section %u to %u\n",
25062 relsec, sechdrs[relsec].sh_info);
25063 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25064 /* This is where to make the change */
25065- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25066- + rel[i].r_offset;
25067+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25068+ location = (uint32_t)plocation;
25069+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25070+ plocation = ktla_ktva((void *)plocation);
25071 /* This is the symbol it is referring to. Note that all
25072 undefined symbols have been resolved. */
25073 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25074@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25075 switch (ELF32_R_TYPE(rel[i].r_info)) {
25076 case R_386_32:
25077 /* We add the value into the location given */
25078- *location += sym->st_value;
25079+ pax_open_kernel();
25080+ *plocation += sym->st_value;
25081+ pax_close_kernel();
25082 break;
25083 case R_386_PC32:
25084 /* Add the value, subtract its position */
25085- *location += sym->st_value - (uint32_t)location;
25086+ pax_open_kernel();
25087+ *plocation += sym->st_value - location;
25088+ pax_close_kernel();
25089 break;
25090 default:
25091 pr_err("%s: Unknown relocation: %u\n",
25092@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25093 case R_X86_64_NONE:
25094 break;
25095 case R_X86_64_64:
25096+ pax_open_kernel();
25097 *(u64 *)loc = val;
25098+ pax_close_kernel();
25099 break;
25100 case R_X86_64_32:
25101+ pax_open_kernel();
25102 *(u32 *)loc = val;
25103+ pax_close_kernel();
25104 if (val != *(u32 *)loc)
25105 goto overflow;
25106 break;
25107 case R_X86_64_32S:
25108+ pax_open_kernel();
25109 *(s32 *)loc = val;
25110+ pax_close_kernel();
25111 if ((s64)val != *(s32 *)loc)
25112 goto overflow;
25113 break;
25114 case R_X86_64_PC32:
25115 val -= (u64)loc;
25116+ pax_open_kernel();
25117 *(u32 *)loc = val;
25118+ pax_close_kernel();
25119+
25120 #if 0
25121 if ((s64)val != *(s32 *)loc)
25122 goto overflow;
25123diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25124index 05266b5..1577fde 100644
25125--- a/arch/x86/kernel/msr.c
25126+++ b/arch/x86/kernel/msr.c
25127@@ -233,7 +233,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25128 return notifier_from_errno(err);
25129 }
25130
25131-static struct notifier_block __refdata msr_class_cpu_notifier = {
25132+static struct notifier_block msr_class_cpu_notifier = {
25133 .notifier_call = msr_class_cpu_callback,
25134 };
25135
25136diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25137index 6fcb49c..5b3f4ff 100644
25138--- a/arch/x86/kernel/nmi.c
25139+++ b/arch/x86/kernel/nmi.c
25140@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25141 return handled;
25142 }
25143
25144-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25145+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25146 {
25147 struct nmi_desc *desc = nmi_to_desc(type);
25148 unsigned long flags;
25149@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25150 * event confuses some handlers (kdump uses this flag)
25151 */
25152 if (action->flags & NMI_FLAG_FIRST)
25153- list_add_rcu(&action->list, &desc->head);
25154+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25155 else
25156- list_add_tail_rcu(&action->list, &desc->head);
25157+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25158
25159 spin_unlock_irqrestore(&desc->lock, flags);
25160 return 0;
25161@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25162 if (!strcmp(n->name, name)) {
25163 WARN(in_nmi(),
25164 "Trying to free NMI (%s) from NMI context!\n", n->name);
25165- list_del_rcu(&n->list);
25166+ pax_list_del_rcu((struct list_head *)&n->list);
25167 break;
25168 }
25169 }
25170@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
25171 dotraplinkage notrace __kprobes void
25172 do_nmi(struct pt_regs *regs, long error_code)
25173 {
25174+
25175+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25176+ if (!user_mode(regs)) {
25177+ unsigned long cs = regs->cs & 0xFFFF;
25178+ unsigned long ip = ktva_ktla(regs->ip);
25179+
25180+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25181+ regs->ip = ip;
25182+ }
25183+#endif
25184+
25185 nmi_nesting_preprocess(regs);
25186
25187 nmi_enter();
25188diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25189index 6d9582e..f746287 100644
25190--- a/arch/x86/kernel/nmi_selftest.c
25191+++ b/arch/x86/kernel/nmi_selftest.c
25192@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25193 {
25194 /* trap all the unknown NMIs we may generate */
25195 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25196- __initdata);
25197+ __initconst);
25198 }
25199
25200 static void __init cleanup_nmi_testsuite(void)
25201@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25202 unsigned long timeout;
25203
25204 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25205- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25206+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25207 nmi_fail = FAILURE;
25208 return;
25209 }
25210diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25211index bbb6c73..24a58ef 100644
25212--- a/arch/x86/kernel/paravirt-spinlocks.c
25213+++ b/arch/x86/kernel/paravirt-spinlocks.c
25214@@ -8,7 +8,7 @@
25215
25216 #include <asm/paravirt.h>
25217
25218-struct pv_lock_ops pv_lock_ops = {
25219+struct pv_lock_ops pv_lock_ops __read_only = {
25220 #ifdef CONFIG_SMP
25221 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25222 .unlock_kick = paravirt_nop,
25223diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25224index 1b10af8..0b58cbc 100644
25225--- a/arch/x86/kernel/paravirt.c
25226+++ b/arch/x86/kernel/paravirt.c
25227@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25228 {
25229 return x;
25230 }
25231+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25232+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25233+#endif
25234
25235 void __init default_banner(void)
25236 {
25237@@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25238 if (opfunc == NULL)
25239 /* If there's no function, patch it with a ud2a (BUG) */
25240 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25241- else if (opfunc == _paravirt_nop)
25242+ else if (opfunc == (void *)_paravirt_nop)
25243 /* If the operation is a nop, then nop the callsite */
25244 ret = paravirt_patch_nop();
25245
25246 /* identity functions just return their single argument */
25247- else if (opfunc == _paravirt_ident_32)
25248+ else if (opfunc == (void *)_paravirt_ident_32)
25249 ret = paravirt_patch_ident_32(insnbuf, len);
25250- else if (opfunc == _paravirt_ident_64)
25251+ else if (opfunc == (void *)_paravirt_ident_64)
25252 ret = paravirt_patch_ident_64(insnbuf, len);
25253+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25254+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25255+ ret = paravirt_patch_ident_64(insnbuf, len);
25256+#endif
25257
25258 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25259 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25260@@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25261 if (insn_len > len || start == NULL)
25262 insn_len = len;
25263 else
25264- memcpy(insnbuf, start, insn_len);
25265+ memcpy(insnbuf, ktla_ktva(start), insn_len);
25266
25267 return insn_len;
25268 }
25269@@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25270 return this_cpu_read(paravirt_lazy_mode);
25271 }
25272
25273-struct pv_info pv_info = {
25274+struct pv_info pv_info __read_only = {
25275 .name = "bare hardware",
25276 .paravirt_enabled = 0,
25277 .kernel_rpl = 0,
25278@@ -310,16 +317,16 @@ struct pv_info pv_info = {
25279 #endif
25280 };
25281
25282-struct pv_init_ops pv_init_ops = {
25283+struct pv_init_ops pv_init_ops __read_only = {
25284 .patch = native_patch,
25285 };
25286
25287-struct pv_time_ops pv_time_ops = {
25288+struct pv_time_ops pv_time_ops __read_only = {
25289 .sched_clock = native_sched_clock,
25290 .steal_clock = native_steal_clock,
25291 };
25292
25293-__visible struct pv_irq_ops pv_irq_ops = {
25294+__visible struct pv_irq_ops pv_irq_ops __read_only = {
25295 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25296 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25297 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25298@@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25299 #endif
25300 };
25301
25302-__visible struct pv_cpu_ops pv_cpu_ops = {
25303+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25304 .cpuid = native_cpuid,
25305 .get_debugreg = native_get_debugreg,
25306 .set_debugreg = native_set_debugreg,
25307@@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25308 .end_context_switch = paravirt_nop,
25309 };
25310
25311-struct pv_apic_ops pv_apic_ops = {
25312+struct pv_apic_ops pv_apic_ops __read_only= {
25313 #ifdef CONFIG_X86_LOCAL_APIC
25314 .startup_ipi_hook = paravirt_nop,
25315 #endif
25316 };
25317
25318-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
25319+#ifdef CONFIG_X86_32
25320+#ifdef CONFIG_X86_PAE
25321+/* 64-bit pagetable entries */
25322+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
25323+#else
25324 /* 32-bit pagetable entries */
25325 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
25326+#endif
25327 #else
25328 /* 64-bit pagetable entries */
25329 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
25330 #endif
25331
25332-struct pv_mmu_ops pv_mmu_ops = {
25333+struct pv_mmu_ops pv_mmu_ops __read_only = {
25334
25335 .read_cr2 = native_read_cr2,
25336 .write_cr2 = native_write_cr2,
25337@@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
25338 .make_pud = PTE_IDENT,
25339
25340 .set_pgd = native_set_pgd,
25341+ .set_pgd_batched = native_set_pgd_batched,
25342 #endif
25343 #endif /* PAGETABLE_LEVELS >= 3 */
25344
25345@@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
25346 },
25347
25348 .set_fixmap = native_set_fixmap,
25349+
25350+#ifdef CONFIG_PAX_KERNEXEC
25351+ .pax_open_kernel = native_pax_open_kernel,
25352+ .pax_close_kernel = native_pax_close_kernel,
25353+#endif
25354+
25355 };
25356
25357 EXPORT_SYMBOL_GPL(pv_time_ops);
25358diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
25359index 299d493..2ccb0ee 100644
25360--- a/arch/x86/kernel/pci-calgary_64.c
25361+++ b/arch/x86/kernel/pci-calgary_64.c
25362@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
25363 tce_space = be64_to_cpu(readq(target));
25364 tce_space = tce_space & TAR_SW_BITS;
25365
25366- tce_space = tce_space & (~specified_table_size);
25367+ tce_space = tce_space & (~(unsigned long)specified_table_size);
25368 info->tce_space = (u64 *)__va(tce_space);
25369 }
25370 }
25371diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
25372index 35ccf75..7a15747 100644
25373--- a/arch/x86/kernel/pci-iommu_table.c
25374+++ b/arch/x86/kernel/pci-iommu_table.c
25375@@ -2,7 +2,7 @@
25376 #include <asm/iommu_table.h>
25377 #include <linux/string.h>
25378 #include <linux/kallsyms.h>
25379-
25380+#include <linux/sched.h>
25381
25382 #define DEBUG 1
25383
25384diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
25385index 6c483ba..d10ce2f 100644
25386--- a/arch/x86/kernel/pci-swiotlb.c
25387+++ b/arch/x86/kernel/pci-swiotlb.c
25388@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
25389 void *vaddr, dma_addr_t dma_addr,
25390 struct dma_attrs *attrs)
25391 {
25392- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
25393+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
25394 }
25395
25396 static struct dma_map_ops swiotlb_dma_ops = {
25397diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
25398index ca7f0d5..8996469 100644
25399--- a/arch/x86/kernel/preempt.S
25400+++ b/arch/x86/kernel/preempt.S
25401@@ -3,12 +3,14 @@
25402 #include <asm/dwarf2.h>
25403 #include <asm/asm.h>
25404 #include <asm/calling.h>
25405+#include <asm/alternative-asm.h>
25406
25407 ENTRY(___preempt_schedule)
25408 CFI_STARTPROC
25409 SAVE_ALL
25410 call preempt_schedule
25411 RESTORE_ALL
25412+ pax_force_retaddr
25413 ret
25414 CFI_ENDPROC
25415
25416@@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
25417 SAVE_ALL
25418 call preempt_schedule_context
25419 RESTORE_ALL
25420+ pax_force_retaddr
25421 ret
25422 CFI_ENDPROC
25423
25424diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
25425index 3fb8d95..254dc51 100644
25426--- a/arch/x86/kernel/process.c
25427+++ b/arch/x86/kernel/process.c
25428@@ -36,7 +36,8 @@
25429 * section. Since TSS's are completely CPU-local, we want them
25430 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
25431 */
25432-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
25433+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
25434+EXPORT_SYMBOL(init_tss);
25435
25436 #ifdef CONFIG_X86_64
25437 static DEFINE_PER_CPU(unsigned char, is_idle);
25438@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
25439 task_xstate_cachep =
25440 kmem_cache_create("task_xstate", xstate_size,
25441 __alignof__(union thread_xstate),
25442- SLAB_PANIC | SLAB_NOTRACK, NULL);
25443+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
25444 }
25445
25446 /*
25447@@ -105,7 +106,7 @@ void exit_thread(void)
25448 unsigned long *bp = t->io_bitmap_ptr;
25449
25450 if (bp) {
25451- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
25452+ struct tss_struct *tss = init_tss + get_cpu();
25453
25454 t->io_bitmap_ptr = NULL;
25455 clear_thread_flag(TIF_IO_BITMAP);
25456@@ -125,6 +126,9 @@ void flush_thread(void)
25457 {
25458 struct task_struct *tsk = current;
25459
25460+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
25461+ loadsegment(gs, 0);
25462+#endif
25463 flush_ptrace_hw_breakpoint(tsk);
25464 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
25465 drop_init_fpu(tsk);
25466@@ -271,7 +275,7 @@ static void __exit_idle(void)
25467 void exit_idle(void)
25468 {
25469 /* idle loop has pid 0 */
25470- if (current->pid)
25471+ if (task_pid_nr(current))
25472 return;
25473 __exit_idle();
25474 }
25475@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
25476 return ret;
25477 }
25478 #endif
25479-void stop_this_cpu(void *dummy)
25480+__noreturn void stop_this_cpu(void *dummy)
25481 {
25482 local_irq_disable();
25483 /*
25484@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
25485 }
25486 early_param("idle", idle_setup);
25487
25488-unsigned long arch_align_stack(unsigned long sp)
25489+#ifdef CONFIG_PAX_RANDKSTACK
25490+void pax_randomize_kstack(struct pt_regs *regs)
25491 {
25492- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
25493- sp -= get_random_int() % 8192;
25494- return sp & ~0xf;
25495-}
25496+ struct thread_struct *thread = &current->thread;
25497+ unsigned long time;
25498
25499-unsigned long arch_randomize_brk(struct mm_struct *mm)
25500-{
25501- unsigned long range_end = mm->brk + 0x02000000;
25502- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
25503-}
25504+ if (!randomize_va_space)
25505+ return;
25506+
25507+ if (v8086_mode(regs))
25508+ return;
25509
25510+ rdtscl(time);
25511+
25512+ /* P4 seems to return a 0 LSB, ignore it */
25513+#ifdef CONFIG_MPENTIUM4
25514+ time &= 0x3EUL;
25515+ time <<= 2;
25516+#elif defined(CONFIG_X86_64)
25517+ time &= 0xFUL;
25518+ time <<= 4;
25519+#else
25520+ time &= 0x1FUL;
25521+ time <<= 3;
25522+#endif
25523+
25524+ thread->sp0 ^= time;
25525+ load_sp0(init_tss + smp_processor_id(), thread);
25526+
25527+#ifdef CONFIG_X86_64
25528+ this_cpu_write(kernel_stack, thread->sp0);
25529+#endif
25530+}
25531+#endif
25532diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
25533index 6f1236c..fd448d4 100644
25534--- a/arch/x86/kernel/process_32.c
25535+++ b/arch/x86/kernel/process_32.c
25536@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
25537 unsigned long thread_saved_pc(struct task_struct *tsk)
25538 {
25539 return ((unsigned long *)tsk->thread.sp)[3];
25540+//XXX return tsk->thread.eip;
25541 }
25542
25543 void __show_regs(struct pt_regs *regs, int all)
25544@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
25545 unsigned long sp;
25546 unsigned short ss, gs;
25547
25548- if (user_mode_vm(regs)) {
25549+ if (user_mode(regs)) {
25550 sp = regs->sp;
25551 ss = regs->ss & 0xffff;
25552- gs = get_user_gs(regs);
25553 } else {
25554 sp = kernel_stack_pointer(regs);
25555 savesegment(ss, ss);
25556- savesegment(gs, gs);
25557 }
25558+ gs = get_user_gs(regs);
25559
25560 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
25561 (u16)regs->cs, regs->ip, regs->flags,
25562- smp_processor_id());
25563+ raw_smp_processor_id());
25564 print_symbol("EIP is at %s\n", regs->ip);
25565
25566 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
25567@@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
25568 int copy_thread(unsigned long clone_flags, unsigned long sp,
25569 unsigned long arg, struct task_struct *p)
25570 {
25571- struct pt_regs *childregs = task_pt_regs(p);
25572+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
25573 struct task_struct *tsk;
25574 int err;
25575
25576 p->thread.sp = (unsigned long) childregs;
25577 p->thread.sp0 = (unsigned long) (childregs+1);
25578+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
25579
25580 if (unlikely(p->flags & PF_KTHREAD)) {
25581 /* kernel thread */
25582 memset(childregs, 0, sizeof(struct pt_regs));
25583 p->thread.ip = (unsigned long) ret_from_kernel_thread;
25584- task_user_gs(p) = __KERNEL_STACK_CANARY;
25585- childregs->ds = __USER_DS;
25586- childregs->es = __USER_DS;
25587+ savesegment(gs, childregs->gs);
25588+ childregs->ds = __KERNEL_DS;
25589+ childregs->es = __KERNEL_DS;
25590 childregs->fs = __KERNEL_PERCPU;
25591 childregs->bx = sp; /* function */
25592 childregs->bp = arg;
25593@@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25594 struct thread_struct *prev = &prev_p->thread,
25595 *next = &next_p->thread;
25596 int cpu = smp_processor_id();
25597- struct tss_struct *tss = &per_cpu(init_tss, cpu);
25598+ struct tss_struct *tss = init_tss + cpu;
25599 fpu_switch_t fpu;
25600
25601 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
25602@@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25603 */
25604 lazy_save_gs(prev->gs);
25605
25606+#ifdef CONFIG_PAX_MEMORY_UDEREF
25607+ __set_fs(task_thread_info(next_p)->addr_limit);
25608+#endif
25609+
25610 /*
25611 * Load the per-thread Thread-Local Storage descriptor.
25612 */
25613@@ -315,6 +320,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25614 */
25615 arch_end_context_switch(next_p);
25616
25617+ this_cpu_write(current_task, next_p);
25618+ this_cpu_write(current_tinfo, &next_p->tinfo);
25619+
25620 /*
25621 * Restore %gs if needed (which is common)
25622 */
25623@@ -323,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25624
25625 switch_fpu_finish(next_p, fpu);
25626
25627- this_cpu_write(current_task, next_p);
25628-
25629 return prev_p;
25630 }
25631
25632@@ -354,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
25633 } while (count++ < 16);
25634 return 0;
25635 }
25636-
25637diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
25638index 9c0280f..5bbb1c0 100644
25639--- a/arch/x86/kernel/process_64.c
25640+++ b/arch/x86/kernel/process_64.c
25641@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
25642 struct pt_regs *childregs;
25643 struct task_struct *me = current;
25644
25645- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
25646+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
25647 childregs = task_pt_regs(p);
25648 p->thread.sp = (unsigned long) childregs;
25649 p->thread.usersp = me->thread.usersp;
25650+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
25651 set_tsk_thread_flag(p, TIF_FORK);
25652 p->thread.fpu_counter = 0;
25653 p->thread.io_bitmap_ptr = NULL;
25654@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
25655 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
25656 savesegment(es, p->thread.es);
25657 savesegment(ds, p->thread.ds);
25658+ savesegment(ss, p->thread.ss);
25659+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
25660 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
25661
25662 if (unlikely(p->flags & PF_KTHREAD)) {
25663@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25664 struct thread_struct *prev = &prev_p->thread;
25665 struct thread_struct *next = &next_p->thread;
25666 int cpu = smp_processor_id();
25667- struct tss_struct *tss = &per_cpu(init_tss, cpu);
25668+ struct tss_struct *tss = init_tss + cpu;
25669 unsigned fsindex, gsindex;
25670 fpu_switch_t fpu;
25671
25672@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25673 if (unlikely(next->ds | prev->ds))
25674 loadsegment(ds, next->ds);
25675
25676+ savesegment(ss, prev->ss);
25677+ if (unlikely(next->ss != prev->ss))
25678+ loadsegment(ss, next->ss);
25679
25680 /* We must save %fs and %gs before load_TLS() because
25681 * %fs and %gs may be cleared by load_TLS().
25682@@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25683 prev->usersp = this_cpu_read(old_rsp);
25684 this_cpu_write(old_rsp, next->usersp);
25685 this_cpu_write(current_task, next_p);
25686+ this_cpu_write(current_tinfo, &next_p->tinfo);
25687
25688 /*
25689 * If it were not for PREEMPT_ACTIVE we could guarantee that the
25690@@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25691 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
25692 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
25693
25694- this_cpu_write(kernel_stack,
25695- (unsigned long)task_stack_page(next_p) +
25696- THREAD_SIZE - KERNEL_STACK_OFFSET);
25697+ this_cpu_write(kernel_stack, next->sp0);
25698
25699 /*
25700 * Now maybe reload the debug registers and handle I/O bitmaps
25701@@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
25702 if (!p || p == current || p->state == TASK_RUNNING)
25703 return 0;
25704 stack = (unsigned long)task_stack_page(p);
25705- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
25706+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
25707 return 0;
25708 fp = *(u64 *)(p->thread.sp);
25709 do {
25710- if (fp < (unsigned long)stack ||
25711- fp >= (unsigned long)stack+THREAD_SIZE)
25712+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
25713 return 0;
25714 ip = *(u64 *)(fp+8);
25715 if (!in_sched_functions(ip))
25716diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
25717index 7461f50..1334029 100644
25718--- a/arch/x86/kernel/ptrace.c
25719+++ b/arch/x86/kernel/ptrace.c
25720@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
25721 {
25722 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
25723 unsigned long sp = (unsigned long)&regs->sp;
25724- struct thread_info *tinfo;
25725
25726- if (context == (sp & ~(THREAD_SIZE - 1)))
25727+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
25728 return sp;
25729
25730- tinfo = (struct thread_info *)context;
25731- if (tinfo->previous_esp)
25732- return tinfo->previous_esp;
25733+ sp = *(unsigned long *)context;
25734+ if (sp)
25735+ return sp;
25736
25737 return (unsigned long)regs;
25738 }
25739@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
25740 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
25741 {
25742 int i;
25743- int dr7 = 0;
25744+ unsigned long dr7 = 0;
25745 struct arch_hw_breakpoint *info;
25746
25747 for (i = 0; i < HBP_NUM; i++) {
25748@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
25749 unsigned long addr, unsigned long data)
25750 {
25751 int ret;
25752- unsigned long __user *datap = (unsigned long __user *)data;
25753+ unsigned long __user *datap = (__force unsigned long __user *)data;
25754
25755 switch (request) {
25756 /* read the word at location addr in the USER area. */
25757@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
25758 if ((int) addr < 0)
25759 return -EIO;
25760 ret = do_get_thread_area(child, addr,
25761- (struct user_desc __user *)data);
25762+ (__force struct user_desc __user *) data);
25763 break;
25764
25765 case PTRACE_SET_THREAD_AREA:
25766 if ((int) addr < 0)
25767 return -EIO;
25768 ret = do_set_thread_area(child, addr,
25769- (struct user_desc __user *)data, 0);
25770+ (__force struct user_desc __user *) data, 0);
25771 break;
25772 #endif
25773
25774@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
25775
25776 #ifdef CONFIG_X86_64
25777
25778-static struct user_regset x86_64_regsets[] __read_mostly = {
25779+static user_regset_no_const x86_64_regsets[] __read_only = {
25780 [REGSET_GENERAL] = {
25781 .core_note_type = NT_PRSTATUS,
25782 .n = sizeof(struct user_regs_struct) / sizeof(long),
25783@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
25784 #endif /* CONFIG_X86_64 */
25785
25786 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
25787-static struct user_regset x86_32_regsets[] __read_mostly = {
25788+static user_regset_no_const x86_32_regsets[] __read_only = {
25789 [REGSET_GENERAL] = {
25790 .core_note_type = NT_PRSTATUS,
25791 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
25792@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
25793 */
25794 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
25795
25796-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
25797+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
25798 {
25799 #ifdef CONFIG_X86_64
25800 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
25801@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
25802 memset(info, 0, sizeof(*info));
25803 info->si_signo = SIGTRAP;
25804 info->si_code = si_code;
25805- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
25806+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
25807 }
25808
25809 void user_single_step_siginfo(struct task_struct *tsk,
25810@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
25811 # define IS_IA32 0
25812 #endif
25813
25814+#ifdef CONFIG_GRKERNSEC_SETXID
25815+extern void gr_delayed_cred_worker(void);
25816+#endif
25817+
25818 /*
25819 * We must return the syscall number to actually look up in the table.
25820 * This can be -1L to skip running any syscall at all.
25821@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
25822
25823 user_exit();
25824
25825+#ifdef CONFIG_GRKERNSEC_SETXID
25826+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
25827+ gr_delayed_cred_worker();
25828+#endif
25829+
25830 /*
25831 * If we stepped into a sysenter/syscall insn, it trapped in
25832 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
25833@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
25834 */
25835 user_exit();
25836
25837+#ifdef CONFIG_GRKERNSEC_SETXID
25838+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
25839+ gr_delayed_cred_worker();
25840+#endif
25841+
25842 audit_syscall_exit(regs);
25843
25844 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
25845diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
25846index 2f355d2..e75ed0a 100644
25847--- a/arch/x86/kernel/pvclock.c
25848+++ b/arch/x86/kernel/pvclock.c
25849@@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
25850 reset_hung_task_detector();
25851 }
25852
25853-static atomic64_t last_value = ATOMIC64_INIT(0);
25854+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
25855
25856 void pvclock_resume(void)
25857 {
25858- atomic64_set(&last_value, 0);
25859+ atomic64_set_unchecked(&last_value, 0);
25860 }
25861
25862 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
25863@@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
25864 * updating at the same time, and one of them could be slightly behind,
25865 * making the assumption that last_value always go forward fail to hold.
25866 */
25867- last = atomic64_read(&last_value);
25868+ last = atomic64_read_unchecked(&last_value);
25869 do {
25870 if (ret < last)
25871 return last;
25872- last = atomic64_cmpxchg(&last_value, last, ret);
25873+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
25874 } while (unlikely(last != ret));
25875
25876 return ret;
25877diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
25878index c752cb4..866c432 100644
25879--- a/arch/x86/kernel/reboot.c
25880+++ b/arch/x86/kernel/reboot.c
25881@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
25882
25883 void __noreturn machine_real_restart(unsigned int type)
25884 {
25885+
25886+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
25887+ struct desc_struct *gdt;
25888+#endif
25889+
25890 local_irq_disable();
25891
25892 /*
25893@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
25894
25895 /* Jump to the identity-mapped low memory code */
25896 #ifdef CONFIG_X86_32
25897- asm volatile("jmpl *%0" : :
25898+
25899+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
25900+ gdt = get_cpu_gdt_table(smp_processor_id());
25901+ pax_open_kernel();
25902+#ifdef CONFIG_PAX_MEMORY_UDEREF
25903+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
25904+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
25905+ loadsegment(ds, __KERNEL_DS);
25906+ loadsegment(es, __KERNEL_DS);
25907+ loadsegment(ss, __KERNEL_DS);
25908+#endif
25909+#ifdef CONFIG_PAX_KERNEXEC
25910+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
25911+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
25912+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
25913+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
25914+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
25915+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
25916+#endif
25917+ pax_close_kernel();
25918+#endif
25919+
25920+ asm volatile("ljmpl *%0" : :
25921 "rm" (real_mode_header->machine_real_restart_asm),
25922 "a" (type));
25923 #else
25924@@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
25925 * try to force a triple fault and then cycle between hitting the keyboard
25926 * controller and doing that
25927 */
25928-static void native_machine_emergency_restart(void)
25929+static void __noreturn native_machine_emergency_restart(void)
25930 {
25931 int i;
25932 int attempt = 0;
25933@@ -593,13 +620,13 @@ void native_machine_shutdown(void)
25934 #endif
25935 }
25936
25937-static void __machine_emergency_restart(int emergency)
25938+static void __noreturn __machine_emergency_restart(int emergency)
25939 {
25940 reboot_emergency = emergency;
25941 machine_ops.emergency_restart();
25942 }
25943
25944-static void native_machine_restart(char *__unused)
25945+static void __noreturn native_machine_restart(char *__unused)
25946 {
25947 pr_notice("machine restart\n");
25948
25949@@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
25950 __machine_emergency_restart(0);
25951 }
25952
25953-static void native_machine_halt(void)
25954+static void __noreturn native_machine_halt(void)
25955 {
25956 /* Stop other cpus and apics */
25957 machine_shutdown();
25958@@ -618,7 +645,7 @@ static void native_machine_halt(void)
25959 stop_this_cpu(NULL);
25960 }
25961
25962-static void native_machine_power_off(void)
25963+static void __noreturn native_machine_power_off(void)
25964 {
25965 if (pm_power_off) {
25966 if (!reboot_force)
25967@@ -627,9 +654,10 @@ static void native_machine_power_off(void)
25968 }
25969 /* A fallback in case there is no PM info available */
25970 tboot_shutdown(TB_SHUTDOWN_HALT);
25971+ unreachable();
25972 }
25973
25974-struct machine_ops machine_ops = {
25975+struct machine_ops machine_ops __read_only = {
25976 .power_off = native_machine_power_off,
25977 .shutdown = native_machine_shutdown,
25978 .emergency_restart = native_machine_emergency_restart,
25979diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
25980index c8e41e9..64049ef 100644
25981--- a/arch/x86/kernel/reboot_fixups_32.c
25982+++ b/arch/x86/kernel/reboot_fixups_32.c
25983@@ -57,7 +57,7 @@ struct device_fixup {
25984 unsigned int vendor;
25985 unsigned int device;
25986 void (*reboot_fixup)(struct pci_dev *);
25987-};
25988+} __do_const;
25989
25990 /*
25991 * PCI ids solely used for fixups_table go here
25992diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
25993index 3fd2c69..16ef367 100644
25994--- a/arch/x86/kernel/relocate_kernel_64.S
25995+++ b/arch/x86/kernel/relocate_kernel_64.S
25996@@ -11,6 +11,7 @@
25997 #include <asm/kexec.h>
25998 #include <asm/processor-flags.h>
25999 #include <asm/pgtable_types.h>
26000+#include <asm/alternative-asm.h>
26001
26002 /*
26003 * Must be relocatable PIC code callable as a C function
26004@@ -96,8 +97,7 @@ relocate_kernel:
26005
26006 /* jump to identity mapped page */
26007 addq $(identity_mapped - relocate_kernel), %r8
26008- pushq %r8
26009- ret
26010+ jmp *%r8
26011
26012 identity_mapped:
26013 /* set return address to 0 if not preserving context */
26014@@ -167,6 +167,7 @@ identity_mapped:
26015 xorl %r14d, %r14d
26016 xorl %r15d, %r15d
26017
26018+ pax_force_retaddr 0, 1
26019 ret
26020
26021 1:
26022diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26023index cb233bc..23b4879 100644
26024--- a/arch/x86/kernel/setup.c
26025+++ b/arch/x86/kernel/setup.c
26026@@ -110,6 +110,7 @@
26027 #include <asm/mce.h>
26028 #include <asm/alternative.h>
26029 #include <asm/prom.h>
26030+#include <asm/boot.h>
26031
26032 /*
26033 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26034@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26035 #endif
26036
26037
26038-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26039-__visible unsigned long mmu_cr4_features;
26040+#ifdef CONFIG_X86_64
26041+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26042+#elif defined(CONFIG_X86_PAE)
26043+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26044 #else
26045-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26046+__visible unsigned long mmu_cr4_features __read_only;
26047 #endif
26048
26049+void set_in_cr4(unsigned long mask)
26050+{
26051+ unsigned long cr4 = read_cr4();
26052+
26053+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26054+ return;
26055+
26056+ pax_open_kernel();
26057+ mmu_cr4_features |= mask;
26058+ pax_close_kernel();
26059+
26060+ if (trampoline_cr4_features)
26061+ *trampoline_cr4_features = mmu_cr4_features;
26062+ cr4 |= mask;
26063+ write_cr4(cr4);
26064+}
26065+EXPORT_SYMBOL(set_in_cr4);
26066+
26067+void clear_in_cr4(unsigned long mask)
26068+{
26069+ unsigned long cr4 = read_cr4();
26070+
26071+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26072+ return;
26073+
26074+ pax_open_kernel();
26075+ mmu_cr4_features &= ~mask;
26076+ pax_close_kernel();
26077+
26078+ if (trampoline_cr4_features)
26079+ *trampoline_cr4_features = mmu_cr4_features;
26080+ cr4 &= ~mask;
26081+ write_cr4(cr4);
26082+}
26083+EXPORT_SYMBOL(clear_in_cr4);
26084+
26085 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26086 int bootloader_type, bootloader_version;
26087
26088@@ -768,7 +807,7 @@ static void __init trim_bios_range(void)
26089 * area (640->1Mb) as ram even though it is not.
26090 * take them out.
26091 */
26092- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26093+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26094
26095 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26096 }
26097@@ -776,7 +815,7 @@ static void __init trim_bios_range(void)
26098 /* called before trim_bios_range() to spare extra sanitize */
26099 static void __init e820_add_kernel_range(void)
26100 {
26101- u64 start = __pa_symbol(_text);
26102+ u64 start = __pa_symbol(ktla_ktva(_text));
26103 u64 size = __pa_symbol(_end) - start;
26104
26105 /*
26106@@ -838,8 +877,12 @@ static void __init trim_low_memory_range(void)
26107
26108 void __init setup_arch(char **cmdline_p)
26109 {
26110+#ifdef CONFIG_X86_32
26111+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26112+#else
26113 memblock_reserve(__pa_symbol(_text),
26114 (unsigned long)__bss_stop - (unsigned long)_text);
26115+#endif
26116
26117 early_reserve_initrd();
26118
26119@@ -931,14 +974,14 @@ void __init setup_arch(char **cmdline_p)
26120
26121 if (!boot_params.hdr.root_flags)
26122 root_mountflags &= ~MS_RDONLY;
26123- init_mm.start_code = (unsigned long) _text;
26124- init_mm.end_code = (unsigned long) _etext;
26125+ init_mm.start_code = ktla_ktva((unsigned long) _text);
26126+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
26127 init_mm.end_data = (unsigned long) _edata;
26128 init_mm.brk = _brk_end;
26129
26130- code_resource.start = __pa_symbol(_text);
26131- code_resource.end = __pa_symbol(_etext)-1;
26132- data_resource.start = __pa_symbol(_etext);
26133+ code_resource.start = __pa_symbol(ktla_ktva(_text));
26134+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26135+ data_resource.start = __pa_symbol(_sdata);
26136 data_resource.end = __pa_symbol(_edata)-1;
26137 bss_resource.start = __pa_symbol(__bss_start);
26138 bss_resource.end = __pa_symbol(__bss_stop)-1;
26139diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26140index 5cdff03..80fa283 100644
26141--- a/arch/x86/kernel/setup_percpu.c
26142+++ b/arch/x86/kernel/setup_percpu.c
26143@@ -21,19 +21,17 @@
26144 #include <asm/cpu.h>
26145 #include <asm/stackprotector.h>
26146
26147-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26148+#ifdef CONFIG_SMP
26149+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26150 EXPORT_PER_CPU_SYMBOL(cpu_number);
26151+#endif
26152
26153-#ifdef CONFIG_X86_64
26154 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26155-#else
26156-#define BOOT_PERCPU_OFFSET 0
26157-#endif
26158
26159 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26160 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26161
26162-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26163+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26164 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26165 };
26166 EXPORT_SYMBOL(__per_cpu_offset);
26167@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26168 {
26169 #ifdef CONFIG_NEED_MULTIPLE_NODES
26170 pg_data_t *last = NULL;
26171- unsigned int cpu;
26172+ int cpu;
26173
26174 for_each_possible_cpu(cpu) {
26175 int node = early_cpu_to_node(cpu);
26176@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26177 {
26178 #ifdef CONFIG_X86_32
26179 struct desc_struct gdt;
26180+ unsigned long base = per_cpu_offset(cpu);
26181
26182- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26183- 0x2 | DESCTYPE_S, 0x8);
26184- gdt.s = 1;
26185+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26186+ 0x83 | DESCTYPE_S, 0xC);
26187 write_gdt_entry(get_cpu_gdt_table(cpu),
26188 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26189 #endif
26190@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26191 /* alrighty, percpu areas up and running */
26192 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26193 for_each_possible_cpu(cpu) {
26194+#ifdef CONFIG_CC_STACKPROTECTOR
26195+#ifdef CONFIG_X86_32
26196+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
26197+#endif
26198+#endif
26199 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26200 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26201 per_cpu(cpu_number, cpu) = cpu;
26202@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26203 */
26204 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26205 #endif
26206+#ifdef CONFIG_CC_STACKPROTECTOR
26207+#ifdef CONFIG_X86_32
26208+ if (!cpu)
26209+ per_cpu(stack_canary.canary, cpu) = canary;
26210+#endif
26211+#endif
26212 /*
26213 * Up to this point, the boot CPU has been using .init.data
26214 * area. Reload any changed state for the boot CPU.
26215diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26216index 9e5de68..16c53cb 100644
26217--- a/arch/x86/kernel/signal.c
26218+++ b/arch/x86/kernel/signal.c
26219@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26220 * Align the stack pointer according to the i386 ABI,
26221 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26222 */
26223- sp = ((sp + 4) & -16ul) - 4;
26224+ sp = ((sp - 12) & -16ul) - 4;
26225 #else /* !CONFIG_X86_32 */
26226 sp = round_down(sp, 16) - 8;
26227 #endif
26228@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26229 }
26230
26231 if (current->mm->context.vdso)
26232- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26233+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26234 else
26235- restorer = &frame->retcode;
26236+ restorer = (void __user *)&frame->retcode;
26237 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26238 restorer = ksig->ka.sa.sa_restorer;
26239
26240@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26241 * reasons and because gdb uses it as a signature to notice
26242 * signal handler stack frames.
26243 */
26244- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26245+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26246
26247 if (err)
26248 return -EFAULT;
26249@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26250 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26251
26252 /* Set up to return from userspace. */
26253- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26254+ if (current->mm->context.vdso)
26255+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26256+ else
26257+ restorer = (void __user *)&frame->retcode;
26258 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26259 restorer = ksig->ka.sa.sa_restorer;
26260 put_user_ex(restorer, &frame->pretcode);
26261@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26262 * reasons and because gdb uses it as a signature to notice
26263 * signal handler stack frames.
26264 */
26265- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26266+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26267 } put_user_catch(err);
26268
26269 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26270@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26271 {
26272 int usig = signr_convert(ksig->sig);
26273 sigset_t *set = sigmask_to_save();
26274- compat_sigset_t *cset = (compat_sigset_t *) set;
26275+ sigset_t sigcopy;
26276+ compat_sigset_t *cset;
26277+
26278+ sigcopy = *set;
26279+
26280+ cset = (compat_sigset_t *) &sigcopy;
26281
26282 /* Set up the stack frame */
26283 if (is_ia32_frame()) {
26284@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26285 } else if (is_x32_frame()) {
26286 return x32_setup_rt_frame(ksig, cset, regs);
26287 } else {
26288- return __setup_rt_frame(ksig->sig, ksig, set, regs);
26289+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26290 }
26291 }
26292
26293diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26294index 7c3a5a6..f0a8961 100644
26295--- a/arch/x86/kernel/smp.c
26296+++ b/arch/x86/kernel/smp.c
26297@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26298
26299 __setup("nonmi_ipi", nonmi_ipi_setup);
26300
26301-struct smp_ops smp_ops = {
26302+struct smp_ops smp_ops __read_only = {
26303 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26304 .smp_prepare_cpus = native_smp_prepare_cpus,
26305 .smp_cpus_done = native_smp_cpus_done,
26306diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
26307index 85dc05a..1241266 100644
26308--- a/arch/x86/kernel/smpboot.c
26309+++ b/arch/x86/kernel/smpboot.c
26310@@ -229,14 +229,18 @@ static void notrace start_secondary(void *unused)
26311
26312 enable_start_cpu0 = 0;
26313
26314-#ifdef CONFIG_X86_32
26315- /* switch away from the initial page table */
26316- load_cr3(swapper_pg_dir);
26317- __flush_tlb_all();
26318-#endif
26319-
26320 /* otherwise gcc will move up smp_processor_id before the cpu_init */
26321 barrier();
26322+
26323+ /* switch away from the initial page table */
26324+#ifdef CONFIG_PAX_PER_CPU_PGD
26325+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
26326+ __flush_tlb_all();
26327+#elif defined(CONFIG_X86_32)
26328+ load_cr3(swapper_pg_dir);
26329+ __flush_tlb_all();
26330+#endif
26331+
26332 /*
26333 * Check TSC synchronization with the BP:
26334 */
26335@@ -751,6 +755,7 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26336 idle->thread.sp = (unsigned long) (((struct pt_regs *)
26337 (THREAD_SIZE + task_stack_page(idle))) - 1);
26338 per_cpu(current_task, cpu) = idle;
26339+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
26340
26341 #ifdef CONFIG_X86_32
26342 /* Stack for startup_32 can be just as for start_secondary onwards */
26343@@ -758,11 +763,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26344 #else
26345 clear_tsk_thread_flag(idle, TIF_FORK);
26346 initial_gs = per_cpu_offset(cpu);
26347- per_cpu(kernel_stack, cpu) =
26348- (unsigned long)task_stack_page(idle) -
26349- KERNEL_STACK_OFFSET + THREAD_SIZE;
26350+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26351 #endif
26352+
26353+ pax_open_kernel();
26354 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
26355+ pax_close_kernel();
26356+
26357 initial_code = (unsigned long)start_secondary;
26358 stack_start = idle->thread.sp;
26359
26360@@ -911,6 +918,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
26361 /* the FPU context is blank, nobody can own it */
26362 __cpu_disable_lazy_restore(cpu);
26363
26364+#ifdef CONFIG_PAX_PER_CPU_PGD
26365+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
26366+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26367+ KERNEL_PGD_PTRS);
26368+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
26369+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26370+ KERNEL_PGD_PTRS);
26371+#endif
26372+
26373 err = do_boot_cpu(apicid, cpu, tidle);
26374 if (err) {
26375 pr_debug("do_boot_cpu failed %d\n", err);
26376diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
26377index 9b4d51d..5d28b58 100644
26378--- a/arch/x86/kernel/step.c
26379+++ b/arch/x86/kernel/step.c
26380@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26381 struct desc_struct *desc;
26382 unsigned long base;
26383
26384- seg &= ~7UL;
26385+ seg >>= 3;
26386
26387 mutex_lock(&child->mm->context.lock);
26388- if (unlikely((seg >> 3) >= child->mm->context.size))
26389+ if (unlikely(seg >= child->mm->context.size))
26390 addr = -1L; /* bogus selector, access would fault */
26391 else {
26392 desc = child->mm->context.ldt + seg;
26393@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26394 addr += base;
26395 }
26396 mutex_unlock(&child->mm->context.lock);
26397- }
26398+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
26399+ addr = ktla_ktva(addr);
26400
26401 return addr;
26402 }
26403@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
26404 unsigned char opcode[15];
26405 unsigned long addr = convert_ip_to_linear(child, regs);
26406
26407+ if (addr == -EINVAL)
26408+ return 0;
26409+
26410 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
26411 for (i = 0; i < copied; i++) {
26412 switch (opcode[i]) {
26413diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
26414new file mode 100644
26415index 0000000..5877189
26416--- /dev/null
26417+++ b/arch/x86/kernel/sys_i386_32.c
26418@@ -0,0 +1,189 @@
26419+/*
26420+ * This file contains various random system calls that
26421+ * have a non-standard calling sequence on the Linux/i386
26422+ * platform.
26423+ */
26424+
26425+#include <linux/errno.h>
26426+#include <linux/sched.h>
26427+#include <linux/mm.h>
26428+#include <linux/fs.h>
26429+#include <linux/smp.h>
26430+#include <linux/sem.h>
26431+#include <linux/msg.h>
26432+#include <linux/shm.h>
26433+#include <linux/stat.h>
26434+#include <linux/syscalls.h>
26435+#include <linux/mman.h>
26436+#include <linux/file.h>
26437+#include <linux/utsname.h>
26438+#include <linux/ipc.h>
26439+#include <linux/elf.h>
26440+
26441+#include <linux/uaccess.h>
26442+#include <linux/unistd.h>
26443+
26444+#include <asm/syscalls.h>
26445+
26446+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
26447+{
26448+ unsigned long pax_task_size = TASK_SIZE;
26449+
26450+#ifdef CONFIG_PAX_SEGMEXEC
26451+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
26452+ pax_task_size = SEGMEXEC_TASK_SIZE;
26453+#endif
26454+
26455+ if (flags & MAP_FIXED)
26456+ if (len > pax_task_size || addr > pax_task_size - len)
26457+ return -EINVAL;
26458+
26459+ return 0;
26460+}
26461+
26462+/*
26463+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
26464+ */
26465+static unsigned long get_align_mask(void)
26466+{
26467+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
26468+ return 0;
26469+
26470+ if (!(current->flags & PF_RANDOMIZE))
26471+ return 0;
26472+
26473+ return va_align.mask;
26474+}
26475+
26476+unsigned long
26477+arch_get_unmapped_area(struct file *filp, unsigned long addr,
26478+ unsigned long len, unsigned long pgoff, unsigned long flags)
26479+{
26480+ struct mm_struct *mm = current->mm;
26481+ struct vm_area_struct *vma;
26482+ unsigned long pax_task_size = TASK_SIZE;
26483+ struct vm_unmapped_area_info info;
26484+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26485+
26486+#ifdef CONFIG_PAX_SEGMEXEC
26487+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26488+ pax_task_size = SEGMEXEC_TASK_SIZE;
26489+#endif
26490+
26491+ pax_task_size -= PAGE_SIZE;
26492+
26493+ if (len > pax_task_size)
26494+ return -ENOMEM;
26495+
26496+ if (flags & MAP_FIXED)
26497+ return addr;
26498+
26499+#ifdef CONFIG_PAX_RANDMMAP
26500+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26501+#endif
26502+
26503+ if (addr) {
26504+ addr = PAGE_ALIGN(addr);
26505+ if (pax_task_size - len >= addr) {
26506+ vma = find_vma(mm, addr);
26507+ if (check_heap_stack_gap(vma, addr, len, offset))
26508+ return addr;
26509+ }
26510+ }
26511+
26512+ info.flags = 0;
26513+ info.length = len;
26514+ info.align_mask = filp ? get_align_mask() : 0;
26515+ info.align_offset = pgoff << PAGE_SHIFT;
26516+ info.threadstack_offset = offset;
26517+
26518+#ifdef CONFIG_PAX_PAGEEXEC
26519+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
26520+ info.low_limit = 0x00110000UL;
26521+ info.high_limit = mm->start_code;
26522+
26523+#ifdef CONFIG_PAX_RANDMMAP
26524+ if (mm->pax_flags & MF_PAX_RANDMMAP)
26525+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
26526+#endif
26527+
26528+ if (info.low_limit < info.high_limit) {
26529+ addr = vm_unmapped_area(&info);
26530+ if (!IS_ERR_VALUE(addr))
26531+ return addr;
26532+ }
26533+ } else
26534+#endif
26535+
26536+ info.low_limit = mm->mmap_base;
26537+ info.high_limit = pax_task_size;
26538+
26539+ return vm_unmapped_area(&info);
26540+}
26541+
26542+unsigned long
26543+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26544+ const unsigned long len, const unsigned long pgoff,
26545+ const unsigned long flags)
26546+{
26547+ struct vm_area_struct *vma;
26548+ struct mm_struct *mm = current->mm;
26549+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
26550+ struct vm_unmapped_area_info info;
26551+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26552+
26553+#ifdef CONFIG_PAX_SEGMEXEC
26554+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26555+ pax_task_size = SEGMEXEC_TASK_SIZE;
26556+#endif
26557+
26558+ pax_task_size -= PAGE_SIZE;
26559+
26560+ /* requested length too big for entire address space */
26561+ if (len > pax_task_size)
26562+ return -ENOMEM;
26563+
26564+ if (flags & MAP_FIXED)
26565+ return addr;
26566+
26567+#ifdef CONFIG_PAX_PAGEEXEC
26568+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
26569+ goto bottomup;
26570+#endif
26571+
26572+#ifdef CONFIG_PAX_RANDMMAP
26573+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26574+#endif
26575+
26576+ /* requesting a specific address */
26577+ if (addr) {
26578+ addr = PAGE_ALIGN(addr);
26579+ if (pax_task_size - len >= addr) {
26580+ vma = find_vma(mm, addr);
26581+ if (check_heap_stack_gap(vma, addr, len, offset))
26582+ return addr;
26583+ }
26584+ }
26585+
26586+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
26587+ info.length = len;
26588+ info.low_limit = PAGE_SIZE;
26589+ info.high_limit = mm->mmap_base;
26590+ info.align_mask = filp ? get_align_mask() : 0;
26591+ info.align_offset = pgoff << PAGE_SHIFT;
26592+ info.threadstack_offset = offset;
26593+
26594+ addr = vm_unmapped_area(&info);
26595+ if (!(addr & ~PAGE_MASK))
26596+ return addr;
26597+ VM_BUG_ON(addr != -ENOMEM);
26598+
26599+bottomup:
26600+ /*
26601+ * A failed mmap() very likely causes application failure,
26602+ * so fall back to the bottom-up function here. This scenario
26603+ * can happen with large stack limits and large mmap()
26604+ * allocations.
26605+ */
26606+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
26607+}
26608diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
26609index 30277e2..5664a29 100644
26610--- a/arch/x86/kernel/sys_x86_64.c
26611+++ b/arch/x86/kernel/sys_x86_64.c
26612@@ -81,8 +81,8 @@ out:
26613 return error;
26614 }
26615
26616-static void find_start_end(unsigned long flags, unsigned long *begin,
26617- unsigned long *end)
26618+static void find_start_end(struct mm_struct *mm, unsigned long flags,
26619+ unsigned long *begin, unsigned long *end)
26620 {
26621 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
26622 unsigned long new_begin;
26623@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
26624 *begin = new_begin;
26625 }
26626 } else {
26627- *begin = current->mm->mmap_legacy_base;
26628+ *begin = mm->mmap_legacy_base;
26629 *end = TASK_SIZE;
26630 }
26631 }
26632@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
26633 struct vm_area_struct *vma;
26634 struct vm_unmapped_area_info info;
26635 unsigned long begin, end;
26636+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26637
26638 if (flags & MAP_FIXED)
26639 return addr;
26640
26641- find_start_end(flags, &begin, &end);
26642+ find_start_end(mm, flags, &begin, &end);
26643
26644 if (len > end)
26645 return -ENOMEM;
26646
26647+#ifdef CONFIG_PAX_RANDMMAP
26648+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26649+#endif
26650+
26651 if (addr) {
26652 addr = PAGE_ALIGN(addr);
26653 vma = find_vma(mm, addr);
26654- if (end - len >= addr &&
26655- (!vma || addr + len <= vma->vm_start))
26656+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26657 return addr;
26658 }
26659
26660@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
26661 info.high_limit = end;
26662 info.align_mask = filp ? get_align_mask() : 0;
26663 info.align_offset = pgoff << PAGE_SHIFT;
26664+ info.threadstack_offset = offset;
26665 return vm_unmapped_area(&info);
26666 }
26667
26668@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26669 struct mm_struct *mm = current->mm;
26670 unsigned long addr = addr0;
26671 struct vm_unmapped_area_info info;
26672+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26673
26674 /* requested length too big for entire address space */
26675 if (len > TASK_SIZE)
26676@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26677 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
26678 goto bottomup;
26679
26680+#ifdef CONFIG_PAX_RANDMMAP
26681+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26682+#endif
26683+
26684 /* requesting a specific address */
26685 if (addr) {
26686 addr = PAGE_ALIGN(addr);
26687 vma = find_vma(mm, addr);
26688- if (TASK_SIZE - len >= addr &&
26689- (!vma || addr + len <= vma->vm_start))
26690+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26691 return addr;
26692 }
26693
26694@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26695 info.high_limit = mm->mmap_base;
26696 info.align_mask = filp ? get_align_mask() : 0;
26697 info.align_offset = pgoff << PAGE_SHIFT;
26698+ info.threadstack_offset = offset;
26699 addr = vm_unmapped_area(&info);
26700 if (!(addr & ~PAGE_MASK))
26701 return addr;
26702diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
26703index 91a4496..bb87552 100644
26704--- a/arch/x86/kernel/tboot.c
26705+++ b/arch/x86/kernel/tboot.c
26706@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
26707
26708 void tboot_shutdown(u32 shutdown_type)
26709 {
26710- void (*shutdown)(void);
26711+ void (* __noreturn shutdown)(void);
26712
26713 if (!tboot_enabled())
26714 return;
26715@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
26716
26717 switch_to_tboot_pt();
26718
26719- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
26720+ shutdown = (void *)(unsigned long)tboot->shutdown_entry;
26721 shutdown();
26722
26723 /* should not reach here */
26724@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
26725 return -ENODEV;
26726 }
26727
26728-static atomic_t ap_wfs_count;
26729+static atomic_unchecked_t ap_wfs_count;
26730
26731 static int tboot_wait_for_aps(int num_aps)
26732 {
26733@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
26734 {
26735 switch (action) {
26736 case CPU_DYING:
26737- atomic_inc(&ap_wfs_count);
26738+ atomic_inc_unchecked(&ap_wfs_count);
26739 if (num_online_cpus() == 1)
26740- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
26741+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
26742 return NOTIFY_BAD;
26743 break;
26744 }
26745@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
26746
26747 tboot_create_trampoline();
26748
26749- atomic_set(&ap_wfs_count, 0);
26750+ atomic_set_unchecked(&ap_wfs_count, 0);
26751 register_hotcpu_notifier(&tboot_cpu_notifier);
26752
26753 #ifdef CONFIG_DEBUG_FS
26754diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
26755index 24d3c91..d06b473 100644
26756--- a/arch/x86/kernel/time.c
26757+++ b/arch/x86/kernel/time.c
26758@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
26759 {
26760 unsigned long pc = instruction_pointer(regs);
26761
26762- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
26763+ if (!user_mode(regs) && in_lock_functions(pc)) {
26764 #ifdef CONFIG_FRAME_POINTER
26765- return *(unsigned long *)(regs->bp + sizeof(long));
26766+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
26767 #else
26768 unsigned long *sp =
26769 (unsigned long *)kernel_stack_pointer(regs);
26770@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
26771 * or above a saved flags. Eflags has bits 22-31 zero,
26772 * kernel addresses don't.
26773 */
26774+
26775+#ifdef CONFIG_PAX_KERNEXEC
26776+ return ktla_ktva(sp[0]);
26777+#else
26778 if (sp[0] >> 22)
26779 return sp[0];
26780 if (sp[1] >> 22)
26781 return sp[1];
26782 #endif
26783+
26784+#endif
26785 }
26786 return pc;
26787 }
26788diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
26789index f7fec09..9991981 100644
26790--- a/arch/x86/kernel/tls.c
26791+++ b/arch/x86/kernel/tls.c
26792@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
26793 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
26794 return -EINVAL;
26795
26796+#ifdef CONFIG_PAX_SEGMEXEC
26797+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
26798+ return -EINVAL;
26799+#endif
26800+
26801 set_tls_desc(p, idx, &info, 1);
26802
26803 return 0;
26804@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
26805
26806 if (kbuf)
26807 info = kbuf;
26808- else if (__copy_from_user(infobuf, ubuf, count))
26809+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
26810 return -EFAULT;
26811 else
26812 info = infobuf;
26813diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
26814index 1c113db..287b42e 100644
26815--- a/arch/x86/kernel/tracepoint.c
26816+++ b/arch/x86/kernel/tracepoint.c
26817@@ -9,11 +9,11 @@
26818 #include <linux/atomic.h>
26819
26820 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
26821-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
26822+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
26823 (unsigned long) trace_idt_table };
26824
26825 /* No need to be aligned, but done to keep all IDTs defined the same way. */
26826-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
26827+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
26828
26829 static int trace_irq_vector_refcount;
26830 static DEFINE_MUTEX(irq_vector_mutex);
26831diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
26832index b857ed8..51ae4cb 100644
26833--- a/arch/x86/kernel/traps.c
26834+++ b/arch/x86/kernel/traps.c
26835@@ -66,7 +66,7 @@
26836 #include <asm/proto.h>
26837
26838 /* No need to be aligned, but done to keep all IDTs defined the same way. */
26839-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
26840+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
26841 #else
26842 #include <asm/processor-flags.h>
26843 #include <asm/setup.h>
26844@@ -75,7 +75,7 @@ asmlinkage int system_call(void);
26845 #endif
26846
26847 /* Must be page-aligned because the real IDT is used in a fixmap. */
26848-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
26849+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
26850
26851 DECLARE_BITMAP(used_vectors, NR_VECTORS);
26852 EXPORT_SYMBOL_GPL(used_vectors);
26853@@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
26854 }
26855
26856 static int __kprobes
26857-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26858+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
26859 struct pt_regs *regs, long error_code)
26860 {
26861 #ifdef CONFIG_X86_32
26862- if (regs->flags & X86_VM_MASK) {
26863+ if (v8086_mode(regs)) {
26864 /*
26865 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
26866 * On nmi (interrupt 2), do_trap should not be called.
26867@@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26868 return -1;
26869 }
26870 #endif
26871- if (!user_mode(regs)) {
26872+ if (!user_mode_novm(regs)) {
26873 if (!fixup_exception(regs)) {
26874 tsk->thread.error_code = error_code;
26875 tsk->thread.trap_nr = trapnr;
26876+
26877+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26878+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
26879+ str = "PAX: suspicious stack segment fault";
26880+#endif
26881+
26882 die(str, regs, error_code);
26883 }
26884+
26885+#ifdef CONFIG_PAX_REFCOUNT
26886+ if (trapnr == 4)
26887+ pax_report_refcount_overflow(regs);
26888+#endif
26889+
26890 return 0;
26891 }
26892
26893@@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26894 }
26895
26896 static void __kprobes
26897-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
26898+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
26899 long error_code, siginfo_t *info)
26900 {
26901 struct task_struct *tsk = current;
26902@@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
26903 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
26904 printk_ratelimit()) {
26905 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
26906- tsk->comm, tsk->pid, str,
26907+ tsk->comm, task_pid_nr(tsk), str,
26908 regs->ip, regs->sp, error_code);
26909 print_vma_addr(" in ", regs->ip);
26910 pr_cont("\n");
26911@@ -277,7 +289,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
26912 conditional_sti(regs);
26913
26914 #ifdef CONFIG_X86_32
26915- if (regs->flags & X86_VM_MASK) {
26916+ if (v8086_mode(regs)) {
26917 local_irq_enable();
26918 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
26919 goto exit;
26920@@ -285,18 +297,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
26921 #endif
26922
26923 tsk = current;
26924- if (!user_mode(regs)) {
26925+ if (!user_mode_novm(regs)) {
26926 if (fixup_exception(regs))
26927 goto exit;
26928
26929 tsk->thread.error_code = error_code;
26930 tsk->thread.trap_nr = X86_TRAP_GP;
26931 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
26932- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
26933+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
26934+
26935+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26936+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
26937+ die("PAX: suspicious general protection fault", regs, error_code);
26938+ else
26939+#endif
26940+
26941 die("general protection fault", regs, error_code);
26942+ }
26943 goto exit;
26944 }
26945
26946+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26947+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
26948+ struct mm_struct *mm = tsk->mm;
26949+ unsigned long limit;
26950+
26951+ down_write(&mm->mmap_sem);
26952+ limit = mm->context.user_cs_limit;
26953+ if (limit < TASK_SIZE) {
26954+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
26955+ up_write(&mm->mmap_sem);
26956+ return;
26957+ }
26958+ up_write(&mm->mmap_sem);
26959+ }
26960+#endif
26961+
26962 tsk->thread.error_code = error_code;
26963 tsk->thread.trap_nr = X86_TRAP_GP;
26964
26965@@ -457,7 +493,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26966 /* It's safe to allow irq's after DR6 has been saved */
26967 preempt_conditional_sti(regs);
26968
26969- if (regs->flags & X86_VM_MASK) {
26970+ if (v8086_mode(regs)) {
26971 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
26972 X86_TRAP_DB);
26973 preempt_conditional_cli(regs);
26974@@ -472,7 +508,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26975 * We already checked v86 mode above, so we can check for kernel mode
26976 * by just checking the CPL of CS.
26977 */
26978- if ((dr6 & DR_STEP) && !user_mode(regs)) {
26979+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
26980 tsk->thread.debugreg6 &= ~DR_STEP;
26981 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
26982 regs->flags &= ~X86_EFLAGS_TF;
26983@@ -504,7 +540,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
26984 return;
26985 conditional_sti(regs);
26986
26987- if (!user_mode_vm(regs))
26988+ if (!user_mode(regs))
26989 {
26990 if (!fixup_exception(regs)) {
26991 task->thread.error_code = error_code;
26992diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
26993index 2ed8459..7cf329f 100644
26994--- a/arch/x86/kernel/uprobes.c
26995+++ b/arch/x86/kernel/uprobes.c
26996@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
26997 int ret = NOTIFY_DONE;
26998
26999 /* We are only interested in userspace traps */
27000- if (regs && !user_mode_vm(regs))
27001+ if (regs && !user_mode(regs))
27002 return NOTIFY_DONE;
27003
27004 switch (val) {
27005@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27006
27007 if (ncopied != rasize) {
27008 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27009- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27010+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27011
27012 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27013 }
27014diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27015index b9242ba..50c5edd 100644
27016--- a/arch/x86/kernel/verify_cpu.S
27017+++ b/arch/x86/kernel/verify_cpu.S
27018@@ -20,6 +20,7 @@
27019 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27020 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27021 * arch/x86/kernel/head_32.S: processor startup
27022+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27023 *
27024 * verify_cpu, returns the status of longmode and SSE in register %eax.
27025 * 0: Success 1: Failure
27026diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27027index e8edcf5..27f9344 100644
27028--- a/arch/x86/kernel/vm86_32.c
27029+++ b/arch/x86/kernel/vm86_32.c
27030@@ -44,6 +44,7 @@
27031 #include <linux/ptrace.h>
27032 #include <linux/audit.h>
27033 #include <linux/stddef.h>
27034+#include <linux/grsecurity.h>
27035
27036 #include <asm/uaccess.h>
27037 #include <asm/io.h>
27038@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27039 do_exit(SIGSEGV);
27040 }
27041
27042- tss = &per_cpu(init_tss, get_cpu());
27043+ tss = init_tss + get_cpu();
27044 current->thread.sp0 = current->thread.saved_sp0;
27045 current->thread.sysenter_cs = __KERNEL_CS;
27046 load_sp0(tss, &current->thread);
27047@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27048
27049 if (tsk->thread.saved_sp0)
27050 return -EPERM;
27051+
27052+#ifdef CONFIG_GRKERNSEC_VM86
27053+ if (!capable(CAP_SYS_RAWIO)) {
27054+ gr_handle_vm86();
27055+ return -EPERM;
27056+ }
27057+#endif
27058+
27059 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27060 offsetof(struct kernel_vm86_struct, vm86plus) -
27061 sizeof(info.regs));
27062@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27063 int tmp;
27064 struct vm86plus_struct __user *v86;
27065
27066+#ifdef CONFIG_GRKERNSEC_VM86
27067+ if (!capable(CAP_SYS_RAWIO)) {
27068+ gr_handle_vm86();
27069+ return -EPERM;
27070+ }
27071+#endif
27072+
27073 tsk = current;
27074 switch (cmd) {
27075 case VM86_REQUEST_IRQ:
27076@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27077 tsk->thread.saved_fs = info->regs32->fs;
27078 tsk->thread.saved_gs = get_user_gs(info->regs32);
27079
27080- tss = &per_cpu(init_tss, get_cpu());
27081+ tss = init_tss + get_cpu();
27082 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27083 if (cpu_has_sep)
27084 tsk->thread.sysenter_cs = 0;
27085@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27086 goto cannot_handle;
27087 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27088 goto cannot_handle;
27089- intr_ptr = (unsigned long __user *) (i << 2);
27090+ intr_ptr = (__force unsigned long __user *) (i << 2);
27091 if (get_user(segoffs, intr_ptr))
27092 goto cannot_handle;
27093 if ((segoffs >> 16) == BIOSSEG)
27094diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27095index da6b35a..977e9cf 100644
27096--- a/arch/x86/kernel/vmlinux.lds.S
27097+++ b/arch/x86/kernel/vmlinux.lds.S
27098@@ -26,6 +26,13 @@
27099 #include <asm/page_types.h>
27100 #include <asm/cache.h>
27101 #include <asm/boot.h>
27102+#include <asm/segment.h>
27103+
27104+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27105+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27106+#else
27107+#define __KERNEL_TEXT_OFFSET 0
27108+#endif
27109
27110 #undef i386 /* in case the preprocessor is a 32bit one */
27111
27112@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27113
27114 PHDRS {
27115 text PT_LOAD FLAGS(5); /* R_E */
27116+#ifdef CONFIG_X86_32
27117+ module PT_LOAD FLAGS(5); /* R_E */
27118+#endif
27119+#ifdef CONFIG_XEN
27120+ rodata PT_LOAD FLAGS(5); /* R_E */
27121+#else
27122+ rodata PT_LOAD FLAGS(4); /* R__ */
27123+#endif
27124 data PT_LOAD FLAGS(6); /* RW_ */
27125-#ifdef CONFIG_X86_64
27126+ init.begin PT_LOAD FLAGS(6); /* RW_ */
27127 #ifdef CONFIG_SMP
27128 percpu PT_LOAD FLAGS(6); /* RW_ */
27129 #endif
27130+ text.init PT_LOAD FLAGS(5); /* R_E */
27131+ text.exit PT_LOAD FLAGS(5); /* R_E */
27132 init PT_LOAD FLAGS(7); /* RWE */
27133-#endif
27134 note PT_NOTE FLAGS(0); /* ___ */
27135 }
27136
27137 SECTIONS
27138 {
27139 #ifdef CONFIG_X86_32
27140- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27141- phys_startup_32 = startup_32 - LOAD_OFFSET;
27142+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27143 #else
27144- . = __START_KERNEL;
27145- phys_startup_64 = startup_64 - LOAD_OFFSET;
27146+ . = __START_KERNEL;
27147 #endif
27148
27149 /* Text and read-only data */
27150- .text : AT(ADDR(.text) - LOAD_OFFSET) {
27151- _text = .;
27152+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27153 /* bootstrapping code */
27154+#ifdef CONFIG_X86_32
27155+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27156+#else
27157+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27158+#endif
27159+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27160+ _text = .;
27161 HEAD_TEXT
27162 . = ALIGN(8);
27163 _stext = .;
27164@@ -104,13 +124,47 @@ SECTIONS
27165 IRQENTRY_TEXT
27166 *(.fixup)
27167 *(.gnu.warning)
27168- /* End of text section */
27169- _etext = .;
27170 } :text = 0x9090
27171
27172- NOTES :text :note
27173+ . += __KERNEL_TEXT_OFFSET;
27174
27175- EXCEPTION_TABLE(16) :text = 0x9090
27176+#ifdef CONFIG_X86_32
27177+ . = ALIGN(PAGE_SIZE);
27178+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27179+
27180+#ifdef CONFIG_PAX_KERNEXEC
27181+ MODULES_EXEC_VADDR = .;
27182+ BYTE(0)
27183+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27184+ . = ALIGN(HPAGE_SIZE) - 1;
27185+ MODULES_EXEC_END = .;
27186+#endif
27187+
27188+ } :module
27189+#endif
27190+
27191+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27192+ /* End of text section */
27193+ BYTE(0)
27194+ _etext = . - __KERNEL_TEXT_OFFSET;
27195+ }
27196+
27197+#ifdef CONFIG_X86_32
27198+ . = ALIGN(PAGE_SIZE);
27199+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27200+ . = ALIGN(PAGE_SIZE);
27201+ *(.empty_zero_page)
27202+ *(.initial_pg_fixmap)
27203+ *(.initial_pg_pmd)
27204+ *(.initial_page_table)
27205+ *(.swapper_pg_dir)
27206+ } :rodata
27207+#endif
27208+
27209+ . = ALIGN(PAGE_SIZE);
27210+ NOTES :rodata :note
27211+
27212+ EXCEPTION_TABLE(16) :rodata
27213
27214 #if defined(CONFIG_DEBUG_RODATA)
27215 /* .text should occupy whole number of pages */
27216@@ -122,16 +176,20 @@ SECTIONS
27217
27218 /* Data */
27219 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27220+
27221+#ifdef CONFIG_PAX_KERNEXEC
27222+ . = ALIGN(HPAGE_SIZE);
27223+#else
27224+ . = ALIGN(PAGE_SIZE);
27225+#endif
27226+
27227 /* Start of data section */
27228 _sdata = .;
27229
27230 /* init_task */
27231 INIT_TASK_DATA(THREAD_SIZE)
27232
27233-#ifdef CONFIG_X86_32
27234- /* 32 bit has nosave before _edata */
27235 NOSAVE_DATA
27236-#endif
27237
27238 PAGE_ALIGNED_DATA(PAGE_SIZE)
27239
27240@@ -172,12 +230,19 @@ SECTIONS
27241 #endif /* CONFIG_X86_64 */
27242
27243 /* Init code and data - will be freed after init */
27244- . = ALIGN(PAGE_SIZE);
27245 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27246+ BYTE(0)
27247+
27248+#ifdef CONFIG_PAX_KERNEXEC
27249+ . = ALIGN(HPAGE_SIZE);
27250+#else
27251+ . = ALIGN(PAGE_SIZE);
27252+#endif
27253+
27254 __init_begin = .; /* paired with __init_end */
27255- }
27256+ } :init.begin
27257
27258-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27259+#ifdef CONFIG_SMP
27260 /*
27261 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27262 * output PHDR, so the next output section - .init.text - should
27263@@ -186,12 +251,27 @@ SECTIONS
27264 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27265 #endif
27266
27267- INIT_TEXT_SECTION(PAGE_SIZE)
27268-#ifdef CONFIG_X86_64
27269- :init
27270-#endif
27271+ . = ALIGN(PAGE_SIZE);
27272+ init_begin = .;
27273+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27274+ VMLINUX_SYMBOL(_sinittext) = .;
27275+ INIT_TEXT
27276+ VMLINUX_SYMBOL(_einittext) = .;
27277+ . = ALIGN(PAGE_SIZE);
27278+ } :text.init
27279
27280- INIT_DATA_SECTION(16)
27281+ /*
27282+ * .exit.text is discard at runtime, not link time, to deal with
27283+ * references from .altinstructions and .eh_frame
27284+ */
27285+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27286+ EXIT_TEXT
27287+ . = ALIGN(16);
27288+ } :text.exit
27289+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
27290+
27291+ . = ALIGN(PAGE_SIZE);
27292+ INIT_DATA_SECTION(16) :init
27293
27294 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
27295 __x86_cpu_dev_start = .;
27296@@ -262,19 +342,12 @@ SECTIONS
27297 }
27298
27299 . = ALIGN(8);
27300- /*
27301- * .exit.text is discard at runtime, not link time, to deal with
27302- * references from .altinstructions and .eh_frame
27303- */
27304- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
27305- EXIT_TEXT
27306- }
27307
27308 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
27309 EXIT_DATA
27310 }
27311
27312-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
27313+#ifndef CONFIG_SMP
27314 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
27315 #endif
27316
27317@@ -293,16 +366,10 @@ SECTIONS
27318 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
27319 __smp_locks = .;
27320 *(.smp_locks)
27321- . = ALIGN(PAGE_SIZE);
27322 __smp_locks_end = .;
27323+ . = ALIGN(PAGE_SIZE);
27324 }
27325
27326-#ifdef CONFIG_X86_64
27327- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
27328- NOSAVE_DATA
27329- }
27330-#endif
27331-
27332 /* BSS */
27333 . = ALIGN(PAGE_SIZE);
27334 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
27335@@ -318,6 +385,7 @@ SECTIONS
27336 __brk_base = .;
27337 . += 64 * 1024; /* 64k alignment slop space */
27338 *(.brk_reservation) /* areas brk users have reserved */
27339+ . = ALIGN(HPAGE_SIZE);
27340 __brk_limit = .;
27341 }
27342
27343@@ -344,13 +412,12 @@ SECTIONS
27344 * for the boot processor.
27345 */
27346 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
27347-INIT_PER_CPU(gdt_page);
27348 INIT_PER_CPU(irq_stack_union);
27349
27350 /*
27351 * Build-time check on the image size:
27352 */
27353-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
27354+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
27355 "kernel image bigger than KERNEL_IMAGE_SIZE");
27356
27357 #ifdef CONFIG_SMP
27358diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
27359index 1f96f93..d5c8f7a 100644
27360--- a/arch/x86/kernel/vsyscall_64.c
27361+++ b/arch/x86/kernel/vsyscall_64.c
27362@@ -56,15 +56,13 @@
27363 DEFINE_VVAR(int, vgetcpu_mode);
27364 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
27365
27366-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
27367+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
27368
27369 static int __init vsyscall_setup(char *str)
27370 {
27371 if (str) {
27372 if (!strcmp("emulate", str))
27373 vsyscall_mode = EMULATE;
27374- else if (!strcmp("native", str))
27375- vsyscall_mode = NATIVE;
27376 else if (!strcmp("none", str))
27377 vsyscall_mode = NONE;
27378 else
27379@@ -323,8 +321,7 @@ do_ret:
27380 return true;
27381
27382 sigsegv:
27383- force_sig(SIGSEGV, current);
27384- return true;
27385+ do_group_exit(SIGKILL);
27386 }
27387
27388 /*
27389@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
27390 extern char __vvar_page;
27391 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
27392
27393- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
27394- vsyscall_mode == NATIVE
27395- ? PAGE_KERNEL_VSYSCALL
27396- : PAGE_KERNEL_VVAR);
27397+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
27398 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
27399 (unsigned long)VSYSCALL_START);
27400
27401diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
27402index 04068192..4d75aa6 100644
27403--- a/arch/x86/kernel/x8664_ksyms_64.c
27404+++ b/arch/x86/kernel/x8664_ksyms_64.c
27405@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
27406 EXPORT_SYMBOL(copy_user_generic_unrolled);
27407 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
27408 EXPORT_SYMBOL(__copy_user_nocache);
27409-EXPORT_SYMBOL(_copy_from_user);
27410-EXPORT_SYMBOL(_copy_to_user);
27411
27412 EXPORT_SYMBOL(copy_page);
27413 EXPORT_SYMBOL(clear_page);
27414@@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
27415 EXPORT_SYMBOL(___preempt_schedule_context);
27416 #endif
27417 #endif
27418+
27419+#ifdef CONFIG_PAX_PER_CPU_PGD
27420+EXPORT_SYMBOL(cpu_pgd);
27421+#endif
27422diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
27423index 021783b..6511282 100644
27424--- a/arch/x86/kernel/x86_init.c
27425+++ b/arch/x86/kernel/x86_init.c
27426@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
27427 static void default_nmi_init(void) { };
27428 static int default_i8042_detect(void) { return 1; };
27429
27430-struct x86_platform_ops x86_platform = {
27431+struct x86_platform_ops x86_platform __read_only = {
27432 .calibrate_tsc = native_calibrate_tsc,
27433 .get_wallclock = mach_get_cmos_time,
27434 .set_wallclock = mach_set_rtc_mmss,
27435@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
27436 EXPORT_SYMBOL_GPL(x86_platform);
27437
27438 #if defined(CONFIG_PCI_MSI)
27439-struct x86_msi_ops x86_msi = {
27440+struct x86_msi_ops x86_msi __read_only = {
27441 .setup_msi_irqs = native_setup_msi_irqs,
27442 .compose_msi_msg = native_compose_msi_msg,
27443 .teardown_msi_irq = native_teardown_msi_irq,
27444@@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
27445 }
27446 #endif
27447
27448-struct x86_io_apic_ops x86_io_apic_ops = {
27449+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
27450 .init = native_io_apic_init_mappings,
27451 .read = native_io_apic_read,
27452 .write = native_io_apic_write,
27453diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
27454index 422fd82..b2d262e 100644
27455--- a/arch/x86/kernel/xsave.c
27456+++ b/arch/x86/kernel/xsave.c
27457@@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27458
27459 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
27460 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
27461- err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27462+ err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27463
27464 if (!use_xsave())
27465 return err;
27466
27467- err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
27468+ err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
27469
27470 /*
27471 * Read the xstate_bv which we copied (directly from the cpu or
27472 * from the state in task struct) to the user buffers.
27473 */
27474- err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
27475+ err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
27476
27477 /*
27478 * For legacy compatible, we always set FP/SSE bits in the bit
27479@@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27480 */
27481 xstate_bv |= XSTATE_FPSSE;
27482
27483- err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
27484+ err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
27485
27486 return err;
27487 }
27488@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
27489 {
27490 int err;
27491
27492+ buf = (struct xsave_struct __user *)____m(buf);
27493 if (use_xsave())
27494 err = xsave_user(buf);
27495 else if (use_fxsr())
27496@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
27497 */
27498 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
27499 {
27500+ buf = (void __user *)____m(buf);
27501 if (use_xsave()) {
27502 if ((unsigned long)buf % 64 || fx_only) {
27503 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
27504diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
27505index c697625..a032162 100644
27506--- a/arch/x86/kvm/cpuid.c
27507+++ b/arch/x86/kvm/cpuid.c
27508@@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
27509 struct kvm_cpuid2 *cpuid,
27510 struct kvm_cpuid_entry2 __user *entries)
27511 {
27512- int r;
27513+ int r, i;
27514
27515 r = -E2BIG;
27516 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
27517 goto out;
27518 r = -EFAULT;
27519- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
27520- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
27521+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
27522 goto out;
27523+ for (i = 0; i < cpuid->nent; ++i) {
27524+ struct kvm_cpuid_entry2 cpuid_entry;
27525+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
27526+ goto out;
27527+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
27528+ }
27529 vcpu->arch.cpuid_nent = cpuid->nent;
27530 kvm_apic_set_version(vcpu);
27531 kvm_x86_ops->cpuid_update(vcpu);
27532@@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
27533 struct kvm_cpuid2 *cpuid,
27534 struct kvm_cpuid_entry2 __user *entries)
27535 {
27536- int r;
27537+ int r, i;
27538
27539 r = -E2BIG;
27540 if (cpuid->nent < vcpu->arch.cpuid_nent)
27541 goto out;
27542 r = -EFAULT;
27543- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
27544- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
27545+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
27546 goto out;
27547+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
27548+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
27549+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
27550+ goto out;
27551+ }
27552 return 0;
27553
27554 out:
27555diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
27556index d86ff15..e77b023 100644
27557--- a/arch/x86/kvm/lapic.c
27558+++ b/arch/x86/kvm/lapic.c
27559@@ -55,7 +55,7 @@
27560 #define APIC_BUS_CYCLE_NS 1
27561
27562 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
27563-#define apic_debug(fmt, arg...)
27564+#define apic_debug(fmt, arg...) do {} while (0)
27565
27566 #define APIC_LVT_NUM 6
27567 /* 14 is the version for Xeon and Pentium 8.4.8*/
27568diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
27569index ad75d77..a679d32 100644
27570--- a/arch/x86/kvm/paging_tmpl.h
27571+++ b/arch/x86/kvm/paging_tmpl.h
27572@@ -331,7 +331,7 @@ retry_walk:
27573 if (unlikely(kvm_is_error_hva(host_addr)))
27574 goto error;
27575
27576- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
27577+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
27578 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
27579 goto error;
27580 walker->ptep_user[walker->level - 1] = ptep_user;
27581diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
27582index c7168a5..09070fc 100644
27583--- a/arch/x86/kvm/svm.c
27584+++ b/arch/x86/kvm/svm.c
27585@@ -3497,7 +3497,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
27586 int cpu = raw_smp_processor_id();
27587
27588 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
27589+
27590+ pax_open_kernel();
27591 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
27592+ pax_close_kernel();
27593+
27594 load_TR_desc();
27595 }
27596
27597@@ -3898,6 +3902,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
27598 #endif
27599 #endif
27600
27601+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
27602+ __set_fs(current_thread_info()->addr_limit);
27603+#endif
27604+
27605 reload_tss(vcpu);
27606
27607 local_irq_disable();
27608diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
27609index da7837e..86c6ebf 100644
27610--- a/arch/x86/kvm/vmx.c
27611+++ b/arch/x86/kvm/vmx.c
27612@@ -1316,12 +1316,12 @@ static void vmcs_write64(unsigned long field, u64 value)
27613 #endif
27614 }
27615
27616-static void vmcs_clear_bits(unsigned long field, u32 mask)
27617+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
27618 {
27619 vmcs_writel(field, vmcs_readl(field) & ~mask);
27620 }
27621
27622-static void vmcs_set_bits(unsigned long field, u32 mask)
27623+static void vmcs_set_bits(unsigned long field, unsigned long mask)
27624 {
27625 vmcs_writel(field, vmcs_readl(field) | mask);
27626 }
27627@@ -1522,7 +1522,11 @@ static void reload_tss(void)
27628 struct desc_struct *descs;
27629
27630 descs = (void *)gdt->address;
27631+
27632+ pax_open_kernel();
27633 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
27634+ pax_close_kernel();
27635+
27636 load_TR_desc();
27637 }
27638
27639@@ -1746,6 +1750,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
27640 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
27641 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
27642
27643+#ifdef CONFIG_PAX_PER_CPU_PGD
27644+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
27645+#endif
27646+
27647 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
27648 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
27649 vmx->loaded_vmcs->cpu = cpu;
27650@@ -2033,7 +2041,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
27651 * reads and returns guest's timestamp counter "register"
27652 * guest_tsc = host_tsc + tsc_offset -- 21.3
27653 */
27654-static u64 guest_read_tsc(void)
27655+static u64 __intentional_overflow(-1) guest_read_tsc(void)
27656 {
27657 u64 host_tsc, tsc_offset;
27658
27659@@ -2987,8 +2995,11 @@ static __init int hardware_setup(void)
27660 if (!cpu_has_vmx_flexpriority())
27661 flexpriority_enabled = 0;
27662
27663- if (!cpu_has_vmx_tpr_shadow())
27664- kvm_x86_ops->update_cr8_intercept = NULL;
27665+ if (!cpu_has_vmx_tpr_shadow()) {
27666+ pax_open_kernel();
27667+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
27668+ pax_close_kernel();
27669+ }
27670
27671 if (enable_ept && !cpu_has_vmx_ept_2m_page())
27672 kvm_disable_largepages();
27673@@ -2999,13 +3010,15 @@ static __init int hardware_setup(void)
27674 if (!cpu_has_vmx_apicv())
27675 enable_apicv = 0;
27676
27677+ pax_open_kernel();
27678 if (enable_apicv)
27679- kvm_x86_ops->update_cr8_intercept = NULL;
27680+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
27681 else {
27682- kvm_x86_ops->hwapic_irr_update = NULL;
27683- kvm_x86_ops->deliver_posted_interrupt = NULL;
27684- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
27685+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
27686+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
27687+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
27688 }
27689+ pax_close_kernel();
27690
27691 if (nested)
27692 nested_vmx_setup_ctls_msrs();
27693@@ -4134,7 +4147,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
27694
27695 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
27696 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
27697+
27698+#ifndef CONFIG_PAX_PER_CPU_PGD
27699 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
27700+#endif
27701
27702 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
27703 #ifdef CONFIG_X86_64
27704@@ -4156,7 +4172,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
27705 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
27706 vmx->host_idt_base = dt.address;
27707
27708- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
27709+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
27710
27711 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
27712 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
27713@@ -7219,6 +7235,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27714 "jmp 2f \n\t"
27715 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
27716 "2: "
27717+
27718+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27719+ "ljmp %[cs],$3f\n\t"
27720+ "3: "
27721+#endif
27722+
27723 /* Save guest registers, load host registers, keep flags */
27724 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
27725 "pop %0 \n\t"
27726@@ -7271,6 +7293,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27727 #endif
27728 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
27729 [wordsize]"i"(sizeof(ulong))
27730+
27731+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27732+ ,[cs]"i"(__KERNEL_CS)
27733+#endif
27734+
27735 : "cc", "memory"
27736 #ifdef CONFIG_X86_64
27737 , "rax", "rbx", "rdi", "rsi"
27738@@ -7284,7 +7311,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27739 if (debugctlmsr)
27740 update_debugctlmsr(debugctlmsr);
27741
27742-#ifndef CONFIG_X86_64
27743+#ifdef CONFIG_X86_32
27744 /*
27745 * The sysexit path does not restore ds/es, so we must set them to
27746 * a reasonable value ourselves.
27747@@ -7293,8 +7320,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27748 * may be executed in interrupt context, which saves and restore segments
27749 * around it, nullifying its effect.
27750 */
27751- loadsegment(ds, __USER_DS);
27752- loadsegment(es, __USER_DS);
27753+ loadsegment(ds, __KERNEL_DS);
27754+ loadsegment(es, __KERNEL_DS);
27755+ loadsegment(ss, __KERNEL_DS);
27756+
27757+#ifdef CONFIG_PAX_KERNEXEC
27758+ loadsegment(fs, __KERNEL_PERCPU);
27759+#endif
27760+
27761+#ifdef CONFIG_PAX_MEMORY_UDEREF
27762+ __set_fs(current_thread_info()->addr_limit);
27763+#endif
27764+
27765 #endif
27766
27767 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
27768diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
27769index d89d51b..f3c612a 100644
27770--- a/arch/x86/kvm/x86.c
27771+++ b/arch/x86/kvm/x86.c
27772@@ -1791,8 +1791,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
27773 {
27774 struct kvm *kvm = vcpu->kvm;
27775 int lm = is_long_mode(vcpu);
27776- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
27777- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
27778+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
27779+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
27780 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
27781 : kvm->arch.xen_hvm_config.blob_size_32;
27782 u32 page_num = data & ~PAGE_MASK;
27783@@ -2676,6 +2676,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
27784 if (n < msr_list.nmsrs)
27785 goto out;
27786 r = -EFAULT;
27787+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
27788+ goto out;
27789 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
27790 num_msrs_to_save * sizeof(u32)))
27791 goto out;
27792@@ -5485,7 +5487,7 @@ static struct notifier_block pvclock_gtod_notifier = {
27793 };
27794 #endif
27795
27796-int kvm_arch_init(void *opaque)
27797+int kvm_arch_init(const void *opaque)
27798 {
27799 int r;
27800 struct kvm_x86_ops *ops = opaque;
27801diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
27802index bdf8532..f63c587 100644
27803--- a/arch/x86/lguest/boot.c
27804+++ b/arch/x86/lguest/boot.c
27805@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
27806 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
27807 * Launcher to reboot us.
27808 */
27809-static void lguest_restart(char *reason)
27810+static __noreturn void lguest_restart(char *reason)
27811 {
27812 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
27813+ BUG();
27814 }
27815
27816 /*G:050
27817diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
27818index 00933d5..3a64af9 100644
27819--- a/arch/x86/lib/atomic64_386_32.S
27820+++ b/arch/x86/lib/atomic64_386_32.S
27821@@ -48,6 +48,10 @@ BEGIN(read)
27822 movl (v), %eax
27823 movl 4(v), %edx
27824 RET_ENDP
27825+BEGIN(read_unchecked)
27826+ movl (v), %eax
27827+ movl 4(v), %edx
27828+RET_ENDP
27829 #undef v
27830
27831 #define v %esi
27832@@ -55,6 +59,10 @@ BEGIN(set)
27833 movl %ebx, (v)
27834 movl %ecx, 4(v)
27835 RET_ENDP
27836+BEGIN(set_unchecked)
27837+ movl %ebx, (v)
27838+ movl %ecx, 4(v)
27839+RET_ENDP
27840 #undef v
27841
27842 #define v %esi
27843@@ -70,6 +78,20 @@ RET_ENDP
27844 BEGIN(add)
27845 addl %eax, (v)
27846 adcl %edx, 4(v)
27847+
27848+#ifdef CONFIG_PAX_REFCOUNT
27849+ jno 0f
27850+ subl %eax, (v)
27851+ sbbl %edx, 4(v)
27852+ int $4
27853+0:
27854+ _ASM_EXTABLE(0b, 0b)
27855+#endif
27856+
27857+RET_ENDP
27858+BEGIN(add_unchecked)
27859+ addl %eax, (v)
27860+ adcl %edx, 4(v)
27861 RET_ENDP
27862 #undef v
27863
27864@@ -77,6 +99,24 @@ RET_ENDP
27865 BEGIN(add_return)
27866 addl (v), %eax
27867 adcl 4(v), %edx
27868+
27869+#ifdef CONFIG_PAX_REFCOUNT
27870+ into
27871+1234:
27872+ _ASM_EXTABLE(1234b, 2f)
27873+#endif
27874+
27875+ movl %eax, (v)
27876+ movl %edx, 4(v)
27877+
27878+#ifdef CONFIG_PAX_REFCOUNT
27879+2:
27880+#endif
27881+
27882+RET_ENDP
27883+BEGIN(add_return_unchecked)
27884+ addl (v), %eax
27885+ adcl 4(v), %edx
27886 movl %eax, (v)
27887 movl %edx, 4(v)
27888 RET_ENDP
27889@@ -86,6 +126,20 @@ RET_ENDP
27890 BEGIN(sub)
27891 subl %eax, (v)
27892 sbbl %edx, 4(v)
27893+
27894+#ifdef CONFIG_PAX_REFCOUNT
27895+ jno 0f
27896+ addl %eax, (v)
27897+ adcl %edx, 4(v)
27898+ int $4
27899+0:
27900+ _ASM_EXTABLE(0b, 0b)
27901+#endif
27902+
27903+RET_ENDP
27904+BEGIN(sub_unchecked)
27905+ subl %eax, (v)
27906+ sbbl %edx, 4(v)
27907 RET_ENDP
27908 #undef v
27909
27910@@ -96,6 +150,27 @@ BEGIN(sub_return)
27911 sbbl $0, %edx
27912 addl (v), %eax
27913 adcl 4(v), %edx
27914+
27915+#ifdef CONFIG_PAX_REFCOUNT
27916+ into
27917+1234:
27918+ _ASM_EXTABLE(1234b, 2f)
27919+#endif
27920+
27921+ movl %eax, (v)
27922+ movl %edx, 4(v)
27923+
27924+#ifdef CONFIG_PAX_REFCOUNT
27925+2:
27926+#endif
27927+
27928+RET_ENDP
27929+BEGIN(sub_return_unchecked)
27930+ negl %edx
27931+ negl %eax
27932+ sbbl $0, %edx
27933+ addl (v), %eax
27934+ adcl 4(v), %edx
27935 movl %eax, (v)
27936 movl %edx, 4(v)
27937 RET_ENDP
27938@@ -105,6 +180,20 @@ RET_ENDP
27939 BEGIN(inc)
27940 addl $1, (v)
27941 adcl $0, 4(v)
27942+
27943+#ifdef CONFIG_PAX_REFCOUNT
27944+ jno 0f
27945+ subl $1, (v)
27946+ sbbl $0, 4(v)
27947+ int $4
27948+0:
27949+ _ASM_EXTABLE(0b, 0b)
27950+#endif
27951+
27952+RET_ENDP
27953+BEGIN(inc_unchecked)
27954+ addl $1, (v)
27955+ adcl $0, 4(v)
27956 RET_ENDP
27957 #undef v
27958
27959@@ -114,6 +203,26 @@ BEGIN(inc_return)
27960 movl 4(v), %edx
27961 addl $1, %eax
27962 adcl $0, %edx
27963+
27964+#ifdef CONFIG_PAX_REFCOUNT
27965+ into
27966+1234:
27967+ _ASM_EXTABLE(1234b, 2f)
27968+#endif
27969+
27970+ movl %eax, (v)
27971+ movl %edx, 4(v)
27972+
27973+#ifdef CONFIG_PAX_REFCOUNT
27974+2:
27975+#endif
27976+
27977+RET_ENDP
27978+BEGIN(inc_return_unchecked)
27979+ movl (v), %eax
27980+ movl 4(v), %edx
27981+ addl $1, %eax
27982+ adcl $0, %edx
27983 movl %eax, (v)
27984 movl %edx, 4(v)
27985 RET_ENDP
27986@@ -123,6 +232,20 @@ RET_ENDP
27987 BEGIN(dec)
27988 subl $1, (v)
27989 sbbl $0, 4(v)
27990+
27991+#ifdef CONFIG_PAX_REFCOUNT
27992+ jno 0f
27993+ addl $1, (v)
27994+ adcl $0, 4(v)
27995+ int $4
27996+0:
27997+ _ASM_EXTABLE(0b, 0b)
27998+#endif
27999+
28000+RET_ENDP
28001+BEGIN(dec_unchecked)
28002+ subl $1, (v)
28003+ sbbl $0, 4(v)
28004 RET_ENDP
28005 #undef v
28006
28007@@ -132,6 +255,26 @@ BEGIN(dec_return)
28008 movl 4(v), %edx
28009 subl $1, %eax
28010 sbbl $0, %edx
28011+
28012+#ifdef CONFIG_PAX_REFCOUNT
28013+ into
28014+1234:
28015+ _ASM_EXTABLE(1234b, 2f)
28016+#endif
28017+
28018+ movl %eax, (v)
28019+ movl %edx, 4(v)
28020+
28021+#ifdef CONFIG_PAX_REFCOUNT
28022+2:
28023+#endif
28024+
28025+RET_ENDP
28026+BEGIN(dec_return_unchecked)
28027+ movl (v), %eax
28028+ movl 4(v), %edx
28029+ subl $1, %eax
28030+ sbbl $0, %edx
28031 movl %eax, (v)
28032 movl %edx, 4(v)
28033 RET_ENDP
28034@@ -143,6 +286,13 @@ BEGIN(add_unless)
28035 adcl %edx, %edi
28036 addl (v), %eax
28037 adcl 4(v), %edx
28038+
28039+#ifdef CONFIG_PAX_REFCOUNT
28040+ into
28041+1234:
28042+ _ASM_EXTABLE(1234b, 2f)
28043+#endif
28044+
28045 cmpl %eax, %ecx
28046 je 3f
28047 1:
28048@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28049 1:
28050 addl $1, %eax
28051 adcl $0, %edx
28052+
28053+#ifdef CONFIG_PAX_REFCOUNT
28054+ into
28055+1234:
28056+ _ASM_EXTABLE(1234b, 2f)
28057+#endif
28058+
28059 movl %eax, (v)
28060 movl %edx, 4(v)
28061 movl $1, %eax
28062@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28063 movl 4(v), %edx
28064 subl $1, %eax
28065 sbbl $0, %edx
28066+
28067+#ifdef CONFIG_PAX_REFCOUNT
28068+ into
28069+1234:
28070+ _ASM_EXTABLE(1234b, 1f)
28071+#endif
28072+
28073 js 1f
28074 movl %eax, (v)
28075 movl %edx, 4(v)
28076diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28077index f5cc9eb..51fa319 100644
28078--- a/arch/x86/lib/atomic64_cx8_32.S
28079+++ b/arch/x86/lib/atomic64_cx8_32.S
28080@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28081 CFI_STARTPROC
28082
28083 read64 %ecx
28084+ pax_force_retaddr
28085 ret
28086 CFI_ENDPROC
28087 ENDPROC(atomic64_read_cx8)
28088
28089+ENTRY(atomic64_read_unchecked_cx8)
28090+ CFI_STARTPROC
28091+
28092+ read64 %ecx
28093+ pax_force_retaddr
28094+ ret
28095+ CFI_ENDPROC
28096+ENDPROC(atomic64_read_unchecked_cx8)
28097+
28098 ENTRY(atomic64_set_cx8)
28099 CFI_STARTPROC
28100
28101@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28102 cmpxchg8b (%esi)
28103 jne 1b
28104
28105+ pax_force_retaddr
28106 ret
28107 CFI_ENDPROC
28108 ENDPROC(atomic64_set_cx8)
28109
28110+ENTRY(atomic64_set_unchecked_cx8)
28111+ CFI_STARTPROC
28112+
28113+1:
28114+/* we don't need LOCK_PREFIX since aligned 64-bit writes
28115+ * are atomic on 586 and newer */
28116+ cmpxchg8b (%esi)
28117+ jne 1b
28118+
28119+ pax_force_retaddr
28120+ ret
28121+ CFI_ENDPROC
28122+ENDPROC(atomic64_set_unchecked_cx8)
28123+
28124 ENTRY(atomic64_xchg_cx8)
28125 CFI_STARTPROC
28126
28127@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28128 cmpxchg8b (%esi)
28129 jne 1b
28130
28131+ pax_force_retaddr
28132 ret
28133 CFI_ENDPROC
28134 ENDPROC(atomic64_xchg_cx8)
28135
28136-.macro addsub_return func ins insc
28137-ENTRY(atomic64_\func\()_return_cx8)
28138+.macro addsub_return func ins insc unchecked=""
28139+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28140 CFI_STARTPROC
28141 SAVE ebp
28142 SAVE ebx
28143@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28144 movl %edx, %ecx
28145 \ins\()l %esi, %ebx
28146 \insc\()l %edi, %ecx
28147+
28148+.ifb \unchecked
28149+#ifdef CONFIG_PAX_REFCOUNT
28150+ into
28151+2:
28152+ _ASM_EXTABLE(2b, 3f)
28153+#endif
28154+.endif
28155+
28156 LOCK_PREFIX
28157 cmpxchg8b (%ebp)
28158 jne 1b
28159-
28160-10:
28161 movl %ebx, %eax
28162 movl %ecx, %edx
28163+
28164+.ifb \unchecked
28165+#ifdef CONFIG_PAX_REFCOUNT
28166+3:
28167+#endif
28168+.endif
28169+
28170 RESTORE edi
28171 RESTORE esi
28172 RESTORE ebx
28173 RESTORE ebp
28174+ pax_force_retaddr
28175 ret
28176 CFI_ENDPROC
28177-ENDPROC(atomic64_\func\()_return_cx8)
28178+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28179 .endm
28180
28181 addsub_return add add adc
28182 addsub_return sub sub sbb
28183+addsub_return add add adc _unchecked
28184+addsub_return sub sub sbb _unchecked
28185
28186-.macro incdec_return func ins insc
28187-ENTRY(atomic64_\func\()_return_cx8)
28188+.macro incdec_return func ins insc unchecked=""
28189+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28190 CFI_STARTPROC
28191 SAVE ebx
28192
28193@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28194 movl %edx, %ecx
28195 \ins\()l $1, %ebx
28196 \insc\()l $0, %ecx
28197+
28198+.ifb \unchecked
28199+#ifdef CONFIG_PAX_REFCOUNT
28200+ into
28201+2:
28202+ _ASM_EXTABLE(2b, 3f)
28203+#endif
28204+.endif
28205+
28206 LOCK_PREFIX
28207 cmpxchg8b (%esi)
28208 jne 1b
28209
28210-10:
28211 movl %ebx, %eax
28212 movl %ecx, %edx
28213+
28214+.ifb \unchecked
28215+#ifdef CONFIG_PAX_REFCOUNT
28216+3:
28217+#endif
28218+.endif
28219+
28220 RESTORE ebx
28221+ pax_force_retaddr
28222 ret
28223 CFI_ENDPROC
28224-ENDPROC(atomic64_\func\()_return_cx8)
28225+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28226 .endm
28227
28228 incdec_return inc add adc
28229 incdec_return dec sub sbb
28230+incdec_return inc add adc _unchecked
28231+incdec_return dec sub sbb _unchecked
28232
28233 ENTRY(atomic64_dec_if_positive_cx8)
28234 CFI_STARTPROC
28235@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28236 movl %edx, %ecx
28237 subl $1, %ebx
28238 sbb $0, %ecx
28239+
28240+#ifdef CONFIG_PAX_REFCOUNT
28241+ into
28242+1234:
28243+ _ASM_EXTABLE(1234b, 2f)
28244+#endif
28245+
28246 js 2f
28247 LOCK_PREFIX
28248 cmpxchg8b (%esi)
28249@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28250 movl %ebx, %eax
28251 movl %ecx, %edx
28252 RESTORE ebx
28253+ pax_force_retaddr
28254 ret
28255 CFI_ENDPROC
28256 ENDPROC(atomic64_dec_if_positive_cx8)
28257@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28258 movl %edx, %ecx
28259 addl %ebp, %ebx
28260 adcl %edi, %ecx
28261+
28262+#ifdef CONFIG_PAX_REFCOUNT
28263+ into
28264+1234:
28265+ _ASM_EXTABLE(1234b, 3f)
28266+#endif
28267+
28268 LOCK_PREFIX
28269 cmpxchg8b (%esi)
28270 jne 1b
28271@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28272 CFI_ADJUST_CFA_OFFSET -8
28273 RESTORE ebx
28274 RESTORE ebp
28275+ pax_force_retaddr
28276 ret
28277 4:
28278 cmpl %edx, 4(%esp)
28279@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28280 xorl %ecx, %ecx
28281 addl $1, %ebx
28282 adcl %edx, %ecx
28283+
28284+#ifdef CONFIG_PAX_REFCOUNT
28285+ into
28286+1234:
28287+ _ASM_EXTABLE(1234b, 3f)
28288+#endif
28289+
28290 LOCK_PREFIX
28291 cmpxchg8b (%esi)
28292 jne 1b
28293@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
28294 movl $1, %eax
28295 3:
28296 RESTORE ebx
28297+ pax_force_retaddr
28298 ret
28299 CFI_ENDPROC
28300 ENDPROC(atomic64_inc_not_zero_cx8)
28301diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
28302index e78b8ee..7e173a8 100644
28303--- a/arch/x86/lib/checksum_32.S
28304+++ b/arch/x86/lib/checksum_32.S
28305@@ -29,7 +29,8 @@
28306 #include <asm/dwarf2.h>
28307 #include <asm/errno.h>
28308 #include <asm/asm.h>
28309-
28310+#include <asm/segment.h>
28311+
28312 /*
28313 * computes a partial checksum, e.g. for TCP/UDP fragments
28314 */
28315@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
28316
28317 #define ARGBASE 16
28318 #define FP 12
28319-
28320-ENTRY(csum_partial_copy_generic)
28321+
28322+ENTRY(csum_partial_copy_generic_to_user)
28323 CFI_STARTPROC
28324+
28325+#ifdef CONFIG_PAX_MEMORY_UDEREF
28326+ pushl_cfi %gs
28327+ popl_cfi %es
28328+ jmp csum_partial_copy_generic
28329+#endif
28330+
28331+ENTRY(csum_partial_copy_generic_from_user)
28332+
28333+#ifdef CONFIG_PAX_MEMORY_UDEREF
28334+ pushl_cfi %gs
28335+ popl_cfi %ds
28336+#endif
28337+
28338+ENTRY(csum_partial_copy_generic)
28339 subl $4,%esp
28340 CFI_ADJUST_CFA_OFFSET 4
28341 pushl_cfi %edi
28342@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
28343 jmp 4f
28344 SRC(1: movw (%esi), %bx )
28345 addl $2, %esi
28346-DST( movw %bx, (%edi) )
28347+DST( movw %bx, %es:(%edi) )
28348 addl $2, %edi
28349 addw %bx, %ax
28350 adcl $0, %eax
28351@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
28352 SRC(1: movl (%esi), %ebx )
28353 SRC( movl 4(%esi), %edx )
28354 adcl %ebx, %eax
28355-DST( movl %ebx, (%edi) )
28356+DST( movl %ebx, %es:(%edi) )
28357 adcl %edx, %eax
28358-DST( movl %edx, 4(%edi) )
28359+DST( movl %edx, %es:4(%edi) )
28360
28361 SRC( movl 8(%esi), %ebx )
28362 SRC( movl 12(%esi), %edx )
28363 adcl %ebx, %eax
28364-DST( movl %ebx, 8(%edi) )
28365+DST( movl %ebx, %es:8(%edi) )
28366 adcl %edx, %eax
28367-DST( movl %edx, 12(%edi) )
28368+DST( movl %edx, %es:12(%edi) )
28369
28370 SRC( movl 16(%esi), %ebx )
28371 SRC( movl 20(%esi), %edx )
28372 adcl %ebx, %eax
28373-DST( movl %ebx, 16(%edi) )
28374+DST( movl %ebx, %es:16(%edi) )
28375 adcl %edx, %eax
28376-DST( movl %edx, 20(%edi) )
28377+DST( movl %edx, %es:20(%edi) )
28378
28379 SRC( movl 24(%esi), %ebx )
28380 SRC( movl 28(%esi), %edx )
28381 adcl %ebx, %eax
28382-DST( movl %ebx, 24(%edi) )
28383+DST( movl %ebx, %es:24(%edi) )
28384 adcl %edx, %eax
28385-DST( movl %edx, 28(%edi) )
28386+DST( movl %edx, %es:28(%edi) )
28387
28388 lea 32(%esi), %esi
28389 lea 32(%edi), %edi
28390@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
28391 shrl $2, %edx # This clears CF
28392 SRC(3: movl (%esi), %ebx )
28393 adcl %ebx, %eax
28394-DST( movl %ebx, (%edi) )
28395+DST( movl %ebx, %es:(%edi) )
28396 lea 4(%esi), %esi
28397 lea 4(%edi), %edi
28398 dec %edx
28399@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
28400 jb 5f
28401 SRC( movw (%esi), %cx )
28402 leal 2(%esi), %esi
28403-DST( movw %cx, (%edi) )
28404+DST( movw %cx, %es:(%edi) )
28405 leal 2(%edi), %edi
28406 je 6f
28407 shll $16,%ecx
28408 SRC(5: movb (%esi), %cl )
28409-DST( movb %cl, (%edi) )
28410+DST( movb %cl, %es:(%edi) )
28411 6: addl %ecx, %eax
28412 adcl $0, %eax
28413 7:
28414@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
28415
28416 6001:
28417 movl ARGBASE+20(%esp), %ebx # src_err_ptr
28418- movl $-EFAULT, (%ebx)
28419+ movl $-EFAULT, %ss:(%ebx)
28420
28421 # zero the complete destination - computing the rest
28422 # is too much work
28423@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
28424
28425 6002:
28426 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28427- movl $-EFAULT,(%ebx)
28428+ movl $-EFAULT,%ss:(%ebx)
28429 jmp 5000b
28430
28431 .previous
28432
28433+ pushl_cfi %ss
28434+ popl_cfi %ds
28435+ pushl_cfi %ss
28436+ popl_cfi %es
28437 popl_cfi %ebx
28438 CFI_RESTORE ebx
28439 popl_cfi %esi
28440@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
28441 popl_cfi %ecx # equivalent to addl $4,%esp
28442 ret
28443 CFI_ENDPROC
28444-ENDPROC(csum_partial_copy_generic)
28445+ENDPROC(csum_partial_copy_generic_to_user)
28446
28447 #else
28448
28449 /* Version for PentiumII/PPro */
28450
28451 #define ROUND1(x) \
28452+ nop; nop; nop; \
28453 SRC(movl x(%esi), %ebx ) ; \
28454 addl %ebx, %eax ; \
28455- DST(movl %ebx, x(%edi) ) ;
28456+ DST(movl %ebx, %es:x(%edi)) ;
28457
28458 #define ROUND(x) \
28459+ nop; nop; nop; \
28460 SRC(movl x(%esi), %ebx ) ; \
28461 adcl %ebx, %eax ; \
28462- DST(movl %ebx, x(%edi) ) ;
28463+ DST(movl %ebx, %es:x(%edi)) ;
28464
28465 #define ARGBASE 12
28466-
28467-ENTRY(csum_partial_copy_generic)
28468+
28469+ENTRY(csum_partial_copy_generic_to_user)
28470 CFI_STARTPROC
28471+
28472+#ifdef CONFIG_PAX_MEMORY_UDEREF
28473+ pushl_cfi %gs
28474+ popl_cfi %es
28475+ jmp csum_partial_copy_generic
28476+#endif
28477+
28478+ENTRY(csum_partial_copy_generic_from_user)
28479+
28480+#ifdef CONFIG_PAX_MEMORY_UDEREF
28481+ pushl_cfi %gs
28482+ popl_cfi %ds
28483+#endif
28484+
28485+ENTRY(csum_partial_copy_generic)
28486 pushl_cfi %ebx
28487 CFI_REL_OFFSET ebx, 0
28488 pushl_cfi %edi
28489@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
28490 subl %ebx, %edi
28491 lea -1(%esi),%edx
28492 andl $-32,%edx
28493- lea 3f(%ebx,%ebx), %ebx
28494+ lea 3f(%ebx,%ebx,2), %ebx
28495 testl %esi, %esi
28496 jmp *%ebx
28497 1: addl $64,%esi
28498@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
28499 jb 5f
28500 SRC( movw (%esi), %dx )
28501 leal 2(%esi), %esi
28502-DST( movw %dx, (%edi) )
28503+DST( movw %dx, %es:(%edi) )
28504 leal 2(%edi), %edi
28505 je 6f
28506 shll $16,%edx
28507 5:
28508 SRC( movb (%esi), %dl )
28509-DST( movb %dl, (%edi) )
28510+DST( movb %dl, %es:(%edi) )
28511 6: addl %edx, %eax
28512 adcl $0, %eax
28513 7:
28514 .section .fixup, "ax"
28515 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
28516- movl $-EFAULT, (%ebx)
28517+ movl $-EFAULT, %ss:(%ebx)
28518 # zero the complete destination (computing the rest is too much work)
28519 movl ARGBASE+8(%esp),%edi # dst
28520 movl ARGBASE+12(%esp),%ecx # len
28521@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
28522 rep; stosb
28523 jmp 7b
28524 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28525- movl $-EFAULT, (%ebx)
28526+ movl $-EFAULT, %ss:(%ebx)
28527 jmp 7b
28528 .previous
28529
28530+#ifdef CONFIG_PAX_MEMORY_UDEREF
28531+ pushl_cfi %ss
28532+ popl_cfi %ds
28533+ pushl_cfi %ss
28534+ popl_cfi %es
28535+#endif
28536+
28537 popl_cfi %esi
28538 CFI_RESTORE esi
28539 popl_cfi %edi
28540@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
28541 CFI_RESTORE ebx
28542 ret
28543 CFI_ENDPROC
28544-ENDPROC(csum_partial_copy_generic)
28545+ENDPROC(csum_partial_copy_generic_to_user)
28546
28547 #undef ROUND
28548 #undef ROUND1
28549diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
28550index f2145cf..cea889d 100644
28551--- a/arch/x86/lib/clear_page_64.S
28552+++ b/arch/x86/lib/clear_page_64.S
28553@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
28554 movl $4096/8,%ecx
28555 xorl %eax,%eax
28556 rep stosq
28557+ pax_force_retaddr
28558 ret
28559 CFI_ENDPROC
28560 ENDPROC(clear_page_c)
28561@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
28562 movl $4096,%ecx
28563 xorl %eax,%eax
28564 rep stosb
28565+ pax_force_retaddr
28566 ret
28567 CFI_ENDPROC
28568 ENDPROC(clear_page_c_e)
28569@@ -43,6 +45,7 @@ ENTRY(clear_page)
28570 leaq 64(%rdi),%rdi
28571 jnz .Lloop
28572 nop
28573+ pax_force_retaddr
28574 ret
28575 CFI_ENDPROC
28576 .Lclear_page_end:
28577@@ -58,7 +61,7 @@ ENDPROC(clear_page)
28578
28579 #include <asm/cpufeature.h>
28580
28581- .section .altinstr_replacement,"ax"
28582+ .section .altinstr_replacement,"a"
28583 1: .byte 0xeb /* jmp <disp8> */
28584 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
28585 2: .byte 0xeb /* jmp <disp8> */
28586diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
28587index 1e572c5..2a162cd 100644
28588--- a/arch/x86/lib/cmpxchg16b_emu.S
28589+++ b/arch/x86/lib/cmpxchg16b_emu.S
28590@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
28591
28592 popf
28593 mov $1, %al
28594+ pax_force_retaddr
28595 ret
28596
28597 not_same:
28598 popf
28599 xor %al,%al
28600+ pax_force_retaddr
28601 ret
28602
28603 CFI_ENDPROC
28604diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
28605index 176cca6..e0d658e 100644
28606--- a/arch/x86/lib/copy_page_64.S
28607+++ b/arch/x86/lib/copy_page_64.S
28608@@ -9,6 +9,7 @@ copy_page_rep:
28609 CFI_STARTPROC
28610 movl $4096/8, %ecx
28611 rep movsq
28612+ pax_force_retaddr
28613 ret
28614 CFI_ENDPROC
28615 ENDPROC(copy_page_rep)
28616@@ -24,8 +25,8 @@ ENTRY(copy_page)
28617 CFI_ADJUST_CFA_OFFSET 2*8
28618 movq %rbx, (%rsp)
28619 CFI_REL_OFFSET rbx, 0
28620- movq %r12, 1*8(%rsp)
28621- CFI_REL_OFFSET r12, 1*8
28622+ movq %r13, 1*8(%rsp)
28623+ CFI_REL_OFFSET r13, 1*8
28624
28625 movl $(4096/64)-5, %ecx
28626 .p2align 4
28627@@ -38,7 +39,7 @@ ENTRY(copy_page)
28628 movq 0x8*4(%rsi), %r9
28629 movq 0x8*5(%rsi), %r10
28630 movq 0x8*6(%rsi), %r11
28631- movq 0x8*7(%rsi), %r12
28632+ movq 0x8*7(%rsi), %r13
28633
28634 prefetcht0 5*64(%rsi)
28635
28636@@ -49,7 +50,7 @@ ENTRY(copy_page)
28637 movq %r9, 0x8*4(%rdi)
28638 movq %r10, 0x8*5(%rdi)
28639 movq %r11, 0x8*6(%rdi)
28640- movq %r12, 0x8*7(%rdi)
28641+ movq %r13, 0x8*7(%rdi)
28642
28643 leaq 64 (%rsi), %rsi
28644 leaq 64 (%rdi), %rdi
28645@@ -68,7 +69,7 @@ ENTRY(copy_page)
28646 movq 0x8*4(%rsi), %r9
28647 movq 0x8*5(%rsi), %r10
28648 movq 0x8*6(%rsi), %r11
28649- movq 0x8*7(%rsi), %r12
28650+ movq 0x8*7(%rsi), %r13
28651
28652 movq %rax, 0x8*0(%rdi)
28653 movq %rbx, 0x8*1(%rdi)
28654@@ -77,7 +78,7 @@ ENTRY(copy_page)
28655 movq %r9, 0x8*4(%rdi)
28656 movq %r10, 0x8*5(%rdi)
28657 movq %r11, 0x8*6(%rdi)
28658- movq %r12, 0x8*7(%rdi)
28659+ movq %r13, 0x8*7(%rdi)
28660
28661 leaq 64(%rdi), %rdi
28662 leaq 64(%rsi), %rsi
28663@@ -85,10 +86,11 @@ ENTRY(copy_page)
28664
28665 movq (%rsp), %rbx
28666 CFI_RESTORE rbx
28667- movq 1*8(%rsp), %r12
28668- CFI_RESTORE r12
28669+ movq 1*8(%rsp), %r13
28670+ CFI_RESTORE r13
28671 addq $2*8, %rsp
28672 CFI_ADJUST_CFA_OFFSET -2*8
28673+ pax_force_retaddr
28674 ret
28675 .Lcopy_page_end:
28676 CFI_ENDPROC
28677@@ -99,7 +101,7 @@ ENDPROC(copy_page)
28678
28679 #include <asm/cpufeature.h>
28680
28681- .section .altinstr_replacement,"ax"
28682+ .section .altinstr_replacement,"a"
28683 1: .byte 0xeb /* jmp <disp8> */
28684 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
28685 2:
28686diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
28687index a30ca15..407412b 100644
28688--- a/arch/x86/lib/copy_user_64.S
28689+++ b/arch/x86/lib/copy_user_64.S
28690@@ -18,31 +18,7 @@
28691 #include <asm/alternative-asm.h>
28692 #include <asm/asm.h>
28693 #include <asm/smap.h>
28694-
28695-/*
28696- * By placing feature2 after feature1 in altinstructions section, we logically
28697- * implement:
28698- * If CPU has feature2, jmp to alt2 is used
28699- * else if CPU has feature1, jmp to alt1 is used
28700- * else jmp to orig is used.
28701- */
28702- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
28703-0:
28704- .byte 0xe9 /* 32bit jump */
28705- .long \orig-1f /* by default jump to orig */
28706-1:
28707- .section .altinstr_replacement,"ax"
28708-2: .byte 0xe9 /* near jump with 32bit immediate */
28709- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
28710-3: .byte 0xe9 /* near jump with 32bit immediate */
28711- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
28712- .previous
28713-
28714- .section .altinstructions,"a"
28715- altinstruction_entry 0b,2b,\feature1,5,5
28716- altinstruction_entry 0b,3b,\feature2,5,5
28717- .previous
28718- .endm
28719+#include <asm/pgtable.h>
28720
28721 .macro ALIGN_DESTINATION
28722 #ifdef FIX_ALIGNMENT
28723@@ -70,52 +46,6 @@
28724 #endif
28725 .endm
28726
28727-/* Standard copy_to_user with segment limit checking */
28728-ENTRY(_copy_to_user)
28729- CFI_STARTPROC
28730- GET_THREAD_INFO(%rax)
28731- movq %rdi,%rcx
28732- addq %rdx,%rcx
28733- jc bad_to_user
28734- cmpq TI_addr_limit(%rax),%rcx
28735- ja bad_to_user
28736- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
28737- copy_user_generic_unrolled,copy_user_generic_string, \
28738- copy_user_enhanced_fast_string
28739- CFI_ENDPROC
28740-ENDPROC(_copy_to_user)
28741-
28742-/* Standard copy_from_user with segment limit checking */
28743-ENTRY(_copy_from_user)
28744- CFI_STARTPROC
28745- GET_THREAD_INFO(%rax)
28746- movq %rsi,%rcx
28747- addq %rdx,%rcx
28748- jc bad_from_user
28749- cmpq TI_addr_limit(%rax),%rcx
28750- ja bad_from_user
28751- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
28752- copy_user_generic_unrolled,copy_user_generic_string, \
28753- copy_user_enhanced_fast_string
28754- CFI_ENDPROC
28755-ENDPROC(_copy_from_user)
28756-
28757- .section .fixup,"ax"
28758- /* must zero dest */
28759-ENTRY(bad_from_user)
28760-bad_from_user:
28761- CFI_STARTPROC
28762- movl %edx,%ecx
28763- xorl %eax,%eax
28764- rep
28765- stosb
28766-bad_to_user:
28767- movl %edx,%eax
28768- ret
28769- CFI_ENDPROC
28770-ENDPROC(bad_from_user)
28771- .previous
28772-
28773 /*
28774 * copy_user_generic_unrolled - memory copy with exception handling.
28775 * This version is for CPUs like P4 that don't have efficient micro
28776@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
28777 */
28778 ENTRY(copy_user_generic_unrolled)
28779 CFI_STARTPROC
28780+ ASM_PAX_OPEN_USERLAND
28781 ASM_STAC
28782 cmpl $8,%edx
28783 jb 20f /* less then 8 bytes, go to byte copy loop */
28784@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
28785 jnz 21b
28786 23: xor %eax,%eax
28787 ASM_CLAC
28788+ ASM_PAX_CLOSE_USERLAND
28789+ pax_force_retaddr
28790 ret
28791
28792 .section .fixup,"ax"
28793@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
28794 */
28795 ENTRY(copy_user_generic_string)
28796 CFI_STARTPROC
28797+ ASM_PAX_OPEN_USERLAND
28798 ASM_STAC
28799 andl %edx,%edx
28800 jz 4f
28801@@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
28802 movsb
28803 4: xorl %eax,%eax
28804 ASM_CLAC
28805+ ASM_PAX_CLOSE_USERLAND
28806+ pax_force_retaddr
28807 ret
28808
28809 .section .fixup,"ax"
28810@@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
28811 */
28812 ENTRY(copy_user_enhanced_fast_string)
28813 CFI_STARTPROC
28814+ ASM_PAX_OPEN_USERLAND
28815 ASM_STAC
28816 andl %edx,%edx
28817 jz 2f
28818@@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
28819 movsb
28820 2: xorl %eax,%eax
28821 ASM_CLAC
28822+ ASM_PAX_CLOSE_USERLAND
28823+ pax_force_retaddr
28824 ret
28825
28826 .section .fixup,"ax"
28827diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
28828index 6a4f43c..c70fb52 100644
28829--- a/arch/x86/lib/copy_user_nocache_64.S
28830+++ b/arch/x86/lib/copy_user_nocache_64.S
28831@@ -8,6 +8,7 @@
28832
28833 #include <linux/linkage.h>
28834 #include <asm/dwarf2.h>
28835+#include <asm/alternative-asm.h>
28836
28837 #define FIX_ALIGNMENT 1
28838
28839@@ -16,6 +17,7 @@
28840 #include <asm/thread_info.h>
28841 #include <asm/asm.h>
28842 #include <asm/smap.h>
28843+#include <asm/pgtable.h>
28844
28845 .macro ALIGN_DESTINATION
28846 #ifdef FIX_ALIGNMENT
28847@@ -49,6 +51,16 @@
28848 */
28849 ENTRY(__copy_user_nocache)
28850 CFI_STARTPROC
28851+
28852+#ifdef CONFIG_PAX_MEMORY_UDEREF
28853+ mov pax_user_shadow_base,%rcx
28854+ cmp %rcx,%rsi
28855+ jae 1f
28856+ add %rcx,%rsi
28857+1:
28858+#endif
28859+
28860+ ASM_PAX_OPEN_USERLAND
28861 ASM_STAC
28862 cmpl $8,%edx
28863 jb 20f /* less then 8 bytes, go to byte copy loop */
28864@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
28865 jnz 21b
28866 23: xorl %eax,%eax
28867 ASM_CLAC
28868+ ASM_PAX_CLOSE_USERLAND
28869 sfence
28870+ pax_force_retaddr
28871 ret
28872
28873 .section .fixup,"ax"
28874diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
28875index 2419d5f..fe52d0e 100644
28876--- a/arch/x86/lib/csum-copy_64.S
28877+++ b/arch/x86/lib/csum-copy_64.S
28878@@ -9,6 +9,7 @@
28879 #include <asm/dwarf2.h>
28880 #include <asm/errno.h>
28881 #include <asm/asm.h>
28882+#include <asm/alternative-asm.h>
28883
28884 /*
28885 * Checksum copy with exception handling.
28886@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
28887 CFI_ADJUST_CFA_OFFSET 7*8
28888 movq %rbx, 2*8(%rsp)
28889 CFI_REL_OFFSET rbx, 2*8
28890- movq %r12, 3*8(%rsp)
28891- CFI_REL_OFFSET r12, 3*8
28892+ movq %r15, 3*8(%rsp)
28893+ CFI_REL_OFFSET r15, 3*8
28894 movq %r14, 4*8(%rsp)
28895 CFI_REL_OFFSET r14, 4*8
28896 movq %r13, 5*8(%rsp)
28897@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
28898 movl %edx, %ecx
28899
28900 xorl %r9d, %r9d
28901- movq %rcx, %r12
28902+ movq %rcx, %r15
28903
28904- shrq $6, %r12
28905+ shrq $6, %r15
28906 jz .Lhandle_tail /* < 64 */
28907
28908 clc
28909
28910 /* main loop. clear in 64 byte blocks */
28911 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
28912- /* r11: temp3, rdx: temp4, r12 loopcnt */
28913+ /* r11: temp3, rdx: temp4, r15 loopcnt */
28914 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
28915 .p2align 4
28916 .Lloop:
28917@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
28918 adcq %r14, %rax
28919 adcq %r13, %rax
28920
28921- decl %r12d
28922+ decl %r15d
28923
28924 dest
28925 movq %rbx, (%rsi)
28926@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
28927 .Lende:
28928 movq 2*8(%rsp), %rbx
28929 CFI_RESTORE rbx
28930- movq 3*8(%rsp), %r12
28931- CFI_RESTORE r12
28932+ movq 3*8(%rsp), %r15
28933+ CFI_RESTORE r15
28934 movq 4*8(%rsp), %r14
28935 CFI_RESTORE r14
28936 movq 5*8(%rsp), %r13
28937@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
28938 CFI_RESTORE rbp
28939 addq $7*8, %rsp
28940 CFI_ADJUST_CFA_OFFSET -7*8
28941+ pax_force_retaddr
28942 ret
28943 CFI_RESTORE_STATE
28944
28945diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
28946index 7609e0e..b449b98 100644
28947--- a/arch/x86/lib/csum-wrappers_64.c
28948+++ b/arch/x86/lib/csum-wrappers_64.c
28949@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
28950 len -= 2;
28951 }
28952 }
28953+ pax_open_userland();
28954 stac();
28955- isum = csum_partial_copy_generic((__force const void *)src,
28956+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
28957 dst, len, isum, errp, NULL);
28958 clac();
28959+ pax_close_userland();
28960 if (unlikely(*errp))
28961 goto out_err;
28962
28963@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
28964 }
28965
28966 *errp = 0;
28967+ pax_open_userland();
28968 stac();
28969- ret = csum_partial_copy_generic(src, (void __force *)dst,
28970+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
28971 len, isum, NULL, errp);
28972 clac();
28973+ pax_close_userland();
28974 return ret;
28975 }
28976 EXPORT_SYMBOL(csum_partial_copy_to_user);
28977diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
28978index a451235..1daa956 100644
28979--- a/arch/x86/lib/getuser.S
28980+++ b/arch/x86/lib/getuser.S
28981@@ -33,17 +33,40 @@
28982 #include <asm/thread_info.h>
28983 #include <asm/asm.h>
28984 #include <asm/smap.h>
28985+#include <asm/segment.h>
28986+#include <asm/pgtable.h>
28987+#include <asm/alternative-asm.h>
28988+
28989+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28990+#define __copyuser_seg gs;
28991+#else
28992+#define __copyuser_seg
28993+#endif
28994
28995 .text
28996 ENTRY(__get_user_1)
28997 CFI_STARTPROC
28998+
28999+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29000 GET_THREAD_INFO(%_ASM_DX)
29001 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29002 jae bad_get_user
29003 ASM_STAC
29004-1: movzbl (%_ASM_AX),%edx
29005+
29006+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29007+ mov pax_user_shadow_base,%_ASM_DX
29008+ cmp %_ASM_DX,%_ASM_AX
29009+ jae 1234f
29010+ add %_ASM_DX,%_ASM_AX
29011+1234:
29012+#endif
29013+
29014+#endif
29015+
29016+1: __copyuser_seg movzbl (%_ASM_AX),%edx
29017 xor %eax,%eax
29018 ASM_CLAC
29019+ pax_force_retaddr
29020 ret
29021 CFI_ENDPROC
29022 ENDPROC(__get_user_1)
29023@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29024 ENTRY(__get_user_2)
29025 CFI_STARTPROC
29026 add $1,%_ASM_AX
29027+
29028+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29029 jc bad_get_user
29030 GET_THREAD_INFO(%_ASM_DX)
29031 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29032 jae bad_get_user
29033 ASM_STAC
29034-2: movzwl -1(%_ASM_AX),%edx
29035+
29036+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29037+ mov pax_user_shadow_base,%_ASM_DX
29038+ cmp %_ASM_DX,%_ASM_AX
29039+ jae 1234f
29040+ add %_ASM_DX,%_ASM_AX
29041+1234:
29042+#endif
29043+
29044+#endif
29045+
29046+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29047 xor %eax,%eax
29048 ASM_CLAC
29049+ pax_force_retaddr
29050 ret
29051 CFI_ENDPROC
29052 ENDPROC(__get_user_2)
29053@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29054 ENTRY(__get_user_4)
29055 CFI_STARTPROC
29056 add $3,%_ASM_AX
29057+
29058+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29059 jc bad_get_user
29060 GET_THREAD_INFO(%_ASM_DX)
29061 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29062 jae bad_get_user
29063 ASM_STAC
29064-3: movl -3(%_ASM_AX),%edx
29065+
29066+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29067+ mov pax_user_shadow_base,%_ASM_DX
29068+ cmp %_ASM_DX,%_ASM_AX
29069+ jae 1234f
29070+ add %_ASM_DX,%_ASM_AX
29071+1234:
29072+#endif
29073+
29074+#endif
29075+
29076+3: __copyuser_seg movl -3(%_ASM_AX),%edx
29077 xor %eax,%eax
29078 ASM_CLAC
29079+ pax_force_retaddr
29080 ret
29081 CFI_ENDPROC
29082 ENDPROC(__get_user_4)
29083@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29084 GET_THREAD_INFO(%_ASM_DX)
29085 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29086 jae bad_get_user
29087+
29088+#ifdef CONFIG_PAX_MEMORY_UDEREF
29089+ mov pax_user_shadow_base,%_ASM_DX
29090+ cmp %_ASM_DX,%_ASM_AX
29091+ jae 1234f
29092+ add %_ASM_DX,%_ASM_AX
29093+1234:
29094+#endif
29095+
29096 ASM_STAC
29097 4: movq -7(%_ASM_AX),%rdx
29098 xor %eax,%eax
29099 ASM_CLAC
29100+ pax_force_retaddr
29101 ret
29102 #else
29103 add $7,%_ASM_AX
29104@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29105 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29106 jae bad_get_user_8
29107 ASM_STAC
29108-4: movl -7(%_ASM_AX),%edx
29109-5: movl -3(%_ASM_AX),%ecx
29110+4: __copyuser_seg movl -7(%_ASM_AX),%edx
29111+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29112 xor %eax,%eax
29113 ASM_CLAC
29114+ pax_force_retaddr
29115 ret
29116 #endif
29117 CFI_ENDPROC
29118@@ -113,6 +175,7 @@ bad_get_user:
29119 xor %edx,%edx
29120 mov $(-EFAULT),%_ASM_AX
29121 ASM_CLAC
29122+ pax_force_retaddr
29123 ret
29124 CFI_ENDPROC
29125 END(bad_get_user)
29126@@ -124,6 +187,7 @@ bad_get_user_8:
29127 xor %ecx,%ecx
29128 mov $(-EFAULT),%_ASM_AX
29129 ASM_CLAC
29130+ pax_force_retaddr
29131 ret
29132 CFI_ENDPROC
29133 END(bad_get_user_8)
29134diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29135index 54fcffe..7be149e 100644
29136--- a/arch/x86/lib/insn.c
29137+++ b/arch/x86/lib/insn.c
29138@@ -20,8 +20,10 @@
29139
29140 #ifdef __KERNEL__
29141 #include <linux/string.h>
29142+#include <asm/pgtable_types.h>
29143 #else
29144 #include <string.h>
29145+#define ktla_ktva(addr) addr
29146 #endif
29147 #include <asm/inat.h>
29148 #include <asm/insn.h>
29149@@ -53,8 +55,8 @@
29150 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29151 {
29152 memset(insn, 0, sizeof(*insn));
29153- insn->kaddr = kaddr;
29154- insn->next_byte = kaddr;
29155+ insn->kaddr = ktla_ktva(kaddr);
29156+ insn->next_byte = ktla_ktva(kaddr);
29157 insn->x86_64 = x86_64 ? 1 : 0;
29158 insn->opnd_bytes = 4;
29159 if (x86_64)
29160diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29161index 05a95e7..326f2fa 100644
29162--- a/arch/x86/lib/iomap_copy_64.S
29163+++ b/arch/x86/lib/iomap_copy_64.S
29164@@ -17,6 +17,7 @@
29165
29166 #include <linux/linkage.h>
29167 #include <asm/dwarf2.h>
29168+#include <asm/alternative-asm.h>
29169
29170 /*
29171 * override generic version in lib/iomap_copy.c
29172@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29173 CFI_STARTPROC
29174 movl %edx,%ecx
29175 rep movsd
29176+ pax_force_retaddr
29177 ret
29178 CFI_ENDPROC
29179 ENDPROC(__iowrite32_copy)
29180diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29181index 56313a3..0db417e 100644
29182--- a/arch/x86/lib/memcpy_64.S
29183+++ b/arch/x86/lib/memcpy_64.S
29184@@ -24,7 +24,7 @@
29185 * This gets patched over the unrolled variant (below) via the
29186 * alternative instructions framework:
29187 */
29188- .section .altinstr_replacement, "ax", @progbits
29189+ .section .altinstr_replacement, "a", @progbits
29190 .Lmemcpy_c:
29191 movq %rdi, %rax
29192 movq %rdx, %rcx
29193@@ -33,6 +33,7 @@
29194 rep movsq
29195 movl %edx, %ecx
29196 rep movsb
29197+ pax_force_retaddr
29198 ret
29199 .Lmemcpy_e:
29200 .previous
29201@@ -44,11 +45,12 @@
29202 * This gets patched over the unrolled variant (below) via the
29203 * alternative instructions framework:
29204 */
29205- .section .altinstr_replacement, "ax", @progbits
29206+ .section .altinstr_replacement, "a", @progbits
29207 .Lmemcpy_c_e:
29208 movq %rdi, %rax
29209 movq %rdx, %rcx
29210 rep movsb
29211+ pax_force_retaddr
29212 ret
29213 .Lmemcpy_e_e:
29214 .previous
29215@@ -136,6 +138,7 @@ ENTRY(memcpy)
29216 movq %r9, 1*8(%rdi)
29217 movq %r10, -2*8(%rdi, %rdx)
29218 movq %r11, -1*8(%rdi, %rdx)
29219+ pax_force_retaddr
29220 retq
29221 .p2align 4
29222 .Lless_16bytes:
29223@@ -148,6 +151,7 @@ ENTRY(memcpy)
29224 movq -1*8(%rsi, %rdx), %r9
29225 movq %r8, 0*8(%rdi)
29226 movq %r9, -1*8(%rdi, %rdx)
29227+ pax_force_retaddr
29228 retq
29229 .p2align 4
29230 .Lless_8bytes:
29231@@ -161,6 +165,7 @@ ENTRY(memcpy)
29232 movl -4(%rsi, %rdx), %r8d
29233 movl %ecx, (%rdi)
29234 movl %r8d, -4(%rdi, %rdx)
29235+ pax_force_retaddr
29236 retq
29237 .p2align 4
29238 .Lless_3bytes:
29239@@ -179,6 +184,7 @@ ENTRY(memcpy)
29240 movb %cl, (%rdi)
29241
29242 .Lend:
29243+ pax_force_retaddr
29244 retq
29245 CFI_ENDPROC
29246 ENDPROC(memcpy)
29247diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29248index 65268a6..dd1de11 100644
29249--- a/arch/x86/lib/memmove_64.S
29250+++ b/arch/x86/lib/memmove_64.S
29251@@ -202,14 +202,16 @@ ENTRY(memmove)
29252 movb (%rsi), %r11b
29253 movb %r11b, (%rdi)
29254 13:
29255+ pax_force_retaddr
29256 retq
29257 CFI_ENDPROC
29258
29259- .section .altinstr_replacement,"ax"
29260+ .section .altinstr_replacement,"a"
29261 .Lmemmove_begin_forward_efs:
29262 /* Forward moving data. */
29263 movq %rdx, %rcx
29264 rep movsb
29265+ pax_force_retaddr
29266 retq
29267 .Lmemmove_end_forward_efs:
29268 .previous
29269diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29270index 2dcb380..2eb79fe 100644
29271--- a/arch/x86/lib/memset_64.S
29272+++ b/arch/x86/lib/memset_64.S
29273@@ -16,7 +16,7 @@
29274 *
29275 * rax original destination
29276 */
29277- .section .altinstr_replacement, "ax", @progbits
29278+ .section .altinstr_replacement, "a", @progbits
29279 .Lmemset_c:
29280 movq %rdi,%r9
29281 movq %rdx,%rcx
29282@@ -30,6 +30,7 @@
29283 movl %edx,%ecx
29284 rep stosb
29285 movq %r9,%rax
29286+ pax_force_retaddr
29287 ret
29288 .Lmemset_e:
29289 .previous
29290@@ -45,13 +46,14 @@
29291 *
29292 * rax original destination
29293 */
29294- .section .altinstr_replacement, "ax", @progbits
29295+ .section .altinstr_replacement, "a", @progbits
29296 .Lmemset_c_e:
29297 movq %rdi,%r9
29298 movb %sil,%al
29299 movq %rdx,%rcx
29300 rep stosb
29301 movq %r9,%rax
29302+ pax_force_retaddr
29303 ret
29304 .Lmemset_e_e:
29305 .previous
29306@@ -118,6 +120,7 @@ ENTRY(__memset)
29307
29308 .Lende:
29309 movq %r10,%rax
29310+ pax_force_retaddr
29311 ret
29312
29313 CFI_RESTORE_STATE
29314diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
29315index c9f2d9b..e7fd2c0 100644
29316--- a/arch/x86/lib/mmx_32.c
29317+++ b/arch/x86/lib/mmx_32.c
29318@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29319 {
29320 void *p;
29321 int i;
29322+ unsigned long cr0;
29323
29324 if (unlikely(in_interrupt()))
29325 return __memcpy(to, from, len);
29326@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29327 kernel_fpu_begin();
29328
29329 __asm__ __volatile__ (
29330- "1: prefetch (%0)\n" /* This set is 28 bytes */
29331- " prefetch 64(%0)\n"
29332- " prefetch 128(%0)\n"
29333- " prefetch 192(%0)\n"
29334- " prefetch 256(%0)\n"
29335+ "1: prefetch (%1)\n" /* This set is 28 bytes */
29336+ " prefetch 64(%1)\n"
29337+ " prefetch 128(%1)\n"
29338+ " prefetch 192(%1)\n"
29339+ " prefetch 256(%1)\n"
29340 "2: \n"
29341 ".section .fixup, \"ax\"\n"
29342- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29343+ "3: \n"
29344+
29345+#ifdef CONFIG_PAX_KERNEXEC
29346+ " movl %%cr0, %0\n"
29347+ " movl %0, %%eax\n"
29348+ " andl $0xFFFEFFFF, %%eax\n"
29349+ " movl %%eax, %%cr0\n"
29350+#endif
29351+
29352+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29353+
29354+#ifdef CONFIG_PAX_KERNEXEC
29355+ " movl %0, %%cr0\n"
29356+#endif
29357+
29358 " jmp 2b\n"
29359 ".previous\n"
29360 _ASM_EXTABLE(1b, 3b)
29361- : : "r" (from));
29362+ : "=&r" (cr0) : "r" (from) : "ax");
29363
29364 for ( ; i > 5; i--) {
29365 __asm__ __volatile__ (
29366- "1: prefetch 320(%0)\n"
29367- "2: movq (%0), %%mm0\n"
29368- " movq 8(%0), %%mm1\n"
29369- " movq 16(%0), %%mm2\n"
29370- " movq 24(%0), %%mm3\n"
29371- " movq %%mm0, (%1)\n"
29372- " movq %%mm1, 8(%1)\n"
29373- " movq %%mm2, 16(%1)\n"
29374- " movq %%mm3, 24(%1)\n"
29375- " movq 32(%0), %%mm0\n"
29376- " movq 40(%0), %%mm1\n"
29377- " movq 48(%0), %%mm2\n"
29378- " movq 56(%0), %%mm3\n"
29379- " movq %%mm0, 32(%1)\n"
29380- " movq %%mm1, 40(%1)\n"
29381- " movq %%mm2, 48(%1)\n"
29382- " movq %%mm3, 56(%1)\n"
29383+ "1: prefetch 320(%1)\n"
29384+ "2: movq (%1), %%mm0\n"
29385+ " movq 8(%1), %%mm1\n"
29386+ " movq 16(%1), %%mm2\n"
29387+ " movq 24(%1), %%mm3\n"
29388+ " movq %%mm0, (%2)\n"
29389+ " movq %%mm1, 8(%2)\n"
29390+ " movq %%mm2, 16(%2)\n"
29391+ " movq %%mm3, 24(%2)\n"
29392+ " movq 32(%1), %%mm0\n"
29393+ " movq 40(%1), %%mm1\n"
29394+ " movq 48(%1), %%mm2\n"
29395+ " movq 56(%1), %%mm3\n"
29396+ " movq %%mm0, 32(%2)\n"
29397+ " movq %%mm1, 40(%2)\n"
29398+ " movq %%mm2, 48(%2)\n"
29399+ " movq %%mm3, 56(%2)\n"
29400 ".section .fixup, \"ax\"\n"
29401- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29402+ "3:\n"
29403+
29404+#ifdef CONFIG_PAX_KERNEXEC
29405+ " movl %%cr0, %0\n"
29406+ " movl %0, %%eax\n"
29407+ " andl $0xFFFEFFFF, %%eax\n"
29408+ " movl %%eax, %%cr0\n"
29409+#endif
29410+
29411+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29412+
29413+#ifdef CONFIG_PAX_KERNEXEC
29414+ " movl %0, %%cr0\n"
29415+#endif
29416+
29417 " jmp 2b\n"
29418 ".previous\n"
29419 _ASM_EXTABLE(1b, 3b)
29420- : : "r" (from), "r" (to) : "memory");
29421+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29422
29423 from += 64;
29424 to += 64;
29425@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
29426 static void fast_copy_page(void *to, void *from)
29427 {
29428 int i;
29429+ unsigned long cr0;
29430
29431 kernel_fpu_begin();
29432
29433@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
29434 * but that is for later. -AV
29435 */
29436 __asm__ __volatile__(
29437- "1: prefetch (%0)\n"
29438- " prefetch 64(%0)\n"
29439- " prefetch 128(%0)\n"
29440- " prefetch 192(%0)\n"
29441- " prefetch 256(%0)\n"
29442+ "1: prefetch (%1)\n"
29443+ " prefetch 64(%1)\n"
29444+ " prefetch 128(%1)\n"
29445+ " prefetch 192(%1)\n"
29446+ " prefetch 256(%1)\n"
29447 "2: \n"
29448 ".section .fixup, \"ax\"\n"
29449- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29450+ "3: \n"
29451+
29452+#ifdef CONFIG_PAX_KERNEXEC
29453+ " movl %%cr0, %0\n"
29454+ " movl %0, %%eax\n"
29455+ " andl $0xFFFEFFFF, %%eax\n"
29456+ " movl %%eax, %%cr0\n"
29457+#endif
29458+
29459+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29460+
29461+#ifdef CONFIG_PAX_KERNEXEC
29462+ " movl %0, %%cr0\n"
29463+#endif
29464+
29465 " jmp 2b\n"
29466 ".previous\n"
29467- _ASM_EXTABLE(1b, 3b) : : "r" (from));
29468+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29469
29470 for (i = 0; i < (4096-320)/64; i++) {
29471 __asm__ __volatile__ (
29472- "1: prefetch 320(%0)\n"
29473- "2: movq (%0), %%mm0\n"
29474- " movntq %%mm0, (%1)\n"
29475- " movq 8(%0), %%mm1\n"
29476- " movntq %%mm1, 8(%1)\n"
29477- " movq 16(%0), %%mm2\n"
29478- " movntq %%mm2, 16(%1)\n"
29479- " movq 24(%0), %%mm3\n"
29480- " movntq %%mm3, 24(%1)\n"
29481- " movq 32(%0), %%mm4\n"
29482- " movntq %%mm4, 32(%1)\n"
29483- " movq 40(%0), %%mm5\n"
29484- " movntq %%mm5, 40(%1)\n"
29485- " movq 48(%0), %%mm6\n"
29486- " movntq %%mm6, 48(%1)\n"
29487- " movq 56(%0), %%mm7\n"
29488- " movntq %%mm7, 56(%1)\n"
29489+ "1: prefetch 320(%1)\n"
29490+ "2: movq (%1), %%mm0\n"
29491+ " movntq %%mm0, (%2)\n"
29492+ " movq 8(%1), %%mm1\n"
29493+ " movntq %%mm1, 8(%2)\n"
29494+ " movq 16(%1), %%mm2\n"
29495+ " movntq %%mm2, 16(%2)\n"
29496+ " movq 24(%1), %%mm3\n"
29497+ " movntq %%mm3, 24(%2)\n"
29498+ " movq 32(%1), %%mm4\n"
29499+ " movntq %%mm4, 32(%2)\n"
29500+ " movq 40(%1), %%mm5\n"
29501+ " movntq %%mm5, 40(%2)\n"
29502+ " movq 48(%1), %%mm6\n"
29503+ " movntq %%mm6, 48(%2)\n"
29504+ " movq 56(%1), %%mm7\n"
29505+ " movntq %%mm7, 56(%2)\n"
29506 ".section .fixup, \"ax\"\n"
29507- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29508+ "3:\n"
29509+
29510+#ifdef CONFIG_PAX_KERNEXEC
29511+ " movl %%cr0, %0\n"
29512+ " movl %0, %%eax\n"
29513+ " andl $0xFFFEFFFF, %%eax\n"
29514+ " movl %%eax, %%cr0\n"
29515+#endif
29516+
29517+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29518+
29519+#ifdef CONFIG_PAX_KERNEXEC
29520+ " movl %0, %%cr0\n"
29521+#endif
29522+
29523 " jmp 2b\n"
29524 ".previous\n"
29525- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
29526+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29527
29528 from += 64;
29529 to += 64;
29530@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
29531 static void fast_copy_page(void *to, void *from)
29532 {
29533 int i;
29534+ unsigned long cr0;
29535
29536 kernel_fpu_begin();
29537
29538 __asm__ __volatile__ (
29539- "1: prefetch (%0)\n"
29540- " prefetch 64(%0)\n"
29541- " prefetch 128(%0)\n"
29542- " prefetch 192(%0)\n"
29543- " prefetch 256(%0)\n"
29544+ "1: prefetch (%1)\n"
29545+ " prefetch 64(%1)\n"
29546+ " prefetch 128(%1)\n"
29547+ " prefetch 192(%1)\n"
29548+ " prefetch 256(%1)\n"
29549 "2: \n"
29550 ".section .fixup, \"ax\"\n"
29551- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29552+ "3: \n"
29553+
29554+#ifdef CONFIG_PAX_KERNEXEC
29555+ " movl %%cr0, %0\n"
29556+ " movl %0, %%eax\n"
29557+ " andl $0xFFFEFFFF, %%eax\n"
29558+ " movl %%eax, %%cr0\n"
29559+#endif
29560+
29561+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29562+
29563+#ifdef CONFIG_PAX_KERNEXEC
29564+ " movl %0, %%cr0\n"
29565+#endif
29566+
29567 " jmp 2b\n"
29568 ".previous\n"
29569- _ASM_EXTABLE(1b, 3b) : : "r" (from));
29570+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29571
29572 for (i = 0; i < 4096/64; i++) {
29573 __asm__ __volatile__ (
29574- "1: prefetch 320(%0)\n"
29575- "2: movq (%0), %%mm0\n"
29576- " movq 8(%0), %%mm1\n"
29577- " movq 16(%0), %%mm2\n"
29578- " movq 24(%0), %%mm3\n"
29579- " movq %%mm0, (%1)\n"
29580- " movq %%mm1, 8(%1)\n"
29581- " movq %%mm2, 16(%1)\n"
29582- " movq %%mm3, 24(%1)\n"
29583- " movq 32(%0), %%mm0\n"
29584- " movq 40(%0), %%mm1\n"
29585- " movq 48(%0), %%mm2\n"
29586- " movq 56(%0), %%mm3\n"
29587- " movq %%mm0, 32(%1)\n"
29588- " movq %%mm1, 40(%1)\n"
29589- " movq %%mm2, 48(%1)\n"
29590- " movq %%mm3, 56(%1)\n"
29591+ "1: prefetch 320(%1)\n"
29592+ "2: movq (%1), %%mm0\n"
29593+ " movq 8(%1), %%mm1\n"
29594+ " movq 16(%1), %%mm2\n"
29595+ " movq 24(%1), %%mm3\n"
29596+ " movq %%mm0, (%2)\n"
29597+ " movq %%mm1, 8(%2)\n"
29598+ " movq %%mm2, 16(%2)\n"
29599+ " movq %%mm3, 24(%2)\n"
29600+ " movq 32(%1), %%mm0\n"
29601+ " movq 40(%1), %%mm1\n"
29602+ " movq 48(%1), %%mm2\n"
29603+ " movq 56(%1), %%mm3\n"
29604+ " movq %%mm0, 32(%2)\n"
29605+ " movq %%mm1, 40(%2)\n"
29606+ " movq %%mm2, 48(%2)\n"
29607+ " movq %%mm3, 56(%2)\n"
29608 ".section .fixup, \"ax\"\n"
29609- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29610+ "3:\n"
29611+
29612+#ifdef CONFIG_PAX_KERNEXEC
29613+ " movl %%cr0, %0\n"
29614+ " movl %0, %%eax\n"
29615+ " andl $0xFFFEFFFF, %%eax\n"
29616+ " movl %%eax, %%cr0\n"
29617+#endif
29618+
29619+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29620+
29621+#ifdef CONFIG_PAX_KERNEXEC
29622+ " movl %0, %%cr0\n"
29623+#endif
29624+
29625 " jmp 2b\n"
29626 ".previous\n"
29627 _ASM_EXTABLE(1b, 3b)
29628- : : "r" (from), "r" (to) : "memory");
29629+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29630
29631 from += 64;
29632 to += 64;
29633diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
29634index f6d13ee..d789440 100644
29635--- a/arch/x86/lib/msr-reg.S
29636+++ b/arch/x86/lib/msr-reg.S
29637@@ -3,6 +3,7 @@
29638 #include <asm/dwarf2.h>
29639 #include <asm/asm.h>
29640 #include <asm/msr.h>
29641+#include <asm/alternative-asm.h>
29642
29643 #ifdef CONFIG_X86_64
29644 /*
29645@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
29646 movl %edi, 28(%r10)
29647 popq_cfi %rbp
29648 popq_cfi %rbx
29649+ pax_force_retaddr
29650 ret
29651 3:
29652 CFI_RESTORE_STATE
29653diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
29654index fc6ba17..d4d989d 100644
29655--- a/arch/x86/lib/putuser.S
29656+++ b/arch/x86/lib/putuser.S
29657@@ -16,7 +16,9 @@
29658 #include <asm/errno.h>
29659 #include <asm/asm.h>
29660 #include <asm/smap.h>
29661-
29662+#include <asm/segment.h>
29663+#include <asm/pgtable.h>
29664+#include <asm/alternative-asm.h>
29665
29666 /*
29667 * __put_user_X
29668@@ -30,57 +32,125 @@
29669 * as they get called from within inline assembly.
29670 */
29671
29672-#define ENTER CFI_STARTPROC ; \
29673- GET_THREAD_INFO(%_ASM_BX)
29674-#define EXIT ASM_CLAC ; \
29675- ret ; \
29676+#define ENTER CFI_STARTPROC
29677+#define EXIT ASM_CLAC ; \
29678+ pax_force_retaddr ; \
29679+ ret ; \
29680 CFI_ENDPROC
29681
29682+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29683+#define _DEST %_ASM_CX,%_ASM_BX
29684+#else
29685+#define _DEST %_ASM_CX
29686+#endif
29687+
29688+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29689+#define __copyuser_seg gs;
29690+#else
29691+#define __copyuser_seg
29692+#endif
29693+
29694 .text
29695 ENTRY(__put_user_1)
29696 ENTER
29697+
29698+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29699+ GET_THREAD_INFO(%_ASM_BX)
29700 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
29701 jae bad_put_user
29702 ASM_STAC
29703-1: movb %al,(%_ASM_CX)
29704+
29705+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29706+ mov pax_user_shadow_base,%_ASM_BX
29707+ cmp %_ASM_BX,%_ASM_CX
29708+ jb 1234f
29709+ xor %ebx,%ebx
29710+1234:
29711+#endif
29712+
29713+#endif
29714+
29715+1: __copyuser_seg movb %al,(_DEST)
29716 xor %eax,%eax
29717 EXIT
29718 ENDPROC(__put_user_1)
29719
29720 ENTRY(__put_user_2)
29721 ENTER
29722+
29723+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29724+ GET_THREAD_INFO(%_ASM_BX)
29725 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29726 sub $1,%_ASM_BX
29727 cmp %_ASM_BX,%_ASM_CX
29728 jae bad_put_user
29729 ASM_STAC
29730-2: movw %ax,(%_ASM_CX)
29731+
29732+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29733+ mov pax_user_shadow_base,%_ASM_BX
29734+ cmp %_ASM_BX,%_ASM_CX
29735+ jb 1234f
29736+ xor %ebx,%ebx
29737+1234:
29738+#endif
29739+
29740+#endif
29741+
29742+2: __copyuser_seg movw %ax,(_DEST)
29743 xor %eax,%eax
29744 EXIT
29745 ENDPROC(__put_user_2)
29746
29747 ENTRY(__put_user_4)
29748 ENTER
29749+
29750+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29751+ GET_THREAD_INFO(%_ASM_BX)
29752 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29753 sub $3,%_ASM_BX
29754 cmp %_ASM_BX,%_ASM_CX
29755 jae bad_put_user
29756 ASM_STAC
29757-3: movl %eax,(%_ASM_CX)
29758+
29759+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29760+ mov pax_user_shadow_base,%_ASM_BX
29761+ cmp %_ASM_BX,%_ASM_CX
29762+ jb 1234f
29763+ xor %ebx,%ebx
29764+1234:
29765+#endif
29766+
29767+#endif
29768+
29769+3: __copyuser_seg movl %eax,(_DEST)
29770 xor %eax,%eax
29771 EXIT
29772 ENDPROC(__put_user_4)
29773
29774 ENTRY(__put_user_8)
29775 ENTER
29776+
29777+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29778+ GET_THREAD_INFO(%_ASM_BX)
29779 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29780 sub $7,%_ASM_BX
29781 cmp %_ASM_BX,%_ASM_CX
29782 jae bad_put_user
29783 ASM_STAC
29784-4: mov %_ASM_AX,(%_ASM_CX)
29785+
29786+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29787+ mov pax_user_shadow_base,%_ASM_BX
29788+ cmp %_ASM_BX,%_ASM_CX
29789+ jb 1234f
29790+ xor %ebx,%ebx
29791+1234:
29792+#endif
29793+
29794+#endif
29795+
29796+4: __copyuser_seg mov %_ASM_AX,(_DEST)
29797 #ifdef CONFIG_X86_32
29798-5: movl %edx,4(%_ASM_CX)
29799+5: __copyuser_seg movl %edx,4(_DEST)
29800 #endif
29801 xor %eax,%eax
29802 EXIT
29803diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
29804index 1cad221..de671ee 100644
29805--- a/arch/x86/lib/rwlock.S
29806+++ b/arch/x86/lib/rwlock.S
29807@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
29808 FRAME
29809 0: LOCK_PREFIX
29810 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29811+
29812+#ifdef CONFIG_PAX_REFCOUNT
29813+ jno 1234f
29814+ LOCK_PREFIX
29815+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29816+ int $4
29817+1234:
29818+ _ASM_EXTABLE(1234b, 1234b)
29819+#endif
29820+
29821 1: rep; nop
29822 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
29823 jne 1b
29824 LOCK_PREFIX
29825 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29826+
29827+#ifdef CONFIG_PAX_REFCOUNT
29828+ jno 1234f
29829+ LOCK_PREFIX
29830+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29831+ int $4
29832+1234:
29833+ _ASM_EXTABLE(1234b, 1234b)
29834+#endif
29835+
29836 jnz 0b
29837 ENDFRAME
29838+ pax_force_retaddr
29839 ret
29840 CFI_ENDPROC
29841 END(__write_lock_failed)
29842@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
29843 FRAME
29844 0: LOCK_PREFIX
29845 READ_LOCK_SIZE(inc) (%__lock_ptr)
29846+
29847+#ifdef CONFIG_PAX_REFCOUNT
29848+ jno 1234f
29849+ LOCK_PREFIX
29850+ READ_LOCK_SIZE(dec) (%__lock_ptr)
29851+ int $4
29852+1234:
29853+ _ASM_EXTABLE(1234b, 1234b)
29854+#endif
29855+
29856 1: rep; nop
29857 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
29858 js 1b
29859 LOCK_PREFIX
29860 READ_LOCK_SIZE(dec) (%__lock_ptr)
29861+
29862+#ifdef CONFIG_PAX_REFCOUNT
29863+ jno 1234f
29864+ LOCK_PREFIX
29865+ READ_LOCK_SIZE(inc) (%__lock_ptr)
29866+ int $4
29867+1234:
29868+ _ASM_EXTABLE(1234b, 1234b)
29869+#endif
29870+
29871 js 0b
29872 ENDFRAME
29873+ pax_force_retaddr
29874 ret
29875 CFI_ENDPROC
29876 END(__read_lock_failed)
29877diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
29878index 5dff5f0..cadebf4 100644
29879--- a/arch/x86/lib/rwsem.S
29880+++ b/arch/x86/lib/rwsem.S
29881@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
29882 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29883 CFI_RESTORE __ASM_REG(dx)
29884 restore_common_regs
29885+ pax_force_retaddr
29886 ret
29887 CFI_ENDPROC
29888 ENDPROC(call_rwsem_down_read_failed)
29889@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
29890 movq %rax,%rdi
29891 call rwsem_down_write_failed
29892 restore_common_regs
29893+ pax_force_retaddr
29894 ret
29895 CFI_ENDPROC
29896 ENDPROC(call_rwsem_down_write_failed)
29897@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
29898 movq %rax,%rdi
29899 call rwsem_wake
29900 restore_common_regs
29901-1: ret
29902+1: pax_force_retaddr
29903+ ret
29904 CFI_ENDPROC
29905 ENDPROC(call_rwsem_wake)
29906
29907@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
29908 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29909 CFI_RESTORE __ASM_REG(dx)
29910 restore_common_regs
29911+ pax_force_retaddr
29912 ret
29913 CFI_ENDPROC
29914 ENDPROC(call_rwsem_downgrade_wake)
29915diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
29916index a63efd6..8149fbe 100644
29917--- a/arch/x86/lib/thunk_64.S
29918+++ b/arch/x86/lib/thunk_64.S
29919@@ -8,6 +8,7 @@
29920 #include <linux/linkage.h>
29921 #include <asm/dwarf2.h>
29922 #include <asm/calling.h>
29923+#include <asm/alternative-asm.h>
29924
29925 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
29926 .macro THUNK name, func, put_ret_addr_in_rdi=0
29927@@ -15,11 +16,11 @@
29928 \name:
29929 CFI_STARTPROC
29930
29931- /* this one pushes 9 elems, the next one would be %rIP */
29932- SAVE_ARGS
29933+ /* this one pushes 15+1 elems, the next one would be %rIP */
29934+ SAVE_ARGS 8
29935
29936 .if \put_ret_addr_in_rdi
29937- movq_cfi_restore 9*8, rdi
29938+ movq_cfi_restore RIP, rdi
29939 .endif
29940
29941 call \func
29942@@ -38,8 +39,9 @@
29943
29944 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
29945 CFI_STARTPROC
29946- SAVE_ARGS
29947+ SAVE_ARGS 8
29948 restore:
29949- RESTORE_ARGS
29950+ RESTORE_ARGS 1,8
29951+ pax_force_retaddr
29952 ret
29953 CFI_ENDPROC
29954diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
29955index e2f5e21..4b22130 100644
29956--- a/arch/x86/lib/usercopy_32.c
29957+++ b/arch/x86/lib/usercopy_32.c
29958@@ -42,11 +42,13 @@ do { \
29959 int __d0; \
29960 might_fault(); \
29961 __asm__ __volatile__( \
29962+ __COPYUSER_SET_ES \
29963 ASM_STAC "\n" \
29964 "0: rep; stosl\n" \
29965 " movl %2,%0\n" \
29966 "1: rep; stosb\n" \
29967 "2: " ASM_CLAC "\n" \
29968+ __COPYUSER_RESTORE_ES \
29969 ".section .fixup,\"ax\"\n" \
29970 "3: lea 0(%2,%0,4),%0\n" \
29971 " jmp 2b\n" \
29972@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
29973
29974 #ifdef CONFIG_X86_INTEL_USERCOPY
29975 static unsigned long
29976-__copy_user_intel(void __user *to, const void *from, unsigned long size)
29977+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
29978 {
29979 int d0, d1;
29980 __asm__ __volatile__(
29981@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29982 " .align 2,0x90\n"
29983 "3: movl 0(%4), %%eax\n"
29984 "4: movl 4(%4), %%edx\n"
29985- "5: movl %%eax, 0(%3)\n"
29986- "6: movl %%edx, 4(%3)\n"
29987+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
29988+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
29989 "7: movl 8(%4), %%eax\n"
29990 "8: movl 12(%4),%%edx\n"
29991- "9: movl %%eax, 8(%3)\n"
29992- "10: movl %%edx, 12(%3)\n"
29993+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
29994+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
29995 "11: movl 16(%4), %%eax\n"
29996 "12: movl 20(%4), %%edx\n"
29997- "13: movl %%eax, 16(%3)\n"
29998- "14: movl %%edx, 20(%3)\n"
29999+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30000+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30001 "15: movl 24(%4), %%eax\n"
30002 "16: movl 28(%4), %%edx\n"
30003- "17: movl %%eax, 24(%3)\n"
30004- "18: movl %%edx, 28(%3)\n"
30005+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30006+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30007 "19: movl 32(%4), %%eax\n"
30008 "20: movl 36(%4), %%edx\n"
30009- "21: movl %%eax, 32(%3)\n"
30010- "22: movl %%edx, 36(%3)\n"
30011+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30012+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30013 "23: movl 40(%4), %%eax\n"
30014 "24: movl 44(%4), %%edx\n"
30015- "25: movl %%eax, 40(%3)\n"
30016- "26: movl %%edx, 44(%3)\n"
30017+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30018+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30019 "27: movl 48(%4), %%eax\n"
30020 "28: movl 52(%4), %%edx\n"
30021- "29: movl %%eax, 48(%3)\n"
30022- "30: movl %%edx, 52(%3)\n"
30023+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30024+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30025 "31: movl 56(%4), %%eax\n"
30026 "32: movl 60(%4), %%edx\n"
30027- "33: movl %%eax, 56(%3)\n"
30028- "34: movl %%edx, 60(%3)\n"
30029+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30030+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30031 " addl $-64, %0\n"
30032 " addl $64, %4\n"
30033 " addl $64, %3\n"
30034@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30035 " shrl $2, %0\n"
30036 " andl $3, %%eax\n"
30037 " cld\n"
30038+ __COPYUSER_SET_ES
30039 "99: rep; movsl\n"
30040 "36: movl %%eax, %0\n"
30041 "37: rep; movsb\n"
30042 "100:\n"
30043+ __COPYUSER_RESTORE_ES
30044+ ".section .fixup,\"ax\"\n"
30045+ "101: lea 0(%%eax,%0,4),%0\n"
30046+ " jmp 100b\n"
30047+ ".previous\n"
30048+ _ASM_EXTABLE(1b,100b)
30049+ _ASM_EXTABLE(2b,100b)
30050+ _ASM_EXTABLE(3b,100b)
30051+ _ASM_EXTABLE(4b,100b)
30052+ _ASM_EXTABLE(5b,100b)
30053+ _ASM_EXTABLE(6b,100b)
30054+ _ASM_EXTABLE(7b,100b)
30055+ _ASM_EXTABLE(8b,100b)
30056+ _ASM_EXTABLE(9b,100b)
30057+ _ASM_EXTABLE(10b,100b)
30058+ _ASM_EXTABLE(11b,100b)
30059+ _ASM_EXTABLE(12b,100b)
30060+ _ASM_EXTABLE(13b,100b)
30061+ _ASM_EXTABLE(14b,100b)
30062+ _ASM_EXTABLE(15b,100b)
30063+ _ASM_EXTABLE(16b,100b)
30064+ _ASM_EXTABLE(17b,100b)
30065+ _ASM_EXTABLE(18b,100b)
30066+ _ASM_EXTABLE(19b,100b)
30067+ _ASM_EXTABLE(20b,100b)
30068+ _ASM_EXTABLE(21b,100b)
30069+ _ASM_EXTABLE(22b,100b)
30070+ _ASM_EXTABLE(23b,100b)
30071+ _ASM_EXTABLE(24b,100b)
30072+ _ASM_EXTABLE(25b,100b)
30073+ _ASM_EXTABLE(26b,100b)
30074+ _ASM_EXTABLE(27b,100b)
30075+ _ASM_EXTABLE(28b,100b)
30076+ _ASM_EXTABLE(29b,100b)
30077+ _ASM_EXTABLE(30b,100b)
30078+ _ASM_EXTABLE(31b,100b)
30079+ _ASM_EXTABLE(32b,100b)
30080+ _ASM_EXTABLE(33b,100b)
30081+ _ASM_EXTABLE(34b,100b)
30082+ _ASM_EXTABLE(35b,100b)
30083+ _ASM_EXTABLE(36b,100b)
30084+ _ASM_EXTABLE(37b,100b)
30085+ _ASM_EXTABLE(99b,101b)
30086+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
30087+ : "1"(to), "2"(from), "0"(size)
30088+ : "eax", "edx", "memory");
30089+ return size;
30090+}
30091+
30092+static unsigned long
30093+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30094+{
30095+ int d0, d1;
30096+ __asm__ __volatile__(
30097+ " .align 2,0x90\n"
30098+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30099+ " cmpl $67, %0\n"
30100+ " jbe 3f\n"
30101+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30102+ " .align 2,0x90\n"
30103+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30104+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30105+ "5: movl %%eax, 0(%3)\n"
30106+ "6: movl %%edx, 4(%3)\n"
30107+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30108+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30109+ "9: movl %%eax, 8(%3)\n"
30110+ "10: movl %%edx, 12(%3)\n"
30111+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30112+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30113+ "13: movl %%eax, 16(%3)\n"
30114+ "14: movl %%edx, 20(%3)\n"
30115+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30116+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30117+ "17: movl %%eax, 24(%3)\n"
30118+ "18: movl %%edx, 28(%3)\n"
30119+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30120+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30121+ "21: movl %%eax, 32(%3)\n"
30122+ "22: movl %%edx, 36(%3)\n"
30123+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30124+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30125+ "25: movl %%eax, 40(%3)\n"
30126+ "26: movl %%edx, 44(%3)\n"
30127+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30128+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30129+ "29: movl %%eax, 48(%3)\n"
30130+ "30: movl %%edx, 52(%3)\n"
30131+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30132+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30133+ "33: movl %%eax, 56(%3)\n"
30134+ "34: movl %%edx, 60(%3)\n"
30135+ " addl $-64, %0\n"
30136+ " addl $64, %4\n"
30137+ " addl $64, %3\n"
30138+ " cmpl $63, %0\n"
30139+ " ja 1b\n"
30140+ "35: movl %0, %%eax\n"
30141+ " shrl $2, %0\n"
30142+ " andl $3, %%eax\n"
30143+ " cld\n"
30144+ "99: rep; "__copyuser_seg" movsl\n"
30145+ "36: movl %%eax, %0\n"
30146+ "37: rep; "__copyuser_seg" movsb\n"
30147+ "100:\n"
30148 ".section .fixup,\"ax\"\n"
30149 "101: lea 0(%%eax,%0,4),%0\n"
30150 " jmp 100b\n"
30151@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30152 int d0, d1;
30153 __asm__ __volatile__(
30154 " .align 2,0x90\n"
30155- "0: movl 32(%4), %%eax\n"
30156+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30157 " cmpl $67, %0\n"
30158 " jbe 2f\n"
30159- "1: movl 64(%4), %%eax\n"
30160+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30161 " .align 2,0x90\n"
30162- "2: movl 0(%4), %%eax\n"
30163- "21: movl 4(%4), %%edx\n"
30164+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30165+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30166 " movl %%eax, 0(%3)\n"
30167 " movl %%edx, 4(%3)\n"
30168- "3: movl 8(%4), %%eax\n"
30169- "31: movl 12(%4),%%edx\n"
30170+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30171+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30172 " movl %%eax, 8(%3)\n"
30173 " movl %%edx, 12(%3)\n"
30174- "4: movl 16(%4), %%eax\n"
30175- "41: movl 20(%4), %%edx\n"
30176+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30177+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30178 " movl %%eax, 16(%3)\n"
30179 " movl %%edx, 20(%3)\n"
30180- "10: movl 24(%4), %%eax\n"
30181- "51: movl 28(%4), %%edx\n"
30182+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30183+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30184 " movl %%eax, 24(%3)\n"
30185 " movl %%edx, 28(%3)\n"
30186- "11: movl 32(%4), %%eax\n"
30187- "61: movl 36(%4), %%edx\n"
30188+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30189+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30190 " movl %%eax, 32(%3)\n"
30191 " movl %%edx, 36(%3)\n"
30192- "12: movl 40(%4), %%eax\n"
30193- "71: movl 44(%4), %%edx\n"
30194+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30195+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30196 " movl %%eax, 40(%3)\n"
30197 " movl %%edx, 44(%3)\n"
30198- "13: movl 48(%4), %%eax\n"
30199- "81: movl 52(%4), %%edx\n"
30200+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30201+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30202 " movl %%eax, 48(%3)\n"
30203 " movl %%edx, 52(%3)\n"
30204- "14: movl 56(%4), %%eax\n"
30205- "91: movl 60(%4), %%edx\n"
30206+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30207+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30208 " movl %%eax, 56(%3)\n"
30209 " movl %%edx, 60(%3)\n"
30210 " addl $-64, %0\n"
30211@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30212 " shrl $2, %0\n"
30213 " andl $3, %%eax\n"
30214 " cld\n"
30215- "6: rep; movsl\n"
30216+ "6: rep; "__copyuser_seg" movsl\n"
30217 " movl %%eax,%0\n"
30218- "7: rep; movsb\n"
30219+ "7: rep; "__copyuser_seg" movsb\n"
30220 "8:\n"
30221 ".section .fixup,\"ax\"\n"
30222 "9: lea 0(%%eax,%0,4),%0\n"
30223@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30224
30225 __asm__ __volatile__(
30226 " .align 2,0x90\n"
30227- "0: movl 32(%4), %%eax\n"
30228+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30229 " cmpl $67, %0\n"
30230 " jbe 2f\n"
30231- "1: movl 64(%4), %%eax\n"
30232+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30233 " .align 2,0x90\n"
30234- "2: movl 0(%4), %%eax\n"
30235- "21: movl 4(%4), %%edx\n"
30236+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30237+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30238 " movnti %%eax, 0(%3)\n"
30239 " movnti %%edx, 4(%3)\n"
30240- "3: movl 8(%4), %%eax\n"
30241- "31: movl 12(%4),%%edx\n"
30242+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30243+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30244 " movnti %%eax, 8(%3)\n"
30245 " movnti %%edx, 12(%3)\n"
30246- "4: movl 16(%4), %%eax\n"
30247- "41: movl 20(%4), %%edx\n"
30248+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30249+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30250 " movnti %%eax, 16(%3)\n"
30251 " movnti %%edx, 20(%3)\n"
30252- "10: movl 24(%4), %%eax\n"
30253- "51: movl 28(%4), %%edx\n"
30254+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30255+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30256 " movnti %%eax, 24(%3)\n"
30257 " movnti %%edx, 28(%3)\n"
30258- "11: movl 32(%4), %%eax\n"
30259- "61: movl 36(%4), %%edx\n"
30260+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30261+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30262 " movnti %%eax, 32(%3)\n"
30263 " movnti %%edx, 36(%3)\n"
30264- "12: movl 40(%4), %%eax\n"
30265- "71: movl 44(%4), %%edx\n"
30266+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30267+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30268 " movnti %%eax, 40(%3)\n"
30269 " movnti %%edx, 44(%3)\n"
30270- "13: movl 48(%4), %%eax\n"
30271- "81: movl 52(%4), %%edx\n"
30272+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30273+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30274 " movnti %%eax, 48(%3)\n"
30275 " movnti %%edx, 52(%3)\n"
30276- "14: movl 56(%4), %%eax\n"
30277- "91: movl 60(%4), %%edx\n"
30278+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30279+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30280 " movnti %%eax, 56(%3)\n"
30281 " movnti %%edx, 60(%3)\n"
30282 " addl $-64, %0\n"
30283@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30284 " shrl $2, %0\n"
30285 " andl $3, %%eax\n"
30286 " cld\n"
30287- "6: rep; movsl\n"
30288+ "6: rep; "__copyuser_seg" movsl\n"
30289 " movl %%eax,%0\n"
30290- "7: rep; movsb\n"
30291+ "7: rep; "__copyuser_seg" movsb\n"
30292 "8:\n"
30293 ".section .fixup,\"ax\"\n"
30294 "9: lea 0(%%eax,%0,4),%0\n"
30295@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
30296
30297 __asm__ __volatile__(
30298 " .align 2,0x90\n"
30299- "0: movl 32(%4), %%eax\n"
30300+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30301 " cmpl $67, %0\n"
30302 " jbe 2f\n"
30303- "1: movl 64(%4), %%eax\n"
30304+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30305 " .align 2,0x90\n"
30306- "2: movl 0(%4), %%eax\n"
30307- "21: movl 4(%4), %%edx\n"
30308+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30309+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30310 " movnti %%eax, 0(%3)\n"
30311 " movnti %%edx, 4(%3)\n"
30312- "3: movl 8(%4), %%eax\n"
30313- "31: movl 12(%4),%%edx\n"
30314+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30315+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30316 " movnti %%eax, 8(%3)\n"
30317 " movnti %%edx, 12(%3)\n"
30318- "4: movl 16(%4), %%eax\n"
30319- "41: movl 20(%4), %%edx\n"
30320+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30321+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30322 " movnti %%eax, 16(%3)\n"
30323 " movnti %%edx, 20(%3)\n"
30324- "10: movl 24(%4), %%eax\n"
30325- "51: movl 28(%4), %%edx\n"
30326+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30327+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30328 " movnti %%eax, 24(%3)\n"
30329 " movnti %%edx, 28(%3)\n"
30330- "11: movl 32(%4), %%eax\n"
30331- "61: movl 36(%4), %%edx\n"
30332+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30333+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30334 " movnti %%eax, 32(%3)\n"
30335 " movnti %%edx, 36(%3)\n"
30336- "12: movl 40(%4), %%eax\n"
30337- "71: movl 44(%4), %%edx\n"
30338+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30339+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30340 " movnti %%eax, 40(%3)\n"
30341 " movnti %%edx, 44(%3)\n"
30342- "13: movl 48(%4), %%eax\n"
30343- "81: movl 52(%4), %%edx\n"
30344+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30345+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30346 " movnti %%eax, 48(%3)\n"
30347 " movnti %%edx, 52(%3)\n"
30348- "14: movl 56(%4), %%eax\n"
30349- "91: movl 60(%4), %%edx\n"
30350+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30351+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30352 " movnti %%eax, 56(%3)\n"
30353 " movnti %%edx, 60(%3)\n"
30354 " addl $-64, %0\n"
30355@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
30356 " shrl $2, %0\n"
30357 " andl $3, %%eax\n"
30358 " cld\n"
30359- "6: rep; movsl\n"
30360+ "6: rep; "__copyuser_seg" movsl\n"
30361 " movl %%eax,%0\n"
30362- "7: rep; movsb\n"
30363+ "7: rep; "__copyuser_seg" movsb\n"
30364 "8:\n"
30365 ".section .fixup,\"ax\"\n"
30366 "9: lea 0(%%eax,%0,4),%0\n"
30367@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
30368 */
30369 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
30370 unsigned long size);
30371-unsigned long __copy_user_intel(void __user *to, const void *from,
30372+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
30373+ unsigned long size);
30374+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
30375 unsigned long size);
30376 unsigned long __copy_user_zeroing_intel_nocache(void *to,
30377 const void __user *from, unsigned long size);
30378 #endif /* CONFIG_X86_INTEL_USERCOPY */
30379
30380 /* Generic arbitrary sized copy. */
30381-#define __copy_user(to, from, size) \
30382+#define __copy_user(to, from, size, prefix, set, restore) \
30383 do { \
30384 int __d0, __d1, __d2; \
30385 __asm__ __volatile__( \
30386+ set \
30387 " cmp $7,%0\n" \
30388 " jbe 1f\n" \
30389 " movl %1,%0\n" \
30390 " negl %0\n" \
30391 " andl $7,%0\n" \
30392 " subl %0,%3\n" \
30393- "4: rep; movsb\n" \
30394+ "4: rep; "prefix"movsb\n" \
30395 " movl %3,%0\n" \
30396 " shrl $2,%0\n" \
30397 " andl $3,%3\n" \
30398 " .align 2,0x90\n" \
30399- "0: rep; movsl\n" \
30400+ "0: rep; "prefix"movsl\n" \
30401 " movl %3,%0\n" \
30402- "1: rep; movsb\n" \
30403+ "1: rep; "prefix"movsb\n" \
30404 "2:\n" \
30405+ restore \
30406 ".section .fixup,\"ax\"\n" \
30407 "5: addl %3,%0\n" \
30408 " jmp 2b\n" \
30409@@ -538,14 +650,14 @@ do { \
30410 " negl %0\n" \
30411 " andl $7,%0\n" \
30412 " subl %0,%3\n" \
30413- "4: rep; movsb\n" \
30414+ "4: rep; "__copyuser_seg"movsb\n" \
30415 " movl %3,%0\n" \
30416 " shrl $2,%0\n" \
30417 " andl $3,%3\n" \
30418 " .align 2,0x90\n" \
30419- "0: rep; movsl\n" \
30420+ "0: rep; "__copyuser_seg"movsl\n" \
30421 " movl %3,%0\n" \
30422- "1: rep; movsb\n" \
30423+ "1: rep; "__copyuser_seg"movsb\n" \
30424 "2:\n" \
30425 ".section .fixup,\"ax\"\n" \
30426 "5: addl %3,%0\n" \
30427@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
30428 {
30429 stac();
30430 if (movsl_is_ok(to, from, n))
30431- __copy_user(to, from, n);
30432+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
30433 else
30434- n = __copy_user_intel(to, from, n);
30435+ n = __generic_copy_to_user_intel(to, from, n);
30436 clac();
30437 return n;
30438 }
30439@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
30440 {
30441 stac();
30442 if (movsl_is_ok(to, from, n))
30443- __copy_user(to, from, n);
30444+ __copy_user(to, from, n, __copyuser_seg, "", "");
30445 else
30446- n = __copy_user_intel((void __user *)to,
30447- (const void *)from, n);
30448+ n = __generic_copy_from_user_intel(to, from, n);
30449 clac();
30450 return n;
30451 }
30452@@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
30453 if (n > 64 && cpu_has_xmm2)
30454 n = __copy_user_intel_nocache(to, from, n);
30455 else
30456- __copy_user(to, from, n);
30457+ __copy_user(to, from, n, __copyuser_seg, "", "");
30458 #else
30459- __copy_user(to, from, n);
30460+ __copy_user(to, from, n, __copyuser_seg, "", "");
30461 #endif
30462 clac();
30463 return n;
30464 }
30465 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
30466
30467-/**
30468- * copy_to_user: - Copy a block of data into user space.
30469- * @to: Destination address, in user space.
30470- * @from: Source address, in kernel space.
30471- * @n: Number of bytes to copy.
30472- *
30473- * Context: User context only. This function may sleep.
30474- *
30475- * Copy data from kernel space to user space.
30476- *
30477- * Returns number of bytes that could not be copied.
30478- * On success, this will be zero.
30479- */
30480-unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
30481+#ifdef CONFIG_PAX_MEMORY_UDEREF
30482+void __set_fs(mm_segment_t x)
30483 {
30484- if (access_ok(VERIFY_WRITE, to, n))
30485- n = __copy_to_user(to, from, n);
30486- return n;
30487+ switch (x.seg) {
30488+ case 0:
30489+ loadsegment(gs, 0);
30490+ break;
30491+ case TASK_SIZE_MAX:
30492+ loadsegment(gs, __USER_DS);
30493+ break;
30494+ case -1UL:
30495+ loadsegment(gs, __KERNEL_DS);
30496+ break;
30497+ default:
30498+ BUG();
30499+ }
30500 }
30501-EXPORT_SYMBOL(_copy_to_user);
30502+EXPORT_SYMBOL(__set_fs);
30503
30504-/**
30505- * copy_from_user: - Copy a block of data from user space.
30506- * @to: Destination address, in kernel space.
30507- * @from: Source address, in user space.
30508- * @n: Number of bytes to copy.
30509- *
30510- * Context: User context only. This function may sleep.
30511- *
30512- * Copy data from user space to kernel space.
30513- *
30514- * Returns number of bytes that could not be copied.
30515- * On success, this will be zero.
30516- *
30517- * If some data could not be copied, this function will pad the copied
30518- * data to the requested size using zero bytes.
30519- */
30520-unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
30521+void set_fs(mm_segment_t x)
30522 {
30523- if (access_ok(VERIFY_READ, from, n))
30524- n = __copy_from_user(to, from, n);
30525- else
30526- memset(to, 0, n);
30527- return n;
30528+ current_thread_info()->addr_limit = x;
30529+ __set_fs(x);
30530 }
30531-EXPORT_SYMBOL(_copy_from_user);
30532+EXPORT_SYMBOL(set_fs);
30533+#endif
30534diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
30535index c905e89..01ab928 100644
30536--- a/arch/x86/lib/usercopy_64.c
30537+++ b/arch/x86/lib/usercopy_64.c
30538@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
30539 might_fault();
30540 /* no memory constraint because it doesn't change any memory gcc knows
30541 about */
30542+ pax_open_userland();
30543 stac();
30544 asm volatile(
30545 " testq %[size8],%[size8]\n"
30546@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
30547 _ASM_EXTABLE(0b,3b)
30548 _ASM_EXTABLE(1b,2b)
30549 : [size8] "=&c"(size), [dst] "=&D" (__d0)
30550- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
30551+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
30552 [zero] "r" (0UL), [eight] "r" (8UL));
30553 clac();
30554+ pax_close_userland();
30555 return size;
30556 }
30557 EXPORT_SYMBOL(__clear_user);
30558@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
30559 }
30560 EXPORT_SYMBOL(clear_user);
30561
30562-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
30563+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
30564 {
30565- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
30566- return copy_user_generic((__force void *)to, (__force void *)from, len);
30567- }
30568- return len;
30569+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
30570+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
30571+ return len;
30572 }
30573 EXPORT_SYMBOL(copy_in_user);
30574
30575@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
30576 * it is not necessary to optimize tail handling.
30577 */
30578 __visible unsigned long
30579-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
30580+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
30581 {
30582 char c;
30583 unsigned zero_len;
30584
30585+ clac();
30586+ pax_close_userland();
30587 for (; len; --len, to++) {
30588 if (__get_user_nocheck(c, from++, sizeof(char)))
30589 break;
30590@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
30591 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
30592 if (__put_user_nocheck(c, to++, sizeof(char)))
30593 break;
30594- clac();
30595 return len;
30596 }
30597diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
30598index 6a19ad9..1c48f9a 100644
30599--- a/arch/x86/mm/Makefile
30600+++ b/arch/x86/mm/Makefile
30601@@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
30602 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
30603
30604 obj-$(CONFIG_MEMTEST) += memtest.o
30605+
30606+quote:="
30607+obj-$(CONFIG_X86_64) += uderef_64.o
30608+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
30609diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
30610index 903ec1e..c4166b2 100644
30611--- a/arch/x86/mm/extable.c
30612+++ b/arch/x86/mm/extable.c
30613@@ -6,12 +6,24 @@
30614 static inline unsigned long
30615 ex_insn_addr(const struct exception_table_entry *x)
30616 {
30617- return (unsigned long)&x->insn + x->insn;
30618+ unsigned long reloc = 0;
30619+
30620+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30621+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30622+#endif
30623+
30624+ return (unsigned long)&x->insn + x->insn + reloc;
30625 }
30626 static inline unsigned long
30627 ex_fixup_addr(const struct exception_table_entry *x)
30628 {
30629- return (unsigned long)&x->fixup + x->fixup;
30630+ unsigned long reloc = 0;
30631+
30632+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30633+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30634+#endif
30635+
30636+ return (unsigned long)&x->fixup + x->fixup + reloc;
30637 }
30638
30639 int fixup_exception(struct pt_regs *regs)
30640@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
30641 unsigned long new_ip;
30642
30643 #ifdef CONFIG_PNPBIOS
30644- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
30645+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
30646 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
30647 extern u32 pnp_bios_is_utter_crap;
30648 pnp_bios_is_utter_crap = 1;
30649@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
30650 i += 4;
30651 p->fixup -= i;
30652 i += 4;
30653+
30654+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30655+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
30656+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30657+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30658+#endif
30659+
30660 }
30661 }
30662
30663diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
30664index 9d591c8..2e61790 100644
30665--- a/arch/x86/mm/fault.c
30666+++ b/arch/x86/mm/fault.c
30667@@ -14,11 +14,18 @@
30668 #include <linux/hugetlb.h> /* hstate_index_to_shift */
30669 #include <linux/prefetch.h> /* prefetchw */
30670 #include <linux/context_tracking.h> /* exception_enter(), ... */
30671+#include <linux/unistd.h>
30672+#include <linux/compiler.h>
30673
30674 #include <asm/traps.h> /* dotraplinkage, ... */
30675 #include <asm/pgalloc.h> /* pgd_*(), ... */
30676 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
30677 #include <asm/fixmap.h> /* VSYSCALL_START */
30678+#include <asm/tlbflush.h>
30679+
30680+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30681+#include <asm/stacktrace.h>
30682+#endif
30683
30684 #define CREATE_TRACE_POINTS
30685 #include <asm/trace/exceptions.h>
30686@@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
30687 int ret = 0;
30688
30689 /* kprobe_running() needs smp_processor_id() */
30690- if (kprobes_built_in() && !user_mode_vm(regs)) {
30691+ if (kprobes_built_in() && !user_mode(regs)) {
30692 preempt_disable();
30693 if (kprobe_running() && kprobe_fault_handler(regs, 14))
30694 ret = 1;
30695@@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
30696 return !instr_lo || (instr_lo>>1) == 1;
30697 case 0x00:
30698 /* Prefetch instruction is 0x0F0D or 0x0F18 */
30699- if (probe_kernel_address(instr, opcode))
30700+ if (user_mode(regs)) {
30701+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
30702+ return 0;
30703+ } else if (probe_kernel_address(instr, opcode))
30704 return 0;
30705
30706 *prefetch = (instr_lo == 0xF) &&
30707@@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
30708 while (instr < max_instr) {
30709 unsigned char opcode;
30710
30711- if (probe_kernel_address(instr, opcode))
30712+ if (user_mode(regs)) {
30713+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
30714+ break;
30715+ } else if (probe_kernel_address(instr, opcode))
30716 break;
30717
30718 instr++;
30719@@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
30720 force_sig_info(si_signo, &info, tsk);
30721 }
30722
30723+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30724+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
30725+#endif
30726+
30727+#ifdef CONFIG_PAX_EMUTRAMP
30728+static int pax_handle_fetch_fault(struct pt_regs *regs);
30729+#endif
30730+
30731+#ifdef CONFIG_PAX_PAGEEXEC
30732+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
30733+{
30734+ pgd_t *pgd;
30735+ pud_t *pud;
30736+ pmd_t *pmd;
30737+
30738+ pgd = pgd_offset(mm, address);
30739+ if (!pgd_present(*pgd))
30740+ return NULL;
30741+ pud = pud_offset(pgd, address);
30742+ if (!pud_present(*pud))
30743+ return NULL;
30744+ pmd = pmd_offset(pud, address);
30745+ if (!pmd_present(*pmd))
30746+ return NULL;
30747+ return pmd;
30748+}
30749+#endif
30750+
30751 DEFINE_SPINLOCK(pgd_lock);
30752 LIST_HEAD(pgd_list);
30753
30754@@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
30755 for (address = VMALLOC_START & PMD_MASK;
30756 address >= TASK_SIZE && address < FIXADDR_TOP;
30757 address += PMD_SIZE) {
30758+
30759+#ifdef CONFIG_PAX_PER_CPU_PGD
30760+ unsigned long cpu;
30761+#else
30762 struct page *page;
30763+#endif
30764
30765 spin_lock(&pgd_lock);
30766+
30767+#ifdef CONFIG_PAX_PER_CPU_PGD
30768+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
30769+ pgd_t *pgd = get_cpu_pgd(cpu, user);
30770+ pmd_t *ret;
30771+
30772+ ret = vmalloc_sync_one(pgd, address);
30773+ if (!ret)
30774+ break;
30775+ pgd = get_cpu_pgd(cpu, kernel);
30776+#else
30777 list_for_each_entry(page, &pgd_list, lru) {
30778+ pgd_t *pgd;
30779 spinlock_t *pgt_lock;
30780 pmd_t *ret;
30781
30782@@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
30783 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
30784
30785 spin_lock(pgt_lock);
30786- ret = vmalloc_sync_one(page_address(page), address);
30787+ pgd = page_address(page);
30788+#endif
30789+
30790+ ret = vmalloc_sync_one(pgd, address);
30791+
30792+#ifndef CONFIG_PAX_PER_CPU_PGD
30793 spin_unlock(pgt_lock);
30794+#endif
30795
30796 if (!ret)
30797 break;
30798@@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30799 * an interrupt in the middle of a task switch..
30800 */
30801 pgd_paddr = read_cr3();
30802+
30803+#ifdef CONFIG_PAX_PER_CPU_PGD
30804+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
30805+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
30806+#endif
30807+
30808 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
30809 if (!pmd_k)
30810 return -1;
30811@@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30812 * happen within a race in page table update. In the later
30813 * case just flush:
30814 */
30815- pgd = pgd_offset(current->active_mm, address);
30816+
30817 pgd_ref = pgd_offset_k(address);
30818 if (pgd_none(*pgd_ref))
30819 return -1;
30820
30821+#ifdef CONFIG_PAX_PER_CPU_PGD
30822+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
30823+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
30824+ if (pgd_none(*pgd)) {
30825+ set_pgd(pgd, *pgd_ref);
30826+ arch_flush_lazy_mmu_mode();
30827+ } else {
30828+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
30829+ }
30830+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
30831+#else
30832+ pgd = pgd_offset(current->active_mm, address);
30833+#endif
30834+
30835 if (pgd_none(*pgd)) {
30836 set_pgd(pgd, *pgd_ref);
30837 arch_flush_lazy_mmu_mode();
30838@@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
30839 static int is_errata100(struct pt_regs *regs, unsigned long address)
30840 {
30841 #ifdef CONFIG_X86_64
30842- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
30843+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
30844 return 1;
30845 #endif
30846 return 0;
30847@@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
30848 }
30849
30850 static const char nx_warning[] = KERN_CRIT
30851-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
30852+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
30853
30854 static void
30855 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30856@@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30857 if (!oops_may_print())
30858 return;
30859
30860- if (error_code & PF_INSTR) {
30861+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
30862 unsigned int level;
30863
30864 pte_t *pte = lookup_address(address, &level);
30865
30866 if (pte && pte_present(*pte) && !pte_exec(*pte))
30867- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
30868+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
30869 }
30870
30871+#ifdef CONFIG_PAX_KERNEXEC
30872+ if (init_mm.start_code <= address && address < init_mm.end_code) {
30873+ if (current->signal->curr_ip)
30874+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
30875+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
30876+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30877+ else
30878+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
30879+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30880+ }
30881+#endif
30882+
30883 printk(KERN_ALERT "BUG: unable to handle kernel ");
30884 if (address < PAGE_SIZE)
30885 printk(KERN_CONT "NULL pointer dereference");
30886@@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
30887 return;
30888 }
30889 #endif
30890+
30891+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30892+ if (pax_is_fetch_fault(regs, error_code, address)) {
30893+
30894+#ifdef CONFIG_PAX_EMUTRAMP
30895+ switch (pax_handle_fetch_fault(regs)) {
30896+ case 2:
30897+ return;
30898+ }
30899+#endif
30900+
30901+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30902+ do_group_exit(SIGKILL);
30903+ }
30904+#endif
30905+
30906 /* Kernel addresses are always protection faults: */
30907 if (address >= TASK_SIZE)
30908 error_code |= PF_PROT;
30909@@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
30910 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
30911 printk(KERN_ERR
30912 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
30913- tsk->comm, tsk->pid, address);
30914+ tsk->comm, task_pid_nr(tsk), address);
30915 code = BUS_MCEERR_AR;
30916 }
30917 #endif
30918@@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
30919 return 1;
30920 }
30921
30922+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30923+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
30924+{
30925+ pte_t *pte;
30926+ pmd_t *pmd;
30927+ spinlock_t *ptl;
30928+ unsigned char pte_mask;
30929+
30930+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
30931+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
30932+ return 0;
30933+
30934+ /* PaX: it's our fault, let's handle it if we can */
30935+
30936+ /* PaX: take a look at read faults before acquiring any locks */
30937+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
30938+ /* instruction fetch attempt from a protected page in user mode */
30939+ up_read(&mm->mmap_sem);
30940+
30941+#ifdef CONFIG_PAX_EMUTRAMP
30942+ switch (pax_handle_fetch_fault(regs)) {
30943+ case 2:
30944+ return 1;
30945+ }
30946+#endif
30947+
30948+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30949+ do_group_exit(SIGKILL);
30950+ }
30951+
30952+ pmd = pax_get_pmd(mm, address);
30953+ if (unlikely(!pmd))
30954+ return 0;
30955+
30956+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
30957+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
30958+ pte_unmap_unlock(pte, ptl);
30959+ return 0;
30960+ }
30961+
30962+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
30963+ /* write attempt to a protected page in user mode */
30964+ pte_unmap_unlock(pte, ptl);
30965+ return 0;
30966+ }
30967+
30968+#ifdef CONFIG_SMP
30969+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
30970+#else
30971+ if (likely(address > get_limit(regs->cs)))
30972+#endif
30973+ {
30974+ set_pte(pte, pte_mkread(*pte));
30975+ __flush_tlb_one(address);
30976+ pte_unmap_unlock(pte, ptl);
30977+ up_read(&mm->mmap_sem);
30978+ return 1;
30979+ }
30980+
30981+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
30982+
30983+ /*
30984+ * PaX: fill DTLB with user rights and retry
30985+ */
30986+ __asm__ __volatile__ (
30987+ "orb %2,(%1)\n"
30988+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
30989+/*
30990+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
30991+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
30992+ * page fault when examined during a TLB load attempt. this is true not only
30993+ * for PTEs holding a non-present entry but also present entries that will
30994+ * raise a page fault (such as those set up by PaX, or the copy-on-write
30995+ * mechanism). in effect it means that we do *not* need to flush the TLBs
30996+ * for our target pages since their PTEs are simply not in the TLBs at all.
30997+
30998+ * the best thing in omitting it is that we gain around 15-20% speed in the
30999+ * fast path of the page fault handler and can get rid of tracing since we
31000+ * can no longer flush unintended entries.
31001+ */
31002+ "invlpg (%0)\n"
31003+#endif
31004+ __copyuser_seg"testb $0,(%0)\n"
31005+ "xorb %3,(%1)\n"
31006+ :
31007+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31008+ : "memory", "cc");
31009+ pte_unmap_unlock(pte, ptl);
31010+ up_read(&mm->mmap_sem);
31011+ return 1;
31012+}
31013+#endif
31014+
31015 /*
31016 * Handle a spurious fault caused by a stale TLB entry.
31017 *
31018@@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
31019 static inline int
31020 access_error(unsigned long error_code, struct vm_area_struct *vma)
31021 {
31022+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31023+ return 1;
31024+
31025 if (error_code & PF_WRITE) {
31026 /* write, present and write, not present: */
31027 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31028@@ -1004,7 +1212,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31029 if (error_code & PF_USER)
31030 return false;
31031
31032- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31033+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31034 return false;
31035
31036 return true;
31037@@ -1031,6 +1239,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31038 /* Get the faulting address: */
31039 address = read_cr2();
31040
31041+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31042+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31043+ if (!search_exception_tables(regs->ip)) {
31044+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31045+ bad_area_nosemaphore(regs, error_code, address);
31046+ return;
31047+ }
31048+ if (address < pax_user_shadow_base) {
31049+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31050+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31051+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31052+ } else
31053+ address -= pax_user_shadow_base;
31054+ }
31055+#endif
31056+
31057 /*
31058 * Detect and handle instructions that would cause a page fault for
31059 * both a tracked kernel page and a userspace page.
31060@@ -1110,7 +1334,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31061 * User-mode registers count as a user access even for any
31062 * potential system fault or CPU buglet:
31063 */
31064- if (user_mode_vm(regs)) {
31065+ if (user_mode(regs)) {
31066 local_irq_enable();
31067 error_code |= PF_USER;
31068 flags |= FAULT_FLAG_USER;
31069@@ -1157,6 +1381,11 @@ retry:
31070 might_sleep();
31071 }
31072
31073+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31074+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31075+ return;
31076+#endif
31077+
31078 vma = find_vma(mm, address);
31079 if (unlikely(!vma)) {
31080 bad_area(regs, error_code, address);
31081@@ -1168,18 +1397,24 @@ retry:
31082 bad_area(regs, error_code, address);
31083 return;
31084 }
31085- if (error_code & PF_USER) {
31086- /*
31087- * Accessing the stack below %sp is always a bug.
31088- * The large cushion allows instructions like enter
31089- * and pusha to work. ("enter $65535, $31" pushes
31090- * 32 pointers and then decrements %sp by 65535.)
31091- */
31092- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31093- bad_area(regs, error_code, address);
31094- return;
31095- }
31096+ /*
31097+ * Accessing the stack below %sp is always a bug.
31098+ * The large cushion allows instructions like enter
31099+ * and pusha to work. ("enter $65535, $31" pushes
31100+ * 32 pointers and then decrements %sp by 65535.)
31101+ */
31102+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31103+ bad_area(regs, error_code, address);
31104+ return;
31105 }
31106+
31107+#ifdef CONFIG_PAX_SEGMEXEC
31108+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31109+ bad_area(regs, error_code, address);
31110+ return;
31111+ }
31112+#endif
31113+
31114 if (unlikely(expand_stack(vma, address))) {
31115 bad_area(regs, error_code, address);
31116 return;
31117@@ -1273,3 +1508,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31118 __do_page_fault(regs, error_code);
31119 exception_exit(prev_state);
31120 }
31121+
31122+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31123+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31124+{
31125+ struct mm_struct *mm = current->mm;
31126+ unsigned long ip = regs->ip;
31127+
31128+ if (v8086_mode(regs))
31129+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31130+
31131+#ifdef CONFIG_PAX_PAGEEXEC
31132+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31133+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31134+ return true;
31135+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31136+ return true;
31137+ return false;
31138+ }
31139+#endif
31140+
31141+#ifdef CONFIG_PAX_SEGMEXEC
31142+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31143+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31144+ return true;
31145+ return false;
31146+ }
31147+#endif
31148+
31149+ return false;
31150+}
31151+#endif
31152+
31153+#ifdef CONFIG_PAX_EMUTRAMP
31154+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31155+{
31156+ int err;
31157+
31158+ do { /* PaX: libffi trampoline emulation */
31159+ unsigned char mov, jmp;
31160+ unsigned int addr1, addr2;
31161+
31162+#ifdef CONFIG_X86_64
31163+ if ((regs->ip + 9) >> 32)
31164+ break;
31165+#endif
31166+
31167+ err = get_user(mov, (unsigned char __user *)regs->ip);
31168+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31169+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31170+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31171+
31172+ if (err)
31173+ break;
31174+
31175+ if (mov == 0xB8 && jmp == 0xE9) {
31176+ regs->ax = addr1;
31177+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31178+ return 2;
31179+ }
31180+ } while (0);
31181+
31182+ do { /* PaX: gcc trampoline emulation #1 */
31183+ unsigned char mov1, mov2;
31184+ unsigned short jmp;
31185+ unsigned int addr1, addr2;
31186+
31187+#ifdef CONFIG_X86_64
31188+ if ((regs->ip + 11) >> 32)
31189+ break;
31190+#endif
31191+
31192+ err = get_user(mov1, (unsigned char __user *)regs->ip);
31193+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31194+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31195+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31196+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31197+
31198+ if (err)
31199+ break;
31200+
31201+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31202+ regs->cx = addr1;
31203+ regs->ax = addr2;
31204+ regs->ip = addr2;
31205+ return 2;
31206+ }
31207+ } while (0);
31208+
31209+ do { /* PaX: gcc trampoline emulation #2 */
31210+ unsigned char mov, jmp;
31211+ unsigned int addr1, addr2;
31212+
31213+#ifdef CONFIG_X86_64
31214+ if ((regs->ip + 9) >> 32)
31215+ break;
31216+#endif
31217+
31218+ err = get_user(mov, (unsigned char __user *)regs->ip);
31219+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31220+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31221+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31222+
31223+ if (err)
31224+ break;
31225+
31226+ if (mov == 0xB9 && jmp == 0xE9) {
31227+ regs->cx = addr1;
31228+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31229+ return 2;
31230+ }
31231+ } while (0);
31232+
31233+ return 1; /* PaX in action */
31234+}
31235+
31236+#ifdef CONFIG_X86_64
31237+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31238+{
31239+ int err;
31240+
31241+ do { /* PaX: libffi trampoline emulation */
31242+ unsigned short mov1, mov2, jmp1;
31243+ unsigned char stcclc, jmp2;
31244+ unsigned long addr1, addr2;
31245+
31246+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31247+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31248+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31249+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31250+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31251+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31252+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31253+
31254+ if (err)
31255+ break;
31256+
31257+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31258+ regs->r11 = addr1;
31259+ regs->r10 = addr2;
31260+ if (stcclc == 0xF8)
31261+ regs->flags &= ~X86_EFLAGS_CF;
31262+ else
31263+ regs->flags |= X86_EFLAGS_CF;
31264+ regs->ip = addr1;
31265+ return 2;
31266+ }
31267+ } while (0);
31268+
31269+ do { /* PaX: gcc trampoline emulation #1 */
31270+ unsigned short mov1, mov2, jmp1;
31271+ unsigned char jmp2;
31272+ unsigned int addr1;
31273+ unsigned long addr2;
31274+
31275+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31276+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31277+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31278+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31279+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31280+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31281+
31282+ if (err)
31283+ break;
31284+
31285+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31286+ regs->r11 = addr1;
31287+ regs->r10 = addr2;
31288+ regs->ip = addr1;
31289+ return 2;
31290+ }
31291+ } while (0);
31292+
31293+ do { /* PaX: gcc trampoline emulation #2 */
31294+ unsigned short mov1, mov2, jmp1;
31295+ unsigned char jmp2;
31296+ unsigned long addr1, addr2;
31297+
31298+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31299+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31300+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31301+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31302+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
31303+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
31304+
31305+ if (err)
31306+ break;
31307+
31308+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31309+ regs->r11 = addr1;
31310+ regs->r10 = addr2;
31311+ regs->ip = addr1;
31312+ return 2;
31313+ }
31314+ } while (0);
31315+
31316+ return 1; /* PaX in action */
31317+}
31318+#endif
31319+
31320+/*
31321+ * PaX: decide what to do with offenders (regs->ip = fault address)
31322+ *
31323+ * returns 1 when task should be killed
31324+ * 2 when gcc trampoline was detected
31325+ */
31326+static int pax_handle_fetch_fault(struct pt_regs *regs)
31327+{
31328+ if (v8086_mode(regs))
31329+ return 1;
31330+
31331+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
31332+ return 1;
31333+
31334+#ifdef CONFIG_X86_32
31335+ return pax_handle_fetch_fault_32(regs);
31336+#else
31337+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
31338+ return pax_handle_fetch_fault_32(regs);
31339+ else
31340+ return pax_handle_fetch_fault_64(regs);
31341+#endif
31342+}
31343+#endif
31344+
31345+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31346+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
31347+{
31348+ long i;
31349+
31350+ printk(KERN_ERR "PAX: bytes at PC: ");
31351+ for (i = 0; i < 20; i++) {
31352+ unsigned char c;
31353+ if (get_user(c, (unsigned char __force_user *)pc+i))
31354+ printk(KERN_CONT "?? ");
31355+ else
31356+ printk(KERN_CONT "%02x ", c);
31357+ }
31358+ printk("\n");
31359+
31360+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
31361+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
31362+ unsigned long c;
31363+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
31364+#ifdef CONFIG_X86_32
31365+ printk(KERN_CONT "???????? ");
31366+#else
31367+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
31368+ printk(KERN_CONT "???????? ???????? ");
31369+ else
31370+ printk(KERN_CONT "???????????????? ");
31371+#endif
31372+ } else {
31373+#ifdef CONFIG_X86_64
31374+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
31375+ printk(KERN_CONT "%08x ", (unsigned int)c);
31376+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
31377+ } else
31378+#endif
31379+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
31380+ }
31381+ }
31382+ printk("\n");
31383+}
31384+#endif
31385+
31386+/**
31387+ * probe_kernel_write(): safely attempt to write to a location
31388+ * @dst: address to write to
31389+ * @src: pointer to the data that shall be written
31390+ * @size: size of the data chunk
31391+ *
31392+ * Safely write to address @dst from the buffer at @src. If a kernel fault
31393+ * happens, handle that and return -EFAULT.
31394+ */
31395+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
31396+{
31397+ long ret;
31398+ mm_segment_t old_fs = get_fs();
31399+
31400+ set_fs(KERNEL_DS);
31401+ pagefault_disable();
31402+ pax_open_kernel();
31403+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
31404+ pax_close_kernel();
31405+ pagefault_enable();
31406+ set_fs(old_fs);
31407+
31408+ return ret ? -EFAULT : 0;
31409+}
31410diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
31411index 0596e8e..9de0b1c 100644
31412--- a/arch/x86/mm/gup.c
31413+++ b/arch/x86/mm/gup.c
31414@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
31415 addr = start;
31416 len = (unsigned long) nr_pages << PAGE_SHIFT;
31417 end = start + len;
31418- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31419+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31420 (void __user *)start, len)))
31421 return 0;
31422
31423@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
31424 goto slow_irqon;
31425 #endif
31426
31427+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31428+ (void __user *)start, len)))
31429+ return 0;
31430+
31431 /*
31432 * XXX: batch / limit 'nr', to avoid large irq off latency
31433 * needs some instrumenting to determine the common sizes used by
31434diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
31435index 4500142..53a363c 100644
31436--- a/arch/x86/mm/highmem_32.c
31437+++ b/arch/x86/mm/highmem_32.c
31438@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
31439 idx = type + KM_TYPE_NR*smp_processor_id();
31440 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31441 BUG_ON(!pte_none(*(kmap_pte-idx)));
31442+
31443+ pax_open_kernel();
31444 set_pte(kmap_pte-idx, mk_pte(page, prot));
31445+ pax_close_kernel();
31446+
31447 arch_flush_lazy_mmu_mode();
31448
31449 return (void *)vaddr;
31450diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
31451index 9d980d8..6bbfacb 100644
31452--- a/arch/x86/mm/hugetlbpage.c
31453+++ b/arch/x86/mm/hugetlbpage.c
31454@@ -92,23 +92,30 @@ int pmd_huge_support(void)
31455 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
31456 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
31457 unsigned long addr, unsigned long len,
31458- unsigned long pgoff, unsigned long flags)
31459+ unsigned long pgoff, unsigned long flags, unsigned long offset)
31460 {
31461 struct hstate *h = hstate_file(file);
31462 struct vm_unmapped_area_info info;
31463-
31464+
31465 info.flags = 0;
31466 info.length = len;
31467 info.low_limit = TASK_UNMAPPED_BASE;
31468+
31469+#ifdef CONFIG_PAX_RANDMMAP
31470+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
31471+ info.low_limit += current->mm->delta_mmap;
31472+#endif
31473+
31474 info.high_limit = TASK_SIZE;
31475 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31476 info.align_offset = 0;
31477+ info.threadstack_offset = offset;
31478 return vm_unmapped_area(&info);
31479 }
31480
31481 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31482 unsigned long addr0, unsigned long len,
31483- unsigned long pgoff, unsigned long flags)
31484+ unsigned long pgoff, unsigned long flags, unsigned long offset)
31485 {
31486 struct hstate *h = hstate_file(file);
31487 struct vm_unmapped_area_info info;
31488@@ -120,6 +127,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31489 info.high_limit = current->mm->mmap_base;
31490 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31491 info.align_offset = 0;
31492+ info.threadstack_offset = offset;
31493 addr = vm_unmapped_area(&info);
31494
31495 /*
31496@@ -132,6 +140,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31497 VM_BUG_ON(addr != -ENOMEM);
31498 info.flags = 0;
31499 info.low_limit = TASK_UNMAPPED_BASE;
31500+
31501+#ifdef CONFIG_PAX_RANDMMAP
31502+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
31503+ info.low_limit += current->mm->delta_mmap;
31504+#endif
31505+
31506 info.high_limit = TASK_SIZE;
31507 addr = vm_unmapped_area(&info);
31508 }
31509@@ -146,10 +160,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
31510 struct hstate *h = hstate_file(file);
31511 struct mm_struct *mm = current->mm;
31512 struct vm_area_struct *vma;
31513+ unsigned long pax_task_size = TASK_SIZE;
31514+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
31515
31516 if (len & ~huge_page_mask(h))
31517 return -EINVAL;
31518- if (len > TASK_SIZE)
31519+
31520+#ifdef CONFIG_PAX_SEGMEXEC
31521+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31522+ pax_task_size = SEGMEXEC_TASK_SIZE;
31523+#endif
31524+
31525+ pax_task_size -= PAGE_SIZE;
31526+
31527+ if (len > pax_task_size)
31528 return -ENOMEM;
31529
31530 if (flags & MAP_FIXED) {
31531@@ -158,19 +182,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
31532 return addr;
31533 }
31534
31535+#ifdef CONFIG_PAX_RANDMMAP
31536+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
31537+#endif
31538+
31539 if (addr) {
31540 addr = ALIGN(addr, huge_page_size(h));
31541 vma = find_vma(mm, addr);
31542- if (TASK_SIZE - len >= addr &&
31543- (!vma || addr + len <= vma->vm_start))
31544+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
31545 return addr;
31546 }
31547 if (mm->get_unmapped_area == arch_get_unmapped_area)
31548 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
31549- pgoff, flags);
31550+ pgoff, flags, offset);
31551 else
31552 return hugetlb_get_unmapped_area_topdown(file, addr, len,
31553- pgoff, flags);
31554+ pgoff, flags, offset);
31555 }
31556
31557 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
31558diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
31559index f971306..e83e0f6 100644
31560--- a/arch/x86/mm/init.c
31561+++ b/arch/x86/mm/init.c
31562@@ -4,6 +4,7 @@
31563 #include <linux/swap.h>
31564 #include <linux/memblock.h>
31565 #include <linux/bootmem.h> /* for max_low_pfn */
31566+#include <linux/tboot.h>
31567
31568 #include <asm/cacheflush.h>
31569 #include <asm/e820.h>
31570@@ -17,6 +18,8 @@
31571 #include <asm/proto.h>
31572 #include <asm/dma.h> /* for MAX_DMA_PFN */
31573 #include <asm/microcode.h>
31574+#include <asm/desc.h>
31575+#include <asm/bios_ebda.h>
31576
31577 #include "mm_internal.h"
31578
31579@@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
31580 early_ioremap_page_table_range_init();
31581 #endif
31582
31583+#ifdef CONFIG_PAX_PER_CPU_PGD
31584+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
31585+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
31586+ KERNEL_PGD_PTRS);
31587+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
31588+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
31589+ KERNEL_PGD_PTRS);
31590+ load_cr3(get_cpu_pgd(0, kernel));
31591+#else
31592 load_cr3(swapper_pg_dir);
31593+#endif
31594+
31595 __flush_tlb_all();
31596
31597 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
31598@@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
31599 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
31600 * mmio resources as well as potential bios/acpi data regions.
31601 */
31602+
31603+#ifdef CONFIG_GRKERNSEC_KMEM
31604+static unsigned int ebda_start __read_only;
31605+static unsigned int ebda_end __read_only;
31606+#endif
31607+
31608 int devmem_is_allowed(unsigned long pagenr)
31609 {
31610- if (pagenr < 256)
31611+#ifdef CONFIG_GRKERNSEC_KMEM
31612+ /* allow BDA */
31613+ if (!pagenr)
31614 return 1;
31615+ /* allow EBDA */
31616+ if (pagenr >= ebda_start && pagenr < ebda_end)
31617+ return 1;
31618+ /* if tboot is in use, allow access to its hardcoded serial log range */
31619+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
31620+ return 1;
31621+#else
31622+ if (!pagenr)
31623+ return 1;
31624+#ifdef CONFIG_VM86
31625+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
31626+ return 1;
31627+#endif
31628+#endif
31629+
31630+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
31631+ return 1;
31632+#ifdef CONFIG_GRKERNSEC_KMEM
31633+ /* throw out everything else below 1MB */
31634+ if (pagenr <= 256)
31635+ return 0;
31636+#endif
31637 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
31638 return 0;
31639 if (!page_is_ram(pagenr))
31640@@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
31641 #endif
31642 }
31643
31644+#ifdef CONFIG_GRKERNSEC_KMEM
31645+static inline void gr_init_ebda(void)
31646+{
31647+ unsigned int ebda_addr;
31648+ unsigned int ebda_size = 0;
31649+
31650+ ebda_addr = get_bios_ebda();
31651+ if (ebda_addr) {
31652+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
31653+ ebda_size <<= 10;
31654+ }
31655+ if (ebda_addr && ebda_size) {
31656+ ebda_start = ebda_addr >> PAGE_SHIFT;
31657+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
31658+ } else {
31659+ ebda_start = 0x9f000 >> PAGE_SHIFT;
31660+ ebda_end = 0xa0000 >> PAGE_SHIFT;
31661+ }
31662+}
31663+#else
31664+static inline void gr_init_ebda(void) { }
31665+#endif
31666+
31667 void free_initmem(void)
31668 {
31669+#ifdef CONFIG_PAX_KERNEXEC
31670+#ifdef CONFIG_X86_32
31671+ /* PaX: limit KERNEL_CS to actual size */
31672+ unsigned long addr, limit;
31673+ struct desc_struct d;
31674+ int cpu;
31675+#else
31676+ pgd_t *pgd;
31677+ pud_t *pud;
31678+ pmd_t *pmd;
31679+ unsigned long addr, end;
31680+#endif
31681+#endif
31682+
31683+ gr_init_ebda();
31684+
31685+#ifdef CONFIG_PAX_KERNEXEC
31686+#ifdef CONFIG_X86_32
31687+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
31688+ limit = (limit - 1UL) >> PAGE_SHIFT;
31689+
31690+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
31691+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
31692+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
31693+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
31694+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
31695+ }
31696+
31697+ /* PaX: make KERNEL_CS read-only */
31698+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
31699+ if (!paravirt_enabled())
31700+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
31701+/*
31702+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
31703+ pgd = pgd_offset_k(addr);
31704+ pud = pud_offset(pgd, addr);
31705+ pmd = pmd_offset(pud, addr);
31706+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31707+ }
31708+*/
31709+#ifdef CONFIG_X86_PAE
31710+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
31711+/*
31712+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
31713+ pgd = pgd_offset_k(addr);
31714+ pud = pud_offset(pgd, addr);
31715+ pmd = pmd_offset(pud, addr);
31716+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
31717+ }
31718+*/
31719+#endif
31720+
31721+#ifdef CONFIG_MODULES
31722+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
31723+#endif
31724+
31725+#else
31726+ /* PaX: make kernel code/rodata read-only, rest non-executable */
31727+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
31728+ pgd = pgd_offset_k(addr);
31729+ pud = pud_offset(pgd, addr);
31730+ pmd = pmd_offset(pud, addr);
31731+ if (!pmd_present(*pmd))
31732+ continue;
31733+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
31734+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31735+ else
31736+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
31737+ }
31738+
31739+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
31740+ end = addr + KERNEL_IMAGE_SIZE;
31741+ for (; addr < end; addr += PMD_SIZE) {
31742+ pgd = pgd_offset_k(addr);
31743+ pud = pud_offset(pgd, addr);
31744+ pmd = pmd_offset(pud, addr);
31745+ if (!pmd_present(*pmd))
31746+ continue;
31747+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
31748+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31749+ }
31750+#endif
31751+
31752+ flush_tlb_all();
31753+#endif
31754+
31755 free_init_pages("unused kernel",
31756 (unsigned long)(&__init_begin),
31757 (unsigned long)(&__init_end));
31758diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
31759index 4287f1f..3b99c71 100644
31760--- a/arch/x86/mm/init_32.c
31761+++ b/arch/x86/mm/init_32.c
31762@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
31763 bool __read_mostly __vmalloc_start_set = false;
31764
31765 /*
31766- * Creates a middle page table and puts a pointer to it in the
31767- * given global directory entry. This only returns the gd entry
31768- * in non-PAE compilation mode, since the middle layer is folded.
31769- */
31770-static pmd_t * __init one_md_table_init(pgd_t *pgd)
31771-{
31772- pud_t *pud;
31773- pmd_t *pmd_table;
31774-
31775-#ifdef CONFIG_X86_PAE
31776- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
31777- pmd_table = (pmd_t *)alloc_low_page();
31778- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
31779- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
31780- pud = pud_offset(pgd, 0);
31781- BUG_ON(pmd_table != pmd_offset(pud, 0));
31782-
31783- return pmd_table;
31784- }
31785-#endif
31786- pud = pud_offset(pgd, 0);
31787- pmd_table = pmd_offset(pud, 0);
31788-
31789- return pmd_table;
31790-}
31791-
31792-/*
31793 * Create a page table and place a pointer to it in a middle page
31794 * directory entry:
31795 */
31796@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
31797 pte_t *page_table = (pte_t *)alloc_low_page();
31798
31799 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
31800+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31801+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
31802+#else
31803 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
31804+#endif
31805 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
31806 }
31807
31808 return pte_offset_kernel(pmd, 0);
31809 }
31810
31811+static pmd_t * __init one_md_table_init(pgd_t *pgd)
31812+{
31813+ pud_t *pud;
31814+ pmd_t *pmd_table;
31815+
31816+ pud = pud_offset(pgd, 0);
31817+ pmd_table = pmd_offset(pud, 0);
31818+
31819+ return pmd_table;
31820+}
31821+
31822 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
31823 {
31824 int pgd_idx = pgd_index(vaddr);
31825@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31826 int pgd_idx, pmd_idx;
31827 unsigned long vaddr;
31828 pgd_t *pgd;
31829+ pud_t *pud;
31830 pmd_t *pmd;
31831 pte_t *pte = NULL;
31832 unsigned long count = page_table_range_init_count(start, end);
31833@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31834 pgd = pgd_base + pgd_idx;
31835
31836 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
31837- pmd = one_md_table_init(pgd);
31838- pmd = pmd + pmd_index(vaddr);
31839+ pud = pud_offset(pgd, vaddr);
31840+ pmd = pmd_offset(pud, vaddr);
31841+
31842+#ifdef CONFIG_X86_PAE
31843+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31844+#endif
31845+
31846 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
31847 pmd++, pmd_idx++) {
31848 pte = page_table_kmap_check(one_page_table_init(pmd),
31849@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31850 }
31851 }
31852
31853-static inline int is_kernel_text(unsigned long addr)
31854+static inline int is_kernel_text(unsigned long start, unsigned long end)
31855 {
31856- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
31857- return 1;
31858- return 0;
31859+ if ((start > ktla_ktva((unsigned long)_etext) ||
31860+ end <= ktla_ktva((unsigned long)_stext)) &&
31861+ (start > ktla_ktva((unsigned long)_einittext) ||
31862+ end <= ktla_ktva((unsigned long)_sinittext)) &&
31863+
31864+#ifdef CONFIG_ACPI_SLEEP
31865+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
31866+#endif
31867+
31868+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
31869+ return 0;
31870+ return 1;
31871 }
31872
31873 /*
31874@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
31875 unsigned long last_map_addr = end;
31876 unsigned long start_pfn, end_pfn;
31877 pgd_t *pgd_base = swapper_pg_dir;
31878- int pgd_idx, pmd_idx, pte_ofs;
31879+ unsigned int pgd_idx, pmd_idx, pte_ofs;
31880 unsigned long pfn;
31881 pgd_t *pgd;
31882+ pud_t *pud;
31883 pmd_t *pmd;
31884 pte_t *pte;
31885 unsigned pages_2m, pages_4k;
31886@@ -291,8 +295,13 @@ repeat:
31887 pfn = start_pfn;
31888 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31889 pgd = pgd_base + pgd_idx;
31890- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
31891- pmd = one_md_table_init(pgd);
31892+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
31893+ pud = pud_offset(pgd, 0);
31894+ pmd = pmd_offset(pud, 0);
31895+
31896+#ifdef CONFIG_X86_PAE
31897+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31898+#endif
31899
31900 if (pfn >= end_pfn)
31901 continue;
31902@@ -304,14 +313,13 @@ repeat:
31903 #endif
31904 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
31905 pmd++, pmd_idx++) {
31906- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
31907+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
31908
31909 /*
31910 * Map with big pages if possible, otherwise
31911 * create normal page tables:
31912 */
31913 if (use_pse) {
31914- unsigned int addr2;
31915 pgprot_t prot = PAGE_KERNEL_LARGE;
31916 /*
31917 * first pass will use the same initial
31918@@ -322,11 +330,7 @@ repeat:
31919 _PAGE_PSE);
31920
31921 pfn &= PMD_MASK >> PAGE_SHIFT;
31922- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
31923- PAGE_OFFSET + PAGE_SIZE-1;
31924-
31925- if (is_kernel_text(addr) ||
31926- is_kernel_text(addr2))
31927+ if (is_kernel_text(address, address + PMD_SIZE))
31928 prot = PAGE_KERNEL_LARGE_EXEC;
31929
31930 pages_2m++;
31931@@ -343,7 +347,7 @@ repeat:
31932 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31933 pte += pte_ofs;
31934 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
31935- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
31936+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
31937 pgprot_t prot = PAGE_KERNEL;
31938 /*
31939 * first pass will use the same initial
31940@@ -351,7 +355,7 @@ repeat:
31941 */
31942 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
31943
31944- if (is_kernel_text(addr))
31945+ if (is_kernel_text(address, address + PAGE_SIZE))
31946 prot = PAGE_KERNEL_EXEC;
31947
31948 pages_4k++;
31949@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
31950
31951 pud = pud_offset(pgd, va);
31952 pmd = pmd_offset(pud, va);
31953- if (!pmd_present(*pmd))
31954+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
31955 break;
31956
31957 /* should not be large page here */
31958@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
31959
31960 static void __init pagetable_init(void)
31961 {
31962- pgd_t *pgd_base = swapper_pg_dir;
31963-
31964- permanent_kmaps_init(pgd_base);
31965+ permanent_kmaps_init(swapper_pg_dir);
31966 }
31967
31968-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31969+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31970 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31971
31972 /* user-defined highmem size */
31973@@ -787,10 +789,10 @@ void __init mem_init(void)
31974 ((unsigned long)&__init_end -
31975 (unsigned long)&__init_begin) >> 10,
31976
31977- (unsigned long)&_etext, (unsigned long)&_edata,
31978- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
31979+ (unsigned long)&_sdata, (unsigned long)&_edata,
31980+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
31981
31982- (unsigned long)&_text, (unsigned long)&_etext,
31983+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
31984 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
31985
31986 /*
31987@@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
31988 if (!kernel_set_to_readonly)
31989 return;
31990
31991+ start = ktla_ktva(start);
31992 pr_debug("Set kernel text: %lx - %lx for read write\n",
31993 start, start+size);
31994
31995@@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
31996 if (!kernel_set_to_readonly)
31997 return;
31998
31999+ start = ktla_ktva(start);
32000 pr_debug("Set kernel text: %lx - %lx for read only\n",
32001 start, start+size);
32002
32003@@ -922,6 +926,7 @@ void mark_rodata_ro(void)
32004 unsigned long start = PFN_ALIGN(_text);
32005 unsigned long size = PFN_ALIGN(_etext) - start;
32006
32007+ start = ktla_ktva(start);
32008 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32009 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32010 size >> 10);
32011diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32012index 104d56a..62ba13f1 100644
32013--- a/arch/x86/mm/init_64.c
32014+++ b/arch/x86/mm/init_64.c
32015@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32016 * around without checking the pgd every time.
32017 */
32018
32019-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32020+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32021 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32022
32023 int force_personality32;
32024@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32025
32026 for (address = start; address <= end; address += PGDIR_SIZE) {
32027 const pgd_t *pgd_ref = pgd_offset_k(address);
32028+
32029+#ifdef CONFIG_PAX_PER_CPU_PGD
32030+ unsigned long cpu;
32031+#else
32032 struct page *page;
32033+#endif
32034
32035 if (pgd_none(*pgd_ref))
32036 continue;
32037
32038 spin_lock(&pgd_lock);
32039+
32040+#ifdef CONFIG_PAX_PER_CPU_PGD
32041+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32042+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32043+
32044+ if (pgd_none(*pgd))
32045+ set_pgd(pgd, *pgd_ref);
32046+ else
32047+ BUG_ON(pgd_page_vaddr(*pgd)
32048+ != pgd_page_vaddr(*pgd_ref));
32049+ pgd = pgd_offset_cpu(cpu, kernel, address);
32050+#else
32051 list_for_each_entry(page, &pgd_list, lru) {
32052 pgd_t *pgd;
32053 spinlock_t *pgt_lock;
32054@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32055 /* the pgt_lock only for Xen */
32056 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32057 spin_lock(pgt_lock);
32058+#endif
32059
32060 if (pgd_none(*pgd))
32061 set_pgd(pgd, *pgd_ref);
32062@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32063 BUG_ON(pgd_page_vaddr(*pgd)
32064 != pgd_page_vaddr(*pgd_ref));
32065
32066+#ifndef CONFIG_PAX_PER_CPU_PGD
32067 spin_unlock(pgt_lock);
32068+#endif
32069+
32070 }
32071 spin_unlock(&pgd_lock);
32072 }
32073@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32074 {
32075 if (pgd_none(*pgd)) {
32076 pud_t *pud = (pud_t *)spp_getpage();
32077- pgd_populate(&init_mm, pgd, pud);
32078+ pgd_populate_kernel(&init_mm, pgd, pud);
32079 if (pud != pud_offset(pgd, 0))
32080 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32081 pud, pud_offset(pgd, 0));
32082@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32083 {
32084 if (pud_none(*pud)) {
32085 pmd_t *pmd = (pmd_t *) spp_getpage();
32086- pud_populate(&init_mm, pud, pmd);
32087+ pud_populate_kernel(&init_mm, pud, pmd);
32088 if (pmd != pmd_offset(pud, 0))
32089 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32090 pmd, pmd_offset(pud, 0));
32091@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32092 pmd = fill_pmd(pud, vaddr);
32093 pte = fill_pte(pmd, vaddr);
32094
32095+ pax_open_kernel();
32096 set_pte(pte, new_pte);
32097+ pax_close_kernel();
32098
32099 /*
32100 * It's enough to flush this one mapping.
32101@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32102 pgd = pgd_offset_k((unsigned long)__va(phys));
32103 if (pgd_none(*pgd)) {
32104 pud = (pud_t *) spp_getpage();
32105- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32106- _PAGE_USER));
32107+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32108 }
32109 pud = pud_offset(pgd, (unsigned long)__va(phys));
32110 if (pud_none(*pud)) {
32111 pmd = (pmd_t *) spp_getpage();
32112- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32113- _PAGE_USER));
32114+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32115 }
32116 pmd = pmd_offset(pud, phys);
32117 BUG_ON(!pmd_none(*pmd));
32118@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32119 prot);
32120
32121 spin_lock(&init_mm.page_table_lock);
32122- pud_populate(&init_mm, pud, pmd);
32123+ pud_populate_kernel(&init_mm, pud, pmd);
32124 spin_unlock(&init_mm.page_table_lock);
32125 }
32126 __flush_tlb_all();
32127@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32128 page_size_mask);
32129
32130 spin_lock(&init_mm.page_table_lock);
32131- pgd_populate(&init_mm, pgd, pud);
32132+ pgd_populate_kernel(&init_mm, pgd, pud);
32133 spin_unlock(&init_mm.page_table_lock);
32134 pgd_changed = true;
32135 }
32136@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32137 static struct vm_area_struct gate_vma = {
32138 .vm_start = VSYSCALL_START,
32139 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32140- .vm_page_prot = PAGE_READONLY_EXEC,
32141- .vm_flags = VM_READ | VM_EXEC
32142+ .vm_page_prot = PAGE_READONLY,
32143+ .vm_flags = VM_READ
32144 };
32145
32146 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32147@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32148
32149 const char *arch_vma_name(struct vm_area_struct *vma)
32150 {
32151- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32152+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32153 return "[vdso]";
32154 if (vma == &gate_vma)
32155 return "[vsyscall]";
32156diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32157index 7b179b4..6bd17777 100644
32158--- a/arch/x86/mm/iomap_32.c
32159+++ b/arch/x86/mm/iomap_32.c
32160@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32161 type = kmap_atomic_idx_push();
32162 idx = type + KM_TYPE_NR * smp_processor_id();
32163 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32164+
32165+ pax_open_kernel();
32166 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32167+ pax_close_kernel();
32168+
32169 arch_flush_lazy_mmu_mode();
32170
32171 return (void *)vaddr;
32172diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32173index 799580c..72f9fe0 100644
32174--- a/arch/x86/mm/ioremap.c
32175+++ b/arch/x86/mm/ioremap.c
32176@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32177 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32178 int is_ram = page_is_ram(pfn);
32179
32180- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32181+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32182 return NULL;
32183 WARN_ON_ONCE(is_ram);
32184 }
32185@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32186 *
32187 * Caller must ensure there is only one unmapping for the same pointer.
32188 */
32189-void iounmap(volatile void __iomem *addr)
32190+void iounmap(const volatile void __iomem *addr)
32191 {
32192 struct vm_struct *p, *o;
32193
32194@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32195
32196 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32197 if (page_is_ram(start >> PAGE_SHIFT))
32198+#ifdef CONFIG_HIGHMEM
32199+ if ((start >> PAGE_SHIFT) < max_low_pfn)
32200+#endif
32201 return __va(phys);
32202
32203 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32204@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32205 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32206 {
32207 if (page_is_ram(phys >> PAGE_SHIFT))
32208+#ifdef CONFIG_HIGHMEM
32209+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
32210+#endif
32211 return;
32212
32213 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32214@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
32215 early_param("early_ioremap_debug", early_ioremap_debug_setup);
32216
32217 static __initdata int after_paging_init;
32218-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32219+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32220
32221 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32222 {
32223@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
32224 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
32225
32226 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32227- memset(bm_pte, 0, sizeof(bm_pte));
32228- pmd_populate_kernel(&init_mm, pmd, bm_pte);
32229+ pmd_populate_user(&init_mm, pmd, bm_pte);
32230
32231 /*
32232 * The boot-ioremap range spans multiple pmds, for which
32233diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32234index d87dd6d..bf3fa66 100644
32235--- a/arch/x86/mm/kmemcheck/kmemcheck.c
32236+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32237@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32238 * memory (e.g. tracked pages)? For now, we need this to avoid
32239 * invoking kmemcheck for PnP BIOS calls.
32240 */
32241- if (regs->flags & X86_VM_MASK)
32242+ if (v8086_mode(regs))
32243 return false;
32244- if (regs->cs != __KERNEL_CS)
32245+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32246 return false;
32247
32248 pte = kmemcheck_pte_lookup(address);
32249diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32250index 25e7e13..1964579 100644
32251--- a/arch/x86/mm/mmap.c
32252+++ b/arch/x86/mm/mmap.c
32253@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32254 * Leave an at least ~128 MB hole with possible stack randomization.
32255 */
32256 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32257-#define MAX_GAP (TASK_SIZE/6*5)
32258+#define MAX_GAP (pax_task_size/6*5)
32259
32260 static int mmap_is_legacy(void)
32261 {
32262@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32263 return rnd << PAGE_SHIFT;
32264 }
32265
32266-static unsigned long mmap_base(void)
32267+static unsigned long mmap_base(struct mm_struct *mm)
32268 {
32269 unsigned long gap = rlimit(RLIMIT_STACK);
32270+ unsigned long pax_task_size = TASK_SIZE;
32271+
32272+#ifdef CONFIG_PAX_SEGMEXEC
32273+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32274+ pax_task_size = SEGMEXEC_TASK_SIZE;
32275+#endif
32276
32277 if (gap < MIN_GAP)
32278 gap = MIN_GAP;
32279 else if (gap > MAX_GAP)
32280 gap = MAX_GAP;
32281
32282- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32283+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32284 }
32285
32286 /*
32287 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32288 * does, but not when emulating X86_32
32289 */
32290-static unsigned long mmap_legacy_base(void)
32291+static unsigned long mmap_legacy_base(struct mm_struct *mm)
32292 {
32293- if (mmap_is_ia32())
32294+ if (mmap_is_ia32()) {
32295+
32296+#ifdef CONFIG_PAX_SEGMEXEC
32297+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32298+ return SEGMEXEC_TASK_UNMAPPED_BASE;
32299+ else
32300+#endif
32301+
32302 return TASK_UNMAPPED_BASE;
32303- else
32304+ } else
32305 return TASK_UNMAPPED_BASE + mmap_rnd();
32306 }
32307
32308@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
32309 */
32310 void arch_pick_mmap_layout(struct mm_struct *mm)
32311 {
32312- mm->mmap_legacy_base = mmap_legacy_base();
32313- mm->mmap_base = mmap_base();
32314+ mm->mmap_legacy_base = mmap_legacy_base(mm);
32315+ mm->mmap_base = mmap_base(mm);
32316+
32317+#ifdef CONFIG_PAX_RANDMMAP
32318+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
32319+ mm->mmap_legacy_base += mm->delta_mmap;
32320+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
32321+ }
32322+#endif
32323
32324 if (mmap_is_legacy()) {
32325 mm->mmap_base = mm->mmap_legacy_base;
32326diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
32327index 0057a7a..95c7edd 100644
32328--- a/arch/x86/mm/mmio-mod.c
32329+++ b/arch/x86/mm/mmio-mod.c
32330@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
32331 break;
32332 default:
32333 {
32334- unsigned char *ip = (unsigned char *)instptr;
32335+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
32336 my_trace->opcode = MMIO_UNKNOWN_OP;
32337 my_trace->width = 0;
32338 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
32339@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
32340 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32341 void __iomem *addr)
32342 {
32343- static atomic_t next_id;
32344+ static atomic_unchecked_t next_id;
32345 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
32346 /* These are page-unaligned. */
32347 struct mmiotrace_map map = {
32348@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32349 .private = trace
32350 },
32351 .phys = offset,
32352- .id = atomic_inc_return(&next_id)
32353+ .id = atomic_inc_return_unchecked(&next_id)
32354 };
32355 map.map_id = trace->id;
32356
32357@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
32358 ioremap_trace_core(offset, size, addr);
32359 }
32360
32361-static void iounmap_trace_core(volatile void __iomem *addr)
32362+static void iounmap_trace_core(const volatile void __iomem *addr)
32363 {
32364 struct mmiotrace_map map = {
32365 .phys = 0,
32366@@ -328,7 +328,7 @@ not_enabled:
32367 }
32368 }
32369
32370-void mmiotrace_iounmap(volatile void __iomem *addr)
32371+void mmiotrace_iounmap(const volatile void __iomem *addr)
32372 {
32373 might_sleep();
32374 if (is_enabled()) /* recheck and proper locking in *_core() */
32375diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
32376index 24aec58..c39fe8b 100644
32377--- a/arch/x86/mm/numa.c
32378+++ b/arch/x86/mm/numa.c
32379@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
32380 return true;
32381 }
32382
32383-static int __init numa_register_memblks(struct numa_meminfo *mi)
32384+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
32385 {
32386 unsigned long uninitialized_var(pfn_align);
32387 int i, nid;
32388diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
32389index d0b1773..4c3327c 100644
32390--- a/arch/x86/mm/pageattr-test.c
32391+++ b/arch/x86/mm/pageattr-test.c
32392@@ -36,7 +36,7 @@ enum {
32393
32394 static int pte_testbit(pte_t pte)
32395 {
32396- return pte_flags(pte) & _PAGE_UNUSED1;
32397+ return pte_flags(pte) & _PAGE_CPA_TEST;
32398 }
32399
32400 struct split_state {
32401diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
32402index bb32480..75f2f5e 100644
32403--- a/arch/x86/mm/pageattr.c
32404+++ b/arch/x86/mm/pageattr.c
32405@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32406 */
32407 #ifdef CONFIG_PCI_BIOS
32408 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
32409- pgprot_val(forbidden) |= _PAGE_NX;
32410+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32411 #endif
32412
32413 /*
32414@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32415 * Does not cover __inittext since that is gone later on. On
32416 * 64bit we do not enforce !NX on the low mapping
32417 */
32418- if (within(address, (unsigned long)_text, (unsigned long)_etext))
32419- pgprot_val(forbidden) |= _PAGE_NX;
32420+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
32421+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32422
32423+#ifdef CONFIG_DEBUG_RODATA
32424 /*
32425 * The .rodata section needs to be read-only. Using the pfn
32426 * catches all aliases.
32427@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32428 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
32429 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
32430 pgprot_val(forbidden) |= _PAGE_RW;
32431+#endif
32432
32433 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
32434 /*
32435@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32436 }
32437 #endif
32438
32439+#ifdef CONFIG_PAX_KERNEXEC
32440+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
32441+ pgprot_val(forbidden) |= _PAGE_RW;
32442+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32443+ }
32444+#endif
32445+
32446 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
32447
32448 return prot;
32449@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
32450 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
32451 {
32452 /* change init_mm */
32453+ pax_open_kernel();
32454 set_pte_atomic(kpte, pte);
32455+
32456 #ifdef CONFIG_X86_32
32457 if (!SHARED_KERNEL_PMD) {
32458+
32459+#ifdef CONFIG_PAX_PER_CPU_PGD
32460+ unsigned long cpu;
32461+#else
32462 struct page *page;
32463+#endif
32464
32465+#ifdef CONFIG_PAX_PER_CPU_PGD
32466+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32467+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
32468+#else
32469 list_for_each_entry(page, &pgd_list, lru) {
32470- pgd_t *pgd;
32471+ pgd_t *pgd = (pgd_t *)page_address(page);
32472+#endif
32473+
32474 pud_t *pud;
32475 pmd_t *pmd;
32476
32477- pgd = (pgd_t *)page_address(page) + pgd_index(address);
32478+ pgd += pgd_index(address);
32479 pud = pud_offset(pgd, address);
32480 pmd = pmd_offset(pud, address);
32481 set_pte_atomic((pte_t *)pmd, pte);
32482 }
32483 }
32484 #endif
32485+ pax_close_kernel();
32486 }
32487
32488 static int
32489diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
32490index 6574388..87e9bef 100644
32491--- a/arch/x86/mm/pat.c
32492+++ b/arch/x86/mm/pat.c
32493@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
32494
32495 if (!entry) {
32496 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
32497- current->comm, current->pid, start, end - 1);
32498+ current->comm, task_pid_nr(current), start, end - 1);
32499 return -EINVAL;
32500 }
32501
32502@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32503
32504 while (cursor < to) {
32505 if (!devmem_is_allowed(pfn)) {
32506- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
32507- current->comm, from, to - 1);
32508+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
32509+ current->comm, from, to - 1, cursor);
32510 return 0;
32511 }
32512 cursor += PAGE_SIZE;
32513@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
32514 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
32515 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
32516 "for [mem %#010Lx-%#010Lx]\n",
32517- current->comm, current->pid,
32518+ current->comm, task_pid_nr(current),
32519 cattr_name(flags),
32520 base, (unsigned long long)(base + size-1));
32521 return -EINVAL;
32522@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
32523 flags = lookup_memtype(paddr);
32524 if (want_flags != flags) {
32525 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
32526- current->comm, current->pid,
32527+ current->comm, task_pid_nr(current),
32528 cattr_name(want_flags),
32529 (unsigned long long)paddr,
32530 (unsigned long long)(paddr + size - 1),
32531@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
32532 free_memtype(paddr, paddr + size);
32533 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
32534 " for [mem %#010Lx-%#010Lx], got %s\n",
32535- current->comm, current->pid,
32536+ current->comm, task_pid_nr(current),
32537 cattr_name(want_flags),
32538 (unsigned long long)paddr,
32539 (unsigned long long)(paddr + size - 1),
32540diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
32541index 415f6c4..d319983 100644
32542--- a/arch/x86/mm/pat_rbtree.c
32543+++ b/arch/x86/mm/pat_rbtree.c
32544@@ -160,7 +160,7 @@ success:
32545
32546 failure:
32547 printk(KERN_INFO "%s:%d conflicting memory types "
32548- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
32549+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
32550 end, cattr_name(found_type), cattr_name(match->type));
32551 return -EBUSY;
32552 }
32553diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
32554index 9f0614d..92ae64a 100644
32555--- a/arch/x86/mm/pf_in.c
32556+++ b/arch/x86/mm/pf_in.c
32557@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
32558 int i;
32559 enum reason_type rv = OTHERS;
32560
32561- p = (unsigned char *)ins_addr;
32562+ p = (unsigned char *)ktla_ktva(ins_addr);
32563 p += skip_prefix(p, &prf);
32564 p += get_opcode(p, &opcode);
32565
32566@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
32567 struct prefix_bits prf;
32568 int i;
32569
32570- p = (unsigned char *)ins_addr;
32571+ p = (unsigned char *)ktla_ktva(ins_addr);
32572 p += skip_prefix(p, &prf);
32573 p += get_opcode(p, &opcode);
32574
32575@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
32576 struct prefix_bits prf;
32577 int i;
32578
32579- p = (unsigned char *)ins_addr;
32580+ p = (unsigned char *)ktla_ktva(ins_addr);
32581 p += skip_prefix(p, &prf);
32582 p += get_opcode(p, &opcode);
32583
32584@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
32585 struct prefix_bits prf;
32586 int i;
32587
32588- p = (unsigned char *)ins_addr;
32589+ p = (unsigned char *)ktla_ktva(ins_addr);
32590 p += skip_prefix(p, &prf);
32591 p += get_opcode(p, &opcode);
32592 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
32593@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
32594 struct prefix_bits prf;
32595 int i;
32596
32597- p = (unsigned char *)ins_addr;
32598+ p = (unsigned char *)ktla_ktva(ins_addr);
32599 p += skip_prefix(p, &prf);
32600 p += get_opcode(p, &opcode);
32601 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
32602diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
32603index c96314a..433b127 100644
32604--- a/arch/x86/mm/pgtable.c
32605+++ b/arch/x86/mm/pgtable.c
32606@@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
32607 list_del(&page->lru);
32608 }
32609
32610-#define UNSHARED_PTRS_PER_PGD \
32611- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
32612+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32613+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
32614
32615+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
32616+{
32617+ unsigned int count = USER_PGD_PTRS;
32618
32619+ if (!pax_user_shadow_base)
32620+ return;
32621+
32622+ while (count--)
32623+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
32624+}
32625+#endif
32626+
32627+#ifdef CONFIG_PAX_PER_CPU_PGD
32628+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
32629+{
32630+ unsigned int count = USER_PGD_PTRS;
32631+
32632+ while (count--) {
32633+ pgd_t pgd;
32634+
32635+#ifdef CONFIG_X86_64
32636+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
32637+#else
32638+ pgd = *src++;
32639+#endif
32640+
32641+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32642+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
32643+#endif
32644+
32645+ *dst++ = pgd;
32646+ }
32647+
32648+}
32649+#endif
32650+
32651+#ifdef CONFIG_X86_64
32652+#define pxd_t pud_t
32653+#define pyd_t pgd_t
32654+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
32655+#define pgtable_pxd_page_ctor(page) true
32656+#define pgtable_pxd_page_dtor(page)
32657+#define pxd_free(mm, pud) pud_free((mm), (pud))
32658+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
32659+#define pyd_offset(mm, address) pgd_offset((mm), (address))
32660+#define PYD_SIZE PGDIR_SIZE
32661+#else
32662+#define pxd_t pmd_t
32663+#define pyd_t pud_t
32664+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
32665+#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
32666+#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
32667+#define pxd_free(mm, pud) pmd_free((mm), (pud))
32668+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
32669+#define pyd_offset(mm, address) pud_offset((mm), (address))
32670+#define PYD_SIZE PUD_SIZE
32671+#endif
32672+
32673+#ifdef CONFIG_PAX_PER_CPU_PGD
32674+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
32675+static inline void pgd_dtor(pgd_t *pgd) {}
32676+#else
32677 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
32678 {
32679 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
32680@@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
32681 pgd_list_del(pgd);
32682 spin_unlock(&pgd_lock);
32683 }
32684+#endif
32685
32686 /*
32687 * List of all pgd's needed for non-PAE so it can invalidate entries
32688@@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
32689 * -- nyc
32690 */
32691
32692-#ifdef CONFIG_X86_PAE
32693+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
32694 /*
32695 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
32696 * updating the top-level pagetable entries to guarantee the
32697@@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
32698 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
32699 * and initialize the kernel pmds here.
32700 */
32701-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
32702+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
32703
32704 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
32705 {
32706@@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
32707 */
32708 flush_tlb_mm(mm);
32709 }
32710+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
32711+#define PREALLOCATED_PXDS USER_PGD_PTRS
32712 #else /* !CONFIG_X86_PAE */
32713
32714 /* No need to prepopulate any pagetable entries in non-PAE modes. */
32715-#define PREALLOCATED_PMDS 0
32716+#define PREALLOCATED_PXDS 0
32717
32718 #endif /* CONFIG_X86_PAE */
32719
32720-static void free_pmds(pmd_t *pmds[])
32721+static void free_pxds(pxd_t *pxds[])
32722 {
32723 int i;
32724
32725- for(i = 0; i < PREALLOCATED_PMDS; i++)
32726- if (pmds[i]) {
32727- pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
32728- free_page((unsigned long)pmds[i]);
32729+ for(i = 0; i < PREALLOCATED_PXDS; i++)
32730+ if (pxds[i]) {
32731+ pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
32732+ free_page((unsigned long)pxds[i]);
32733 }
32734 }
32735
32736-static int preallocate_pmds(pmd_t *pmds[])
32737+static int preallocate_pxds(pxd_t *pxds[])
32738 {
32739 int i;
32740 bool failed = false;
32741
32742- for(i = 0; i < PREALLOCATED_PMDS; i++) {
32743- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
32744- if (!pmd)
32745+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
32746+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
32747+ if (!pxd)
32748 failed = true;
32749- if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
32750- free_page((unsigned long)pmd);
32751- pmd = NULL;
32752+ if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
32753+ free_page((unsigned long)pxd);
32754+ pxd = NULL;
32755 failed = true;
32756 }
32757- pmds[i] = pmd;
32758+ pxds[i] = pxd;
32759 }
32760
32761 if (failed) {
32762- free_pmds(pmds);
32763+ free_pxds(pxds);
32764 return -ENOMEM;
32765 }
32766
32767@@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
32768 * preallocate which never got a corresponding vma will need to be
32769 * freed manually.
32770 */
32771-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
32772+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
32773 {
32774 int i;
32775
32776- for(i = 0; i < PREALLOCATED_PMDS; i++) {
32777+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
32778 pgd_t pgd = pgdp[i];
32779
32780 if (pgd_val(pgd) != 0) {
32781- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
32782+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
32783
32784- pgdp[i] = native_make_pgd(0);
32785+ set_pgd(pgdp + i, native_make_pgd(0));
32786
32787- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
32788- pmd_free(mm, pmd);
32789+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
32790+ pxd_free(mm, pxd);
32791 }
32792 }
32793 }
32794
32795-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
32796+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
32797 {
32798- pud_t *pud;
32799+ pyd_t *pyd;
32800 int i;
32801
32802- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
32803+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
32804 return;
32805
32806- pud = pud_offset(pgd, 0);
32807-
32808- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
32809- pmd_t *pmd = pmds[i];
32810+#ifdef CONFIG_X86_64
32811+ pyd = pyd_offset(mm, 0L);
32812+#else
32813+ pyd = pyd_offset(pgd, 0L);
32814+#endif
32815
32816+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
32817+ pxd_t *pxd = pxds[i];
32818 if (i >= KERNEL_PGD_BOUNDARY)
32819- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32820- sizeof(pmd_t) * PTRS_PER_PMD);
32821+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32822+ sizeof(pxd_t) * PTRS_PER_PMD);
32823
32824- pud_populate(mm, pud, pmd);
32825+ pyd_populate(mm, pyd, pxd);
32826 }
32827 }
32828
32829 pgd_t *pgd_alloc(struct mm_struct *mm)
32830 {
32831 pgd_t *pgd;
32832- pmd_t *pmds[PREALLOCATED_PMDS];
32833+ pxd_t *pxds[PREALLOCATED_PXDS];
32834
32835 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
32836
32837@@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32838
32839 mm->pgd = pgd;
32840
32841- if (preallocate_pmds(pmds) != 0)
32842+ if (preallocate_pxds(pxds) != 0)
32843 goto out_free_pgd;
32844
32845 if (paravirt_pgd_alloc(mm) != 0)
32846- goto out_free_pmds;
32847+ goto out_free_pxds;
32848
32849 /*
32850 * Make sure that pre-populating the pmds is atomic with
32851@@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32852 spin_lock(&pgd_lock);
32853
32854 pgd_ctor(mm, pgd);
32855- pgd_prepopulate_pmd(mm, pgd, pmds);
32856+ pgd_prepopulate_pxd(mm, pgd, pxds);
32857
32858 spin_unlock(&pgd_lock);
32859
32860 return pgd;
32861
32862-out_free_pmds:
32863- free_pmds(pmds);
32864+out_free_pxds:
32865+ free_pxds(pxds);
32866 out_free_pgd:
32867 free_page((unsigned long)pgd);
32868 out:
32869@@ -313,7 +380,7 @@ out:
32870
32871 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
32872 {
32873- pgd_mop_up_pmds(mm, pgd);
32874+ pgd_mop_up_pxds(mm, pgd);
32875 pgd_dtor(pgd);
32876 paravirt_pgd_free(mm, pgd);
32877 free_page((unsigned long)pgd);
32878diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
32879index a69bcb8..19068ab 100644
32880--- a/arch/x86/mm/pgtable_32.c
32881+++ b/arch/x86/mm/pgtable_32.c
32882@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
32883 return;
32884 }
32885 pte = pte_offset_kernel(pmd, vaddr);
32886+
32887+ pax_open_kernel();
32888 if (pte_val(pteval))
32889 set_pte_at(&init_mm, vaddr, pte, pteval);
32890 else
32891 pte_clear(&init_mm, vaddr, pte);
32892+ pax_close_kernel();
32893
32894 /*
32895 * It's enough to flush this one mapping.
32896diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
32897index e666cbb..61788c45 100644
32898--- a/arch/x86/mm/physaddr.c
32899+++ b/arch/x86/mm/physaddr.c
32900@@ -10,7 +10,7 @@
32901 #ifdef CONFIG_X86_64
32902
32903 #ifdef CONFIG_DEBUG_VIRTUAL
32904-unsigned long __phys_addr(unsigned long x)
32905+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32906 {
32907 unsigned long y = x - __START_KERNEL_map;
32908
32909@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
32910 #else
32911
32912 #ifdef CONFIG_DEBUG_VIRTUAL
32913-unsigned long __phys_addr(unsigned long x)
32914+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32915 {
32916 unsigned long phys_addr = x - PAGE_OFFSET;
32917 /* VMALLOC_* aren't constants */
32918diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
32919index 90555bf..f5f1828 100644
32920--- a/arch/x86/mm/setup_nx.c
32921+++ b/arch/x86/mm/setup_nx.c
32922@@ -5,8 +5,10 @@
32923 #include <asm/pgtable.h>
32924 #include <asm/proto.h>
32925
32926+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32927 static int disable_nx;
32928
32929+#ifndef CONFIG_PAX_PAGEEXEC
32930 /*
32931 * noexec = on|off
32932 *
32933@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
32934 return 0;
32935 }
32936 early_param("noexec", noexec_setup);
32937+#endif
32938+
32939+#endif
32940
32941 void x86_configure_nx(void)
32942 {
32943+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32944 if (cpu_has_nx && !disable_nx)
32945 __supported_pte_mask |= _PAGE_NX;
32946 else
32947+#endif
32948 __supported_pte_mask &= ~_PAGE_NX;
32949 }
32950
32951diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
32952index ae699b3..f1b2ad2 100644
32953--- a/arch/x86/mm/tlb.c
32954+++ b/arch/x86/mm/tlb.c
32955@@ -48,7 +48,11 @@ void leave_mm(int cpu)
32956 BUG();
32957 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
32958 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
32959+
32960+#ifndef CONFIG_PAX_PER_CPU_PGD
32961 load_cr3(swapper_pg_dir);
32962+#endif
32963+
32964 }
32965 }
32966 EXPORT_SYMBOL_GPL(leave_mm);
32967diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
32968new file mode 100644
32969index 0000000..dace51c
32970--- /dev/null
32971+++ b/arch/x86/mm/uderef_64.c
32972@@ -0,0 +1,37 @@
32973+#include <linux/mm.h>
32974+#include <asm/pgtable.h>
32975+#include <asm/uaccess.h>
32976+
32977+#ifdef CONFIG_PAX_MEMORY_UDEREF
32978+/* PaX: due to the special call convention these functions must
32979+ * - remain leaf functions under all configurations,
32980+ * - never be called directly, only dereferenced from the wrappers.
32981+ */
32982+void __pax_open_userland(void)
32983+{
32984+ unsigned int cpu;
32985+
32986+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32987+ return;
32988+
32989+ cpu = raw_get_cpu();
32990+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
32991+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
32992+ raw_put_cpu_no_resched();
32993+}
32994+EXPORT_SYMBOL(__pax_open_userland);
32995+
32996+void __pax_close_userland(void)
32997+{
32998+ unsigned int cpu;
32999+
33000+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33001+ return;
33002+
33003+ cpu = raw_get_cpu();
33004+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33005+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33006+ raw_put_cpu_no_resched();
33007+}
33008+EXPORT_SYMBOL(__pax_close_userland);
33009+#endif
33010diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33011index 877b9a1..a8ecf42 100644
33012--- a/arch/x86/net/bpf_jit.S
33013+++ b/arch/x86/net/bpf_jit.S
33014@@ -9,6 +9,7 @@
33015 */
33016 #include <linux/linkage.h>
33017 #include <asm/dwarf2.h>
33018+#include <asm/alternative-asm.h>
33019
33020 /*
33021 * Calling convention :
33022@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33023 jle bpf_slow_path_word
33024 mov (SKBDATA,%rsi),%eax
33025 bswap %eax /* ntohl() */
33026+ pax_force_retaddr
33027 ret
33028
33029 sk_load_half:
33030@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33031 jle bpf_slow_path_half
33032 movzwl (SKBDATA,%rsi),%eax
33033 rol $8,%ax # ntohs()
33034+ pax_force_retaddr
33035 ret
33036
33037 sk_load_byte:
33038@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33039 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33040 jle bpf_slow_path_byte
33041 movzbl (SKBDATA,%rsi),%eax
33042+ pax_force_retaddr
33043 ret
33044
33045 /**
33046@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33047 movzbl (SKBDATA,%rsi),%ebx
33048 and $15,%bl
33049 shl $2,%bl
33050+ pax_force_retaddr
33051 ret
33052
33053 /* rsi contains offset and can be scratched */
33054@@ -109,6 +114,7 @@ bpf_slow_path_word:
33055 js bpf_error
33056 mov -12(%rbp),%eax
33057 bswap %eax
33058+ pax_force_retaddr
33059 ret
33060
33061 bpf_slow_path_half:
33062@@ -117,12 +123,14 @@ bpf_slow_path_half:
33063 mov -12(%rbp),%ax
33064 rol $8,%ax
33065 movzwl %ax,%eax
33066+ pax_force_retaddr
33067 ret
33068
33069 bpf_slow_path_byte:
33070 bpf_slow_path_common(1)
33071 js bpf_error
33072 movzbl -12(%rbp),%eax
33073+ pax_force_retaddr
33074 ret
33075
33076 bpf_slow_path_byte_msh:
33077@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33078 and $15,%al
33079 shl $2,%al
33080 xchg %eax,%ebx
33081+ pax_force_retaddr
33082 ret
33083
33084 #define sk_negative_common(SIZE) \
33085@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33086 sk_negative_common(4)
33087 mov (%rax), %eax
33088 bswap %eax
33089+ pax_force_retaddr
33090 ret
33091
33092 bpf_slow_path_half_neg:
33093@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33094 mov (%rax),%ax
33095 rol $8,%ax
33096 movzwl %ax,%eax
33097+ pax_force_retaddr
33098 ret
33099
33100 bpf_slow_path_byte_neg:
33101@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33102 .globl sk_load_byte_negative_offset
33103 sk_negative_common(1)
33104 movzbl (%rax), %eax
33105+ pax_force_retaddr
33106 ret
33107
33108 bpf_slow_path_byte_msh_neg:
33109@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33110 and $15,%al
33111 shl $2,%al
33112 xchg %eax,%ebx
33113+ pax_force_retaddr
33114 ret
33115
33116 bpf_error:
33117@@ -197,4 +210,5 @@ bpf_error:
33118 xor %eax,%eax
33119 mov -8(%rbp),%rbx
33120 leaveq
33121+ pax_force_retaddr
33122 ret
33123diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33124index 4ed75dd..8dfe0d5 100644
33125--- a/arch/x86/net/bpf_jit_comp.c
33126+++ b/arch/x86/net/bpf_jit_comp.c
33127@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33128 return ptr + len;
33129 }
33130
33131+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33132+#define MAX_INSTR_CODE_SIZE 96
33133+#else
33134+#define MAX_INSTR_CODE_SIZE 64
33135+#endif
33136+
33137 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33138
33139 #define EMIT1(b1) EMIT(b1, 1)
33140 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33141 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33142 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33143+
33144+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33145+/* original constant will appear in ecx */
33146+#define DILUTE_CONST_SEQUENCE(_off, _key) \
33147+do { \
33148+ /* mov ecx, randkey */ \
33149+ EMIT1(0xb9); \
33150+ EMIT(_key, 4); \
33151+ /* xor ecx, randkey ^ off */ \
33152+ EMIT2(0x81, 0xf1); \
33153+ EMIT((_key) ^ (_off), 4); \
33154+} while (0)
33155+
33156+#define EMIT1_off32(b1, _off) \
33157+do { \
33158+ switch (b1) { \
33159+ case 0x05: /* add eax, imm32 */ \
33160+ case 0x2d: /* sub eax, imm32 */ \
33161+ case 0x25: /* and eax, imm32 */ \
33162+ case 0x0d: /* or eax, imm32 */ \
33163+ case 0xb8: /* mov eax, imm32 */ \
33164+ case 0x35: /* xor eax, imm32 */ \
33165+ case 0x3d: /* cmp eax, imm32 */ \
33166+ case 0xa9: /* test eax, imm32 */ \
33167+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33168+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33169+ break; \
33170+ case 0xbb: /* mov ebx, imm32 */ \
33171+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33172+ /* mov ebx, ecx */ \
33173+ EMIT2(0x89, 0xcb); \
33174+ break; \
33175+ case 0xbe: /* mov esi, imm32 */ \
33176+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33177+ /* mov esi, ecx */ \
33178+ EMIT2(0x89, 0xce); \
33179+ break; \
33180+ case 0xe8: /* call rel imm32, always to known funcs */ \
33181+ EMIT1(b1); \
33182+ EMIT(_off, 4); \
33183+ break; \
33184+ case 0xe9: /* jmp rel imm32 */ \
33185+ EMIT1(b1); \
33186+ EMIT(_off, 4); \
33187+ /* prevent fall-through, we're not called if off = 0 */ \
33188+ EMIT(0xcccccccc, 4); \
33189+ EMIT(0xcccccccc, 4); \
33190+ break; \
33191+ default: \
33192+ BUILD_BUG(); \
33193+ } \
33194+} while (0)
33195+
33196+#define EMIT2_off32(b1, b2, _off) \
33197+do { \
33198+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33199+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33200+ EMIT(randkey, 4); \
33201+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33202+ EMIT((_off) - randkey, 4); \
33203+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33204+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33205+ /* imul eax, ecx */ \
33206+ EMIT3(0x0f, 0xaf, 0xc1); \
33207+ } else { \
33208+ BUILD_BUG(); \
33209+ } \
33210+} while (0)
33211+#else
33212 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33213+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33214+#endif
33215
33216 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33217 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33218@@ -91,6 +168,24 @@ do { \
33219 #define X86_JBE 0x76
33220 #define X86_JA 0x77
33221
33222+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33223+#define APPEND_FLOW_VERIFY() \
33224+do { \
33225+ /* mov ecx, randkey */ \
33226+ EMIT1(0xb9); \
33227+ EMIT(randkey, 4); \
33228+ /* cmp ecx, randkey */ \
33229+ EMIT2(0x81, 0xf9); \
33230+ EMIT(randkey, 4); \
33231+ /* jz after 8 int 3s */ \
33232+ EMIT2(0x74, 0x08); \
33233+ EMIT(0xcccccccc, 4); \
33234+ EMIT(0xcccccccc, 4); \
33235+} while (0)
33236+#else
33237+#define APPEND_FLOW_VERIFY() do { } while (0)
33238+#endif
33239+
33240 #define EMIT_COND_JMP(op, offset) \
33241 do { \
33242 if (is_near(offset)) \
33243@@ -98,6 +193,7 @@ do { \
33244 else { \
33245 EMIT2(0x0f, op + 0x10); \
33246 EMIT(offset, 4); /* jxx .+off32 */ \
33247+ APPEND_FLOW_VERIFY(); \
33248 } \
33249 } while (0)
33250
33251@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33252 return -1;
33253 }
33254
33255-struct bpf_binary_header {
33256- unsigned int pages;
33257- /* Note : for security reasons, bpf code will follow a randomly
33258- * sized amount of int3 instructions
33259- */
33260- u8 image[];
33261-};
33262-
33263-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33264+/* Note : for security reasons, bpf code will follow a randomly
33265+ * sized amount of int3 instructions
33266+ */
33267+static u8 *bpf_alloc_binary(unsigned int proglen,
33268 u8 **image_ptr)
33269 {
33270 unsigned int sz, hole;
33271- struct bpf_binary_header *header;
33272+ u8 *header;
33273
33274 /* Most of BPF filters are really small,
33275 * but if some of them fill a page, allow at least
33276 * 128 extra bytes to insert a random section of int3
33277 */
33278- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33279- header = module_alloc(sz);
33280+ sz = round_up(proglen + 128, PAGE_SIZE);
33281+ header = module_alloc_exec(sz);
33282 if (!header)
33283 return NULL;
33284
33285+ pax_open_kernel();
33286 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33287+ pax_close_kernel();
33288
33289- header->pages = sz / PAGE_SIZE;
33290- hole = sz - (proglen + sizeof(*header));
33291+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
33292
33293 /* insert a random number of int3 instructions before BPF code */
33294- *image_ptr = &header->image[prandom_u32() % hole];
33295+ *image_ptr = &header[prandom_u32() % hole];
33296 return header;
33297 }
33298
33299 void bpf_jit_compile(struct sk_filter *fp)
33300 {
33301- u8 temp[64];
33302+ u8 temp[MAX_INSTR_CODE_SIZE];
33303 u8 *prog;
33304 unsigned int proglen, oldproglen = 0;
33305 int ilen, i;
33306 int t_offset, f_offset;
33307 u8 t_op, f_op, seen = 0, pass;
33308 u8 *image = NULL;
33309- struct bpf_binary_header *header = NULL;
33310+ u8 *header = NULL;
33311 u8 *func;
33312 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
33313 unsigned int cleanup_addr; /* epilogue code offset */
33314 unsigned int *addrs;
33315 const struct sock_filter *filter = fp->insns;
33316 int flen = fp->len;
33317+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33318+ unsigned int randkey;
33319+#endif
33320
33321 if (!bpf_jit_enable)
33322 return;
33323@@ -202,11 +297,15 @@ void bpf_jit_compile(struct sk_filter *fp)
33324 if (addrs == NULL)
33325 return;
33326
33327+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33328+ randkey = get_random_int();
33329+#endif
33330+
33331 /* Before first pass, make a rough estimation of addrs[]
33332- * each bpf instruction is translated to less than 64 bytes
33333+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
33334 */
33335 for (proglen = 0, i = 0; i < flen; i++) {
33336- proglen += 64;
33337+ proglen += MAX_INSTR_CODE_SIZE;
33338 addrs[i] = proglen;
33339 }
33340 cleanup_addr = proglen; /* epilogue address */
33341@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
33342 case BPF_S_ALU_MUL_K: /* A *= K */
33343 if (is_imm8(K))
33344 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
33345- else {
33346- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
33347- EMIT(K, 4);
33348- }
33349+ else
33350+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
33351 break;
33352 case BPF_S_ALU_DIV_X: /* A /= X; */
33353 seen |= SEEN_XREG;
33354@@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33355 break;
33356 }
33357 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33358+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33359+ DILUTE_CONST_SEQUENCE(K, randkey);
33360+#else
33361 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33362+#endif
33363 EMIT2(0xf7, 0xf1); /* div %ecx */
33364 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
33365 break;
33366@@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33367 if (K == 1)
33368 break;
33369 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33370+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33371+ DILUTE_CONST_SEQUENCE(K, randkey);
33372+#else
33373 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33374+#endif
33375 EMIT2(0xf7, 0xf1); /* div %ecx */
33376 break;
33377 case BPF_S_ALU_AND_X:
33378@@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
33379 if (is_imm8(K)) {
33380 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
33381 } else {
33382- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
33383- EMIT(K, 4);
33384+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
33385 }
33386 } else {
33387 EMIT2(0x89,0xde); /* mov %ebx,%esi */
33388@@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33389 if (unlikely(proglen + ilen > oldproglen)) {
33390 pr_err("bpb_jit_compile fatal error\n");
33391 kfree(addrs);
33392- module_free(NULL, header);
33393+ module_free_exec(NULL, image);
33394 return;
33395 }
33396+ pax_open_kernel();
33397 memcpy(image + proglen, temp, ilen);
33398+ pax_close_kernel();
33399 }
33400 proglen += ilen;
33401 addrs[i] = proglen;
33402@@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33403
33404 if (image) {
33405 bpf_flush_icache(header, image + proglen);
33406- set_memory_ro((unsigned long)header, header->pages);
33407 fp->bpf_func = (void *)image;
33408 }
33409 out:
33410@@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
33411 {
33412 struct sk_filter *fp = container_of(work, struct sk_filter, work);
33413 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
33414- struct bpf_binary_header *header = (void *)addr;
33415
33416- set_memory_rw(addr, header->pages);
33417- module_free(NULL, header);
33418+ set_memory_rw(addr, 1);
33419+ module_free_exec(NULL, (void *)addr);
33420 kfree(fp);
33421 }
33422
33423diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
33424index 5d04be5..2beeaa2 100644
33425--- a/arch/x86/oprofile/backtrace.c
33426+++ b/arch/x86/oprofile/backtrace.c
33427@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
33428 struct stack_frame_ia32 *fp;
33429 unsigned long bytes;
33430
33431- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33432+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33433 if (bytes != 0)
33434 return NULL;
33435
33436- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
33437+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
33438
33439 oprofile_add_trace(bufhead[0].return_address);
33440
33441@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
33442 struct stack_frame bufhead[2];
33443 unsigned long bytes;
33444
33445- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33446+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33447 if (bytes != 0)
33448 return NULL;
33449
33450@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
33451 {
33452 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
33453
33454- if (!user_mode_vm(regs)) {
33455+ if (!user_mode(regs)) {
33456 unsigned long stack = kernel_stack_pointer(regs);
33457 if (depth)
33458 dump_trace(NULL, regs, (unsigned long *)stack, 0,
33459diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
33460index 6890d84..1dad1f1 100644
33461--- a/arch/x86/oprofile/nmi_int.c
33462+++ b/arch/x86/oprofile/nmi_int.c
33463@@ -23,6 +23,7 @@
33464 #include <asm/nmi.h>
33465 #include <asm/msr.h>
33466 #include <asm/apic.h>
33467+#include <asm/pgtable.h>
33468
33469 #include "op_counter.h"
33470 #include "op_x86_model.h"
33471@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
33472 if (ret)
33473 return ret;
33474
33475- if (!model->num_virt_counters)
33476- model->num_virt_counters = model->num_counters;
33477+ if (!model->num_virt_counters) {
33478+ pax_open_kernel();
33479+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
33480+ pax_close_kernel();
33481+ }
33482
33483 mux_init(ops);
33484
33485diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
33486index 50d86c0..7985318 100644
33487--- a/arch/x86/oprofile/op_model_amd.c
33488+++ b/arch/x86/oprofile/op_model_amd.c
33489@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
33490 num_counters = AMD64_NUM_COUNTERS;
33491 }
33492
33493- op_amd_spec.num_counters = num_counters;
33494- op_amd_spec.num_controls = num_counters;
33495- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
33496+ pax_open_kernel();
33497+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
33498+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
33499+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
33500+ pax_close_kernel();
33501
33502 return 0;
33503 }
33504diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
33505index d90528e..0127e2b 100644
33506--- a/arch/x86/oprofile/op_model_ppro.c
33507+++ b/arch/x86/oprofile/op_model_ppro.c
33508@@ -19,6 +19,7 @@
33509 #include <asm/msr.h>
33510 #include <asm/apic.h>
33511 #include <asm/nmi.h>
33512+#include <asm/pgtable.h>
33513
33514 #include "op_x86_model.h"
33515 #include "op_counter.h"
33516@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
33517
33518 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
33519
33520- op_arch_perfmon_spec.num_counters = num_counters;
33521- op_arch_perfmon_spec.num_controls = num_counters;
33522+ pax_open_kernel();
33523+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
33524+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
33525+ pax_close_kernel();
33526 }
33527
33528 static int arch_perfmon_init(struct oprofile_operations *ignore)
33529diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
33530index 71e8a67..6a313bb 100644
33531--- a/arch/x86/oprofile/op_x86_model.h
33532+++ b/arch/x86/oprofile/op_x86_model.h
33533@@ -52,7 +52,7 @@ struct op_x86_model_spec {
33534 void (*switch_ctrl)(struct op_x86_model_spec const *model,
33535 struct op_msrs const * const msrs);
33536 #endif
33537-};
33538+} __do_const;
33539
33540 struct op_counter_config;
33541
33542diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
33543index 51384ca..a25f51e 100644
33544--- a/arch/x86/pci/intel_mid_pci.c
33545+++ b/arch/x86/pci/intel_mid_pci.c
33546@@ -241,7 +241,7 @@ int __init intel_mid_pci_init(void)
33547 pr_info("Intel MID platform detected, using MID PCI ops\n");
33548 pci_mmcfg_late_init();
33549 pcibios_enable_irq = intel_mid_pci_irq_enable;
33550- pci_root_ops = intel_mid_pci_ops;
33551+ memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
33552 pci_soc_mode = 1;
33553 /* Continue with standard init */
33554 return 1;
33555diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
33556index 372e9b8..e775a6c 100644
33557--- a/arch/x86/pci/irq.c
33558+++ b/arch/x86/pci/irq.c
33559@@ -50,7 +50,7 @@ struct irq_router {
33560 struct irq_router_handler {
33561 u16 vendor;
33562 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
33563-};
33564+} __do_const;
33565
33566 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
33567 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
33568@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
33569 return 0;
33570 }
33571
33572-static __initdata struct irq_router_handler pirq_routers[] = {
33573+static __initconst const struct irq_router_handler pirq_routers[] = {
33574 { PCI_VENDOR_ID_INTEL, intel_router_probe },
33575 { PCI_VENDOR_ID_AL, ali_router_probe },
33576 { PCI_VENDOR_ID_ITE, ite_router_probe },
33577@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
33578 static void __init pirq_find_router(struct irq_router *r)
33579 {
33580 struct irq_routing_table *rt = pirq_table;
33581- struct irq_router_handler *h;
33582+ const struct irq_router_handler *h;
33583
33584 #ifdef CONFIG_PCI_BIOS
33585 if (!rt->signature) {
33586@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
33587 return 0;
33588 }
33589
33590-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
33591+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
33592 {
33593 .callback = fix_broken_hp_bios_irq9,
33594 .ident = "HP Pavilion N5400 Series Laptop",
33595diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
33596index c77b24a..c979855 100644
33597--- a/arch/x86/pci/pcbios.c
33598+++ b/arch/x86/pci/pcbios.c
33599@@ -79,7 +79,7 @@ union bios32 {
33600 static struct {
33601 unsigned long address;
33602 unsigned short segment;
33603-} bios32_indirect = { 0, __KERNEL_CS };
33604+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
33605
33606 /*
33607 * Returns the entry point for the given service, NULL on error
33608@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
33609 unsigned long length; /* %ecx */
33610 unsigned long entry; /* %edx */
33611 unsigned long flags;
33612+ struct desc_struct d, *gdt;
33613
33614 local_irq_save(flags);
33615- __asm__("lcall *(%%edi); cld"
33616+
33617+ gdt = get_cpu_gdt_table(smp_processor_id());
33618+
33619+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
33620+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
33621+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
33622+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
33623+
33624+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
33625 : "=a" (return_code),
33626 "=b" (address),
33627 "=c" (length),
33628 "=d" (entry)
33629 : "0" (service),
33630 "1" (0),
33631- "D" (&bios32_indirect));
33632+ "D" (&bios32_indirect),
33633+ "r"(__PCIBIOS_DS)
33634+ : "memory");
33635+
33636+ pax_open_kernel();
33637+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
33638+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
33639+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
33640+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
33641+ pax_close_kernel();
33642+
33643 local_irq_restore(flags);
33644
33645 switch (return_code) {
33646- case 0:
33647- return address + entry;
33648- case 0x80: /* Not present */
33649- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
33650- return 0;
33651- default: /* Shouldn't happen */
33652- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
33653- service, return_code);
33654+ case 0: {
33655+ int cpu;
33656+ unsigned char flags;
33657+
33658+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
33659+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
33660+ printk(KERN_WARNING "bios32_service: not valid\n");
33661 return 0;
33662+ }
33663+ address = address + PAGE_OFFSET;
33664+ length += 16UL; /* some BIOSs underreport this... */
33665+ flags = 4;
33666+ if (length >= 64*1024*1024) {
33667+ length >>= PAGE_SHIFT;
33668+ flags |= 8;
33669+ }
33670+
33671+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
33672+ gdt = get_cpu_gdt_table(cpu);
33673+ pack_descriptor(&d, address, length, 0x9b, flags);
33674+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
33675+ pack_descriptor(&d, address, length, 0x93, flags);
33676+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
33677+ }
33678+ return entry;
33679+ }
33680+ case 0x80: /* Not present */
33681+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
33682+ return 0;
33683+ default: /* Shouldn't happen */
33684+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
33685+ service, return_code);
33686+ return 0;
33687 }
33688 }
33689
33690 static struct {
33691 unsigned long address;
33692 unsigned short segment;
33693-} pci_indirect = { 0, __KERNEL_CS };
33694+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
33695
33696-static int pci_bios_present;
33697+static int pci_bios_present __read_only;
33698
33699 static int check_pcibios(void)
33700 {
33701@@ -131,11 +174,13 @@ static int check_pcibios(void)
33702 unsigned long flags, pcibios_entry;
33703
33704 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
33705- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
33706+ pci_indirect.address = pcibios_entry;
33707
33708 local_irq_save(flags);
33709- __asm__(
33710- "lcall *(%%edi); cld\n\t"
33711+ __asm__("movw %w6, %%ds\n\t"
33712+ "lcall *%%ss:(%%edi); cld\n\t"
33713+ "push %%ss\n\t"
33714+ "pop %%ds\n\t"
33715 "jc 1f\n\t"
33716 "xor %%ah, %%ah\n"
33717 "1:"
33718@@ -144,7 +189,8 @@ static int check_pcibios(void)
33719 "=b" (ebx),
33720 "=c" (ecx)
33721 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
33722- "D" (&pci_indirect)
33723+ "D" (&pci_indirect),
33724+ "r" (__PCIBIOS_DS)
33725 : "memory");
33726 local_irq_restore(flags);
33727
33728@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33729
33730 switch (len) {
33731 case 1:
33732- __asm__("lcall *(%%esi); cld\n\t"
33733+ __asm__("movw %w6, %%ds\n\t"
33734+ "lcall *%%ss:(%%esi); cld\n\t"
33735+ "push %%ss\n\t"
33736+ "pop %%ds\n\t"
33737 "jc 1f\n\t"
33738 "xor %%ah, %%ah\n"
33739 "1:"
33740@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33741 : "1" (PCIBIOS_READ_CONFIG_BYTE),
33742 "b" (bx),
33743 "D" ((long)reg),
33744- "S" (&pci_indirect));
33745+ "S" (&pci_indirect),
33746+ "r" (__PCIBIOS_DS));
33747 /*
33748 * Zero-extend the result beyond 8 bits, do not trust the
33749 * BIOS having done it:
33750@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33751 *value &= 0xff;
33752 break;
33753 case 2:
33754- __asm__("lcall *(%%esi); cld\n\t"
33755+ __asm__("movw %w6, %%ds\n\t"
33756+ "lcall *%%ss:(%%esi); cld\n\t"
33757+ "push %%ss\n\t"
33758+ "pop %%ds\n\t"
33759 "jc 1f\n\t"
33760 "xor %%ah, %%ah\n"
33761 "1:"
33762@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33763 : "1" (PCIBIOS_READ_CONFIG_WORD),
33764 "b" (bx),
33765 "D" ((long)reg),
33766- "S" (&pci_indirect));
33767+ "S" (&pci_indirect),
33768+ "r" (__PCIBIOS_DS));
33769 /*
33770 * Zero-extend the result beyond 16 bits, do not trust the
33771 * BIOS having done it:
33772@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33773 *value &= 0xffff;
33774 break;
33775 case 4:
33776- __asm__("lcall *(%%esi); cld\n\t"
33777+ __asm__("movw %w6, %%ds\n\t"
33778+ "lcall *%%ss:(%%esi); cld\n\t"
33779+ "push %%ss\n\t"
33780+ "pop %%ds\n\t"
33781 "jc 1f\n\t"
33782 "xor %%ah, %%ah\n"
33783 "1:"
33784@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33785 : "1" (PCIBIOS_READ_CONFIG_DWORD),
33786 "b" (bx),
33787 "D" ((long)reg),
33788- "S" (&pci_indirect));
33789+ "S" (&pci_indirect),
33790+ "r" (__PCIBIOS_DS));
33791 break;
33792 }
33793
33794@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33795
33796 switch (len) {
33797 case 1:
33798- __asm__("lcall *(%%esi); cld\n\t"
33799+ __asm__("movw %w6, %%ds\n\t"
33800+ "lcall *%%ss:(%%esi); cld\n\t"
33801+ "push %%ss\n\t"
33802+ "pop %%ds\n\t"
33803 "jc 1f\n\t"
33804 "xor %%ah, %%ah\n"
33805 "1:"
33806@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33807 "c" (value),
33808 "b" (bx),
33809 "D" ((long)reg),
33810- "S" (&pci_indirect));
33811+ "S" (&pci_indirect),
33812+ "r" (__PCIBIOS_DS));
33813 break;
33814 case 2:
33815- __asm__("lcall *(%%esi); cld\n\t"
33816+ __asm__("movw %w6, %%ds\n\t"
33817+ "lcall *%%ss:(%%esi); cld\n\t"
33818+ "push %%ss\n\t"
33819+ "pop %%ds\n\t"
33820 "jc 1f\n\t"
33821 "xor %%ah, %%ah\n"
33822 "1:"
33823@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33824 "c" (value),
33825 "b" (bx),
33826 "D" ((long)reg),
33827- "S" (&pci_indirect));
33828+ "S" (&pci_indirect),
33829+ "r" (__PCIBIOS_DS));
33830 break;
33831 case 4:
33832- __asm__("lcall *(%%esi); cld\n\t"
33833+ __asm__("movw %w6, %%ds\n\t"
33834+ "lcall *%%ss:(%%esi); cld\n\t"
33835+ "push %%ss\n\t"
33836+ "pop %%ds\n\t"
33837 "jc 1f\n\t"
33838 "xor %%ah, %%ah\n"
33839 "1:"
33840@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33841 "c" (value),
33842 "b" (bx),
33843 "D" ((long)reg),
33844- "S" (&pci_indirect));
33845+ "S" (&pci_indirect),
33846+ "r" (__PCIBIOS_DS));
33847 break;
33848 }
33849
33850@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33851
33852 DBG("PCI: Fetching IRQ routing table... ");
33853 __asm__("push %%es\n\t"
33854+ "movw %w8, %%ds\n\t"
33855 "push %%ds\n\t"
33856 "pop %%es\n\t"
33857- "lcall *(%%esi); cld\n\t"
33858+ "lcall *%%ss:(%%esi); cld\n\t"
33859 "pop %%es\n\t"
33860+ "push %%ss\n\t"
33861+ "pop %%ds\n"
33862 "jc 1f\n\t"
33863 "xor %%ah, %%ah\n"
33864 "1:"
33865@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33866 "1" (0),
33867 "D" ((long) &opt),
33868 "S" (&pci_indirect),
33869- "m" (opt)
33870+ "m" (opt),
33871+ "r" (__PCIBIOS_DS)
33872 : "memory");
33873 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
33874 if (ret & 0xff00)
33875@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33876 {
33877 int ret;
33878
33879- __asm__("lcall *(%%esi); cld\n\t"
33880+ __asm__("movw %w5, %%ds\n\t"
33881+ "lcall *%%ss:(%%esi); cld\n\t"
33882+ "push %%ss\n\t"
33883+ "pop %%ds\n"
33884 "jc 1f\n\t"
33885 "xor %%ah, %%ah\n"
33886 "1:"
33887@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33888 : "0" (PCIBIOS_SET_PCI_HW_INT),
33889 "b" ((dev->bus->number << 8) | dev->devfn),
33890 "c" ((irq << 8) | (pin + 10)),
33891- "S" (&pci_indirect));
33892+ "S" (&pci_indirect),
33893+ "r" (__PCIBIOS_DS));
33894 return !(ret & 0xff00);
33895 }
33896 EXPORT_SYMBOL(pcibios_set_irq_routing);
33897diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
33898index 40e4469..d915bf9 100644
33899--- a/arch/x86/platform/efi/efi_32.c
33900+++ b/arch/x86/platform/efi/efi_32.c
33901@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
33902 {
33903 struct desc_ptr gdt_descr;
33904
33905+#ifdef CONFIG_PAX_KERNEXEC
33906+ struct desc_struct d;
33907+#endif
33908+
33909 local_irq_save(efi_rt_eflags);
33910
33911 load_cr3(initial_page_table);
33912 __flush_tlb_all();
33913
33914+#ifdef CONFIG_PAX_KERNEXEC
33915+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
33916+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33917+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
33918+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33919+#endif
33920+
33921 gdt_descr.address = __pa(get_cpu_gdt_table(0));
33922 gdt_descr.size = GDT_SIZE - 1;
33923 load_gdt(&gdt_descr);
33924@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
33925 {
33926 struct desc_ptr gdt_descr;
33927
33928+#ifdef CONFIG_PAX_KERNEXEC
33929+ struct desc_struct d;
33930+
33931+ memset(&d, 0, sizeof d);
33932+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33933+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33934+#endif
33935+
33936 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
33937 gdt_descr.size = GDT_SIZE - 1;
33938 load_gdt(&gdt_descr);
33939
33940+#ifdef CONFIG_PAX_PER_CPU_PGD
33941+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33942+#else
33943 load_cr3(swapper_pg_dir);
33944+#endif
33945+
33946 __flush_tlb_all();
33947
33948 local_irq_restore(efi_rt_eflags);
33949diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
33950index 39a0e7f1..872396e 100644
33951--- a/arch/x86/platform/efi/efi_64.c
33952+++ b/arch/x86/platform/efi/efi_64.c
33953@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
33954 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
33955 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
33956 }
33957+
33958+#ifdef CONFIG_PAX_PER_CPU_PGD
33959+ load_cr3(swapper_pg_dir);
33960+#endif
33961+
33962 __flush_tlb_all();
33963 }
33964
33965@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
33966 for (pgd = 0; pgd < n_pgds; pgd++)
33967 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
33968 kfree(save_pgd);
33969+
33970+#ifdef CONFIG_PAX_PER_CPU_PGD
33971+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33972+#endif
33973+
33974 __flush_tlb_all();
33975 local_irq_restore(efi_flags);
33976 early_code_mapping_set_exec(0);
33977diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
33978index fbe66e6..eae5e38 100644
33979--- a/arch/x86/platform/efi/efi_stub_32.S
33980+++ b/arch/x86/platform/efi/efi_stub_32.S
33981@@ -6,7 +6,9 @@
33982 */
33983
33984 #include <linux/linkage.h>
33985+#include <linux/init.h>
33986 #include <asm/page_types.h>
33987+#include <asm/segment.h>
33988
33989 /*
33990 * efi_call_phys(void *, ...) is a function with variable parameters.
33991@@ -20,7 +22,7 @@
33992 * service functions will comply with gcc calling convention, too.
33993 */
33994
33995-.text
33996+__INIT
33997 ENTRY(efi_call_phys)
33998 /*
33999 * 0. The function can only be called in Linux kernel. So CS has been
34000@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34001 * The mapping of lower virtual memory has been created in prelog and
34002 * epilog.
34003 */
34004- movl $1f, %edx
34005- subl $__PAGE_OFFSET, %edx
34006- jmp *%edx
34007+#ifdef CONFIG_PAX_KERNEXEC
34008+ movl $(__KERNEXEC_EFI_DS), %edx
34009+ mov %edx, %ds
34010+ mov %edx, %es
34011+ mov %edx, %ss
34012+ addl $2f,(1f)
34013+ ljmp *(1f)
34014+
34015+__INITDATA
34016+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34017+.previous
34018+
34019+2:
34020+ subl $2b,(1b)
34021+#else
34022+ jmp 1f-__PAGE_OFFSET
34023 1:
34024+#endif
34025
34026 /*
34027 * 2. Now on the top of stack is the return
34028@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34029 * parameter 2, ..., param n. To make things easy, we save the return
34030 * address of efi_call_phys in a global variable.
34031 */
34032- popl %edx
34033- movl %edx, saved_return_addr
34034- /* get the function pointer into ECX*/
34035- popl %ecx
34036- movl %ecx, efi_rt_function_ptr
34037- movl $2f, %edx
34038- subl $__PAGE_OFFSET, %edx
34039- pushl %edx
34040+ popl (saved_return_addr)
34041+ popl (efi_rt_function_ptr)
34042
34043 /*
34044 * 3. Clear PG bit in %CR0.
34045@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34046 /*
34047 * 5. Call the physical function.
34048 */
34049- jmp *%ecx
34050+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
34051
34052-2:
34053 /*
34054 * 6. After EFI runtime service returns, control will return to
34055 * following instruction. We'd better readjust stack pointer first.
34056@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34057 movl %cr0, %edx
34058 orl $0x80000000, %edx
34059 movl %edx, %cr0
34060- jmp 1f
34061-1:
34062+
34063 /*
34064 * 8. Now restore the virtual mode from flat mode by
34065 * adding EIP with PAGE_OFFSET.
34066 */
34067- movl $1f, %edx
34068- jmp *%edx
34069+#ifdef CONFIG_PAX_KERNEXEC
34070+ movl $(__KERNEL_DS), %edx
34071+ mov %edx, %ds
34072+ mov %edx, %es
34073+ mov %edx, %ss
34074+ ljmp $(__KERNEL_CS),$1f
34075+#else
34076+ jmp 1f+__PAGE_OFFSET
34077+#endif
34078 1:
34079
34080 /*
34081 * 9. Balance the stack. And because EAX contain the return value,
34082 * we'd better not clobber it.
34083 */
34084- leal efi_rt_function_ptr, %edx
34085- movl (%edx), %ecx
34086- pushl %ecx
34087+ pushl (efi_rt_function_ptr)
34088
34089 /*
34090- * 10. Push the saved return address onto the stack and return.
34091+ * 10. Return to the saved return address.
34092 */
34093- leal saved_return_addr, %edx
34094- movl (%edx), %ecx
34095- pushl %ecx
34096- ret
34097+ jmpl *(saved_return_addr)
34098 ENDPROC(efi_call_phys)
34099 .previous
34100
34101-.data
34102+__INITDATA
34103 saved_return_addr:
34104 .long 0
34105 efi_rt_function_ptr:
34106diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34107index 4c07cca..2c8427d 100644
34108--- a/arch/x86/platform/efi/efi_stub_64.S
34109+++ b/arch/x86/platform/efi/efi_stub_64.S
34110@@ -7,6 +7,7 @@
34111 */
34112
34113 #include <linux/linkage.h>
34114+#include <asm/alternative-asm.h>
34115
34116 #define SAVE_XMM \
34117 mov %rsp, %rax; \
34118@@ -40,6 +41,7 @@ ENTRY(efi_call0)
34119 call *%rdi
34120 addq $32, %rsp
34121 RESTORE_XMM
34122+ pax_force_retaddr 0, 1
34123 ret
34124 ENDPROC(efi_call0)
34125
34126@@ -50,6 +52,7 @@ ENTRY(efi_call1)
34127 call *%rdi
34128 addq $32, %rsp
34129 RESTORE_XMM
34130+ pax_force_retaddr 0, 1
34131 ret
34132 ENDPROC(efi_call1)
34133
34134@@ -60,6 +63,7 @@ ENTRY(efi_call2)
34135 call *%rdi
34136 addq $32, %rsp
34137 RESTORE_XMM
34138+ pax_force_retaddr 0, 1
34139 ret
34140 ENDPROC(efi_call2)
34141
34142@@ -71,6 +75,7 @@ ENTRY(efi_call3)
34143 call *%rdi
34144 addq $32, %rsp
34145 RESTORE_XMM
34146+ pax_force_retaddr 0, 1
34147 ret
34148 ENDPROC(efi_call3)
34149
34150@@ -83,6 +88,7 @@ ENTRY(efi_call4)
34151 call *%rdi
34152 addq $32, %rsp
34153 RESTORE_XMM
34154+ pax_force_retaddr 0, 1
34155 ret
34156 ENDPROC(efi_call4)
34157
34158@@ -96,6 +102,7 @@ ENTRY(efi_call5)
34159 call *%rdi
34160 addq $48, %rsp
34161 RESTORE_XMM
34162+ pax_force_retaddr 0, 1
34163 ret
34164 ENDPROC(efi_call5)
34165
34166@@ -112,5 +119,6 @@ ENTRY(efi_call6)
34167 call *%rdi
34168 addq $48, %rsp
34169 RESTORE_XMM
34170+ pax_force_retaddr 0, 1
34171 ret
34172 ENDPROC(efi_call6)
34173diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34174index f90e290..435f0dd 100644
34175--- a/arch/x86/platform/intel-mid/intel-mid.c
34176+++ b/arch/x86/platform/intel-mid/intel-mid.c
34177@@ -65,9 +65,10 @@ static void intel_mid_power_off(void)
34178 {
34179 }
34180
34181-static void intel_mid_reboot(void)
34182+static void __noreturn intel_mid_reboot(void)
34183 {
34184 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34185+ BUG();
34186 }
34187
34188 static unsigned long __init intel_mid_calibrate_tsc(void)
34189diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34190index d6ee929..3637cb5 100644
34191--- a/arch/x86/platform/olpc/olpc_dt.c
34192+++ b/arch/x86/platform/olpc/olpc_dt.c
34193@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34194 return res;
34195 }
34196
34197-static struct of_pdt_ops prom_olpc_ops __initdata = {
34198+static struct of_pdt_ops prom_olpc_ops __initconst = {
34199 .nextprop = olpc_dt_nextprop,
34200 .getproplen = olpc_dt_getproplen,
34201 .getproperty = olpc_dt_getproperty,
34202diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34203index 424f4c9..f2a2988 100644
34204--- a/arch/x86/power/cpu.c
34205+++ b/arch/x86/power/cpu.c
34206@@ -137,11 +137,8 @@ static void do_fpu_end(void)
34207 static void fix_processor_context(void)
34208 {
34209 int cpu = smp_processor_id();
34210- struct tss_struct *t = &per_cpu(init_tss, cpu);
34211-#ifdef CONFIG_X86_64
34212- struct desc_struct *desc = get_cpu_gdt_table(cpu);
34213- tss_desc tss;
34214-#endif
34215+ struct tss_struct *t = init_tss + cpu;
34216+
34217 set_tss_desc(cpu, t); /*
34218 * This just modifies memory; should not be
34219 * necessary. But... This is necessary, because
34220@@ -150,10 +147,6 @@ static void fix_processor_context(void)
34221 */
34222
34223 #ifdef CONFIG_X86_64
34224- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34225- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34226- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34227-
34228 syscall_init(); /* This sets MSR_*STAR and related */
34229 #endif
34230 load_TR_desc(); /* This does ltr */
34231diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34232index a44f457..9140171 100644
34233--- a/arch/x86/realmode/init.c
34234+++ b/arch/x86/realmode/init.c
34235@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
34236 __va(real_mode_header->trampoline_header);
34237
34238 #ifdef CONFIG_X86_32
34239- trampoline_header->start = __pa_symbol(startup_32_smp);
34240+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34241+
34242+#ifdef CONFIG_PAX_KERNEXEC
34243+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34244+#endif
34245+
34246+ trampoline_header->boot_cs = __BOOT_CS;
34247 trampoline_header->gdt_limit = __BOOT_DS + 7;
34248 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34249 #else
34250@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
34251 *trampoline_cr4_features = read_cr4();
34252
34253 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34254- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34255+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34256 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34257 #endif
34258 }
34259diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34260index 9cac825..4890b25 100644
34261--- a/arch/x86/realmode/rm/Makefile
34262+++ b/arch/x86/realmode/rm/Makefile
34263@@ -79,5 +79,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
34264 $(call cc-option, -fno-unit-at-a-time)) \
34265 $(call cc-option, -fno-stack-protector) \
34266 $(call cc-option, -mpreferred-stack-boundary=2)
34267+ifdef CONSTIFY_PLUGIN
34268+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34269+endif
34270 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34271 GCOV_PROFILE := n
34272diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34273index a28221d..93c40f1 100644
34274--- a/arch/x86/realmode/rm/header.S
34275+++ b/arch/x86/realmode/rm/header.S
34276@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34277 #endif
34278 /* APM/BIOS reboot */
34279 .long pa_machine_real_restart_asm
34280-#ifdef CONFIG_X86_64
34281+#ifdef CONFIG_X86_32
34282+ .long __KERNEL_CS
34283+#else
34284 .long __KERNEL32_CS
34285 #endif
34286 END(real_mode_header)
34287diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
34288index c1b2791..f9e31c7 100644
34289--- a/arch/x86/realmode/rm/trampoline_32.S
34290+++ b/arch/x86/realmode/rm/trampoline_32.S
34291@@ -25,6 +25,12 @@
34292 #include <asm/page_types.h>
34293 #include "realmode.h"
34294
34295+#ifdef CONFIG_PAX_KERNEXEC
34296+#define ta(X) (X)
34297+#else
34298+#define ta(X) (pa_ ## X)
34299+#endif
34300+
34301 .text
34302 .code16
34303
34304@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
34305
34306 cli # We should be safe anyway
34307
34308- movl tr_start, %eax # where we need to go
34309-
34310 movl $0xA5A5A5A5, trampoline_status
34311 # write marker for master knows we're running
34312
34313@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
34314 movw $1, %dx # protected mode (PE) bit
34315 lmsw %dx # into protected mode
34316
34317- ljmpl $__BOOT_CS, $pa_startup_32
34318+ ljmpl *(trampoline_header)
34319
34320 .section ".text32","ax"
34321 .code32
34322@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
34323 .balign 8
34324 GLOBAL(trampoline_header)
34325 tr_start: .space 4
34326- tr_gdt_pad: .space 2
34327+ tr_boot_cs: .space 2
34328 tr_gdt: .space 6
34329 END(trampoline_header)
34330
34331diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
34332index bb360dc..d0fd8f8 100644
34333--- a/arch/x86/realmode/rm/trampoline_64.S
34334+++ b/arch/x86/realmode/rm/trampoline_64.S
34335@@ -94,6 +94,7 @@ ENTRY(startup_32)
34336 movl %edx, %gs
34337
34338 movl pa_tr_cr4, %eax
34339+ andl $~X86_CR4_PCIDE, %eax
34340 movl %eax, %cr4 # Enable PAE mode
34341
34342 # Setup trampoline 4 level pagetables
34343@@ -107,7 +108,7 @@ ENTRY(startup_32)
34344 wrmsr
34345
34346 # Enable paging and in turn activate Long Mode
34347- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
34348+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
34349 movl %eax, %cr0
34350
34351 /*
34352diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
34353index e812034..c747134 100644
34354--- a/arch/x86/tools/Makefile
34355+++ b/arch/x86/tools/Makefile
34356@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
34357
34358 $(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
34359
34360-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
34361+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
34362 hostprogs-y += relocs
34363 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
34364 relocs: $(obj)/relocs
34365diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
34366index f7bab68..b6d9886 100644
34367--- a/arch/x86/tools/relocs.c
34368+++ b/arch/x86/tools/relocs.c
34369@@ -1,5 +1,7 @@
34370 /* This is included from relocs_32/64.c */
34371
34372+#include "../../../include/generated/autoconf.h"
34373+
34374 #define ElfW(type) _ElfW(ELF_BITS, type)
34375 #define _ElfW(bits, type) __ElfW(bits, type)
34376 #define __ElfW(bits, type) Elf##bits##_##type
34377@@ -11,6 +13,7 @@
34378 #define Elf_Sym ElfW(Sym)
34379
34380 static Elf_Ehdr ehdr;
34381+static Elf_Phdr *phdr;
34382
34383 struct relocs {
34384 uint32_t *offset;
34385@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
34386 }
34387 }
34388
34389+static void read_phdrs(FILE *fp)
34390+{
34391+ unsigned int i;
34392+
34393+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
34394+ if (!phdr) {
34395+ die("Unable to allocate %d program headers\n",
34396+ ehdr.e_phnum);
34397+ }
34398+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
34399+ die("Seek to %d failed: %s\n",
34400+ ehdr.e_phoff, strerror(errno));
34401+ }
34402+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
34403+ die("Cannot read ELF program headers: %s\n",
34404+ strerror(errno));
34405+ }
34406+ for(i = 0; i < ehdr.e_phnum; i++) {
34407+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
34408+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
34409+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
34410+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
34411+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
34412+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
34413+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
34414+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
34415+ }
34416+
34417+}
34418+
34419 static void read_shdrs(FILE *fp)
34420 {
34421- int i;
34422+ unsigned int i;
34423 Elf_Shdr shdr;
34424
34425 secs = calloc(ehdr.e_shnum, sizeof(struct section));
34426@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
34427
34428 static void read_strtabs(FILE *fp)
34429 {
34430- int i;
34431+ unsigned int i;
34432 for (i = 0; i < ehdr.e_shnum; i++) {
34433 struct section *sec = &secs[i];
34434 if (sec->shdr.sh_type != SHT_STRTAB) {
34435@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
34436
34437 static void read_symtabs(FILE *fp)
34438 {
34439- int i,j;
34440+ unsigned int i,j;
34441 for (i = 0; i < ehdr.e_shnum; i++) {
34442 struct section *sec = &secs[i];
34443 if (sec->shdr.sh_type != SHT_SYMTAB) {
34444@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
34445 }
34446
34447
34448-static void read_relocs(FILE *fp)
34449+static void read_relocs(FILE *fp, int use_real_mode)
34450 {
34451- int i,j;
34452+ unsigned int i,j;
34453+ uint32_t base;
34454+
34455 for (i = 0; i < ehdr.e_shnum; i++) {
34456 struct section *sec = &secs[i];
34457 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34458@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
34459 die("Cannot read symbol table: %s\n",
34460 strerror(errno));
34461 }
34462+ base = 0;
34463+
34464+#ifdef CONFIG_X86_32
34465+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
34466+ if (phdr[j].p_type != PT_LOAD )
34467+ continue;
34468+ 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)
34469+ continue;
34470+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
34471+ break;
34472+ }
34473+#endif
34474+
34475 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
34476 Elf_Rel *rel = &sec->reltab[j];
34477- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
34478+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
34479 rel->r_info = elf_xword_to_cpu(rel->r_info);
34480 #if (SHT_REL_TYPE == SHT_RELA)
34481 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
34482@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
34483
34484 static void print_absolute_symbols(void)
34485 {
34486- int i;
34487+ unsigned int i;
34488 const char *format;
34489
34490 if (ELF_BITS == 64)
34491@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
34492 for (i = 0; i < ehdr.e_shnum; i++) {
34493 struct section *sec = &secs[i];
34494 char *sym_strtab;
34495- int j;
34496+ unsigned int j;
34497
34498 if (sec->shdr.sh_type != SHT_SYMTAB) {
34499 continue;
34500@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
34501
34502 static void print_absolute_relocs(void)
34503 {
34504- int i, printed = 0;
34505+ unsigned int i, printed = 0;
34506 const char *format;
34507
34508 if (ELF_BITS == 64)
34509@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
34510 struct section *sec_applies, *sec_symtab;
34511 char *sym_strtab;
34512 Elf_Sym *sh_symtab;
34513- int j;
34514+ unsigned int j;
34515 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34516 continue;
34517 }
34518@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
34519 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
34520 Elf_Sym *sym, const char *symname))
34521 {
34522- int i;
34523+ unsigned int i;
34524 /* Walk through the relocations */
34525 for (i = 0; i < ehdr.e_shnum; i++) {
34526 char *sym_strtab;
34527 Elf_Sym *sh_symtab;
34528 struct section *sec_applies, *sec_symtab;
34529- int j;
34530+ unsigned int j;
34531 struct section *sec = &secs[i];
34532
34533 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34534@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
34535 {
34536 unsigned r_type = ELF32_R_TYPE(rel->r_info);
34537 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
34538+ char *sym_strtab = sec->link->link->strtab;
34539+
34540+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
34541+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
34542+ return 0;
34543+
34544+#ifdef CONFIG_PAX_KERNEXEC
34545+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
34546+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
34547+ return 0;
34548+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
34549+ return 0;
34550+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
34551+ return 0;
34552+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
34553+ return 0;
34554+#endif
34555
34556 switch (r_type) {
34557 case R_386_NONE:
34558@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
34559
34560 static void emit_relocs(int as_text, int use_real_mode)
34561 {
34562- int i;
34563+ unsigned int i;
34564 int (*write_reloc)(uint32_t, FILE *) = write32;
34565 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
34566 const char *symname);
34567@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
34568 {
34569 regex_init(use_real_mode);
34570 read_ehdr(fp);
34571+ read_phdrs(fp);
34572 read_shdrs(fp);
34573 read_strtabs(fp);
34574 read_symtabs(fp);
34575- read_relocs(fp);
34576+ read_relocs(fp, use_real_mode);
34577 if (ELF_BITS == 64)
34578 percpu_init();
34579 if (show_absolute_syms) {
34580diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
34581index 80ffa5b..a33bd15 100644
34582--- a/arch/x86/um/tls_32.c
34583+++ b/arch/x86/um/tls_32.c
34584@@ -260,7 +260,7 @@ out:
34585 if (unlikely(task == current &&
34586 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
34587 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
34588- "without flushed TLS.", current->pid);
34589+ "without flushed TLS.", task_pid_nr(current));
34590 }
34591
34592 return 0;
34593diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
34594index fd14be1..e3c79c0 100644
34595--- a/arch/x86/vdso/Makefile
34596+++ b/arch/x86/vdso/Makefile
34597@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
34598 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
34599 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
34600
34601-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
34602+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
34603 GCOV_PROFILE := n
34604
34605 #
34606diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
34607index d6bfb87..876ee18 100644
34608--- a/arch/x86/vdso/vdso32-setup.c
34609+++ b/arch/x86/vdso/vdso32-setup.c
34610@@ -25,6 +25,7 @@
34611 #include <asm/tlbflush.h>
34612 #include <asm/vdso.h>
34613 #include <asm/proto.h>
34614+#include <asm/mman.h>
34615
34616 enum {
34617 VDSO_DISABLED = 0,
34618@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
34619 void enable_sep_cpu(void)
34620 {
34621 int cpu = get_cpu();
34622- struct tss_struct *tss = &per_cpu(init_tss, cpu);
34623+ struct tss_struct *tss = init_tss + cpu;
34624
34625 if (!boot_cpu_has(X86_FEATURE_SEP)) {
34626 put_cpu();
34627@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
34628 gate_vma.vm_start = FIXADDR_USER_START;
34629 gate_vma.vm_end = FIXADDR_USER_END;
34630 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
34631- gate_vma.vm_page_prot = __P101;
34632+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
34633
34634 return 0;
34635 }
34636@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34637 if (compat)
34638 addr = VDSO_HIGH_BASE;
34639 else {
34640- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
34641+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
34642 if (IS_ERR_VALUE(addr)) {
34643 ret = addr;
34644 goto up_fail;
34645 }
34646 }
34647
34648- current->mm->context.vdso = (void *)addr;
34649+ current->mm->context.vdso = addr;
34650
34651 if (compat_uses_vma || !compat) {
34652 /*
34653@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34654 }
34655
34656 current_thread_info()->sysenter_return =
34657- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
34658+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
34659
34660 up_fail:
34661 if (ret)
34662- current->mm->context.vdso = NULL;
34663+ current->mm->context.vdso = 0;
34664
34665 up_write(&mm->mmap_sem);
34666
34667@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
34668
34669 const char *arch_vma_name(struct vm_area_struct *vma)
34670 {
34671- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
34672+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
34673 return "[vdso]";
34674+
34675+#ifdef CONFIG_PAX_SEGMEXEC
34676+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
34677+ return "[vdso]";
34678+#endif
34679+
34680 return NULL;
34681 }
34682
34683@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
34684 * Check to see if the corresponding task was created in compat vdso
34685 * mode.
34686 */
34687- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
34688+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
34689 return &gate_vma;
34690 return NULL;
34691 }
34692diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
34693index 431e875..cbb23f3 100644
34694--- a/arch/x86/vdso/vma.c
34695+++ b/arch/x86/vdso/vma.c
34696@@ -16,8 +16,6 @@
34697 #include <asm/vdso.h>
34698 #include <asm/page.h>
34699
34700-unsigned int __read_mostly vdso_enabled = 1;
34701-
34702 extern char vdso_start[], vdso_end[];
34703 extern unsigned short vdso_sync_cpuid;
34704
34705@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
34706 * unaligned here as a result of stack start randomization.
34707 */
34708 addr = PAGE_ALIGN(addr);
34709- addr = align_vdso_addr(addr);
34710
34711 return addr;
34712 }
34713@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
34714 unsigned size)
34715 {
34716 struct mm_struct *mm = current->mm;
34717- unsigned long addr;
34718+ unsigned long addr = 0;
34719 int ret;
34720
34721- if (!vdso_enabled)
34722- return 0;
34723-
34724 down_write(&mm->mmap_sem);
34725+
34726+#ifdef CONFIG_PAX_RANDMMAP
34727+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
34728+#endif
34729+
34730 addr = vdso_addr(mm->start_stack, size);
34731+ addr = align_vdso_addr(addr);
34732 addr = get_unmapped_area(NULL, addr, size, 0, 0);
34733 if (IS_ERR_VALUE(addr)) {
34734 ret = addr;
34735 goto up_fail;
34736 }
34737
34738- current->mm->context.vdso = (void *)addr;
34739+ mm->context.vdso = addr;
34740
34741 ret = install_special_mapping(mm, addr, size,
34742 VM_READ|VM_EXEC|
34743 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
34744 pages);
34745- if (ret) {
34746- current->mm->context.vdso = NULL;
34747- goto up_fail;
34748- }
34749+ if (ret)
34750+ mm->context.vdso = 0;
34751
34752 up_fail:
34753 up_write(&mm->mmap_sem);
34754@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34755 vdsox32_size);
34756 }
34757 #endif
34758-
34759-static __init int vdso_setup(char *s)
34760-{
34761- vdso_enabled = simple_strtoul(s, NULL, 0);
34762- return 0;
34763-}
34764-__setup("vdso=", vdso_setup);
34765diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
34766index fa6ade7..73da73a5 100644
34767--- a/arch/x86/xen/enlighten.c
34768+++ b/arch/x86/xen/enlighten.c
34769@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
34770
34771 struct shared_info xen_dummy_shared_info;
34772
34773-void *xen_initial_gdt;
34774-
34775 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
34776 __read_mostly int xen_have_vector_callback;
34777 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
34778@@ -541,8 +539,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
34779 {
34780 unsigned long va = dtr->address;
34781 unsigned int size = dtr->size + 1;
34782- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
34783- unsigned long frames[pages];
34784+ unsigned long frames[65536 / PAGE_SIZE];
34785 int f;
34786
34787 /*
34788@@ -590,8 +587,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
34789 {
34790 unsigned long va = dtr->address;
34791 unsigned int size = dtr->size + 1;
34792- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
34793- unsigned long frames[pages];
34794+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
34795 int f;
34796
34797 /*
34798@@ -599,7 +595,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
34799 * 8-byte entries, or 16 4k pages..
34800 */
34801
34802- BUG_ON(size > 65536);
34803+ BUG_ON(size > GDT_SIZE);
34804 BUG_ON(va & ~PAGE_MASK);
34805
34806 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
34807@@ -988,7 +984,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
34808 return 0;
34809 }
34810
34811-static void set_xen_basic_apic_ops(void)
34812+static void __init set_xen_basic_apic_ops(void)
34813 {
34814 apic->read = xen_apic_read;
34815 apic->write = xen_apic_write;
34816@@ -1293,30 +1289,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
34817 #endif
34818 };
34819
34820-static void xen_reboot(int reason)
34821+static __noreturn void xen_reboot(int reason)
34822 {
34823 struct sched_shutdown r = { .reason = reason };
34824
34825- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
34826- BUG();
34827+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
34828+ BUG();
34829 }
34830
34831-static void xen_restart(char *msg)
34832+static __noreturn void xen_restart(char *msg)
34833 {
34834 xen_reboot(SHUTDOWN_reboot);
34835 }
34836
34837-static void xen_emergency_restart(void)
34838+static __noreturn void xen_emergency_restart(void)
34839 {
34840 xen_reboot(SHUTDOWN_reboot);
34841 }
34842
34843-static void xen_machine_halt(void)
34844+static __noreturn void xen_machine_halt(void)
34845 {
34846 xen_reboot(SHUTDOWN_poweroff);
34847 }
34848
34849-static void xen_machine_power_off(void)
34850+static __noreturn void xen_machine_power_off(void)
34851 {
34852 if (pm_power_off)
34853 pm_power_off();
34854@@ -1467,7 +1463,17 @@ asmlinkage void __init xen_start_kernel(void)
34855 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
34856
34857 /* Work out if we support NX */
34858- x86_configure_nx();
34859+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34860+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
34861+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
34862+ unsigned l, h;
34863+
34864+ __supported_pte_mask |= _PAGE_NX;
34865+ rdmsr(MSR_EFER, l, h);
34866+ l |= EFER_NX;
34867+ wrmsr(MSR_EFER, l, h);
34868+ }
34869+#endif
34870
34871 xen_setup_features();
34872
34873@@ -1498,13 +1504,6 @@ asmlinkage void __init xen_start_kernel(void)
34874
34875 machine_ops = xen_machine_ops;
34876
34877- /*
34878- * The only reliable way to retain the initial address of the
34879- * percpu gdt_page is to remember it here, so we can go and
34880- * mark it RW later, when the initial percpu area is freed.
34881- */
34882- xen_initial_gdt = &per_cpu(gdt_page, 0);
34883-
34884 xen_smp_init();
34885
34886 #ifdef CONFIG_ACPI_NUMA
34887diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
34888index ce563be..7327d91 100644
34889--- a/arch/x86/xen/mmu.c
34890+++ b/arch/x86/xen/mmu.c
34891@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
34892 return val;
34893 }
34894
34895-static pteval_t pte_pfn_to_mfn(pteval_t val)
34896+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
34897 {
34898 if (val & _PAGE_PRESENT) {
34899 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
34900@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34901 /* L3_k[510] -> level2_kernel_pgt
34902 * L3_i[511] -> level2_fixmap_pgt */
34903 convert_pfn_mfn(level3_kernel_pgt);
34904+ convert_pfn_mfn(level3_vmalloc_start_pgt);
34905+ convert_pfn_mfn(level3_vmalloc_end_pgt);
34906+ convert_pfn_mfn(level3_vmemmap_pgt);
34907
34908 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
34909 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
34910@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34911 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
34912 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
34913 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
34914+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
34915+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
34916+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
34917 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
34918 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
34919+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
34920 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
34921 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
34922
34923@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
34924 pv_mmu_ops.set_pud = xen_set_pud;
34925 #if PAGETABLE_LEVELS == 4
34926 pv_mmu_ops.set_pgd = xen_set_pgd;
34927+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
34928 #endif
34929
34930 /* This will work as long as patching hasn't happened yet
34931@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
34932 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
34933 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
34934 .set_pgd = xen_set_pgd_hyper,
34935+ .set_pgd_batched = xen_set_pgd_hyper,
34936
34937 .alloc_pud = xen_alloc_pmd_init,
34938 .release_pud = xen_release_pmd_init,
34939diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
34940index c36b325..b0f1518 100644
34941--- a/arch/x86/xen/smp.c
34942+++ b/arch/x86/xen/smp.c
34943@@ -274,17 +274,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
34944 native_smp_prepare_boot_cpu();
34945
34946 if (xen_pv_domain()) {
34947- /* We've switched to the "real" per-cpu gdt, so make sure the
34948- old memory can be recycled */
34949- make_lowmem_page_readwrite(xen_initial_gdt);
34950-
34951 #ifdef CONFIG_X86_32
34952 /*
34953 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
34954 * expects __USER_DS
34955 */
34956- loadsegment(ds, __USER_DS);
34957- loadsegment(es, __USER_DS);
34958+ loadsegment(ds, __KERNEL_DS);
34959+ loadsegment(es, __KERNEL_DS);
34960 #endif
34961
34962 xen_filter_cpu_maps();
34963@@ -364,7 +360,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34964 ctxt->user_regs.ss = __KERNEL_DS;
34965 #ifdef CONFIG_X86_32
34966 ctxt->user_regs.fs = __KERNEL_PERCPU;
34967- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
34968+ savesegment(gs, ctxt->user_regs.gs);
34969 #else
34970 ctxt->gs_base_kernel = per_cpu_offset(cpu);
34971 #endif
34972@@ -374,8 +370,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34973
34974 {
34975 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
34976- ctxt->user_regs.ds = __USER_DS;
34977- ctxt->user_regs.es = __USER_DS;
34978+ ctxt->user_regs.ds = __KERNEL_DS;
34979+ ctxt->user_regs.es = __KERNEL_DS;
34980
34981 xen_copy_trap_info(ctxt->trap_ctxt);
34982
34983@@ -420,13 +416,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
34984 int rc;
34985
34986 per_cpu(current_task, cpu) = idle;
34987+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
34988 #ifdef CONFIG_X86_32
34989 irq_ctx_init(cpu);
34990 #else
34991 clear_tsk_thread_flag(idle, TIF_FORK);
34992- per_cpu(kernel_stack, cpu) =
34993- (unsigned long)task_stack_page(idle) -
34994- KERNEL_STACK_OFFSET + THREAD_SIZE;
34995+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
34996 #endif
34997 xen_setup_runstate_info(cpu);
34998 xen_setup_timer(cpu);
34999@@ -702,7 +697,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35000
35001 void __init xen_smp_init(void)
35002 {
35003- smp_ops = xen_smp_ops;
35004+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35005 xen_fill_possible_map();
35006 }
35007
35008diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35009index 33ca6e4..0ded929 100644
35010--- a/arch/x86/xen/xen-asm_32.S
35011+++ b/arch/x86/xen/xen-asm_32.S
35012@@ -84,14 +84,14 @@ ENTRY(xen_iret)
35013 ESP_OFFSET=4 # bytes pushed onto stack
35014
35015 /*
35016- * Store vcpu_info pointer for easy access. Do it this way to
35017- * avoid having to reload %fs
35018+ * Store vcpu_info pointer for easy access.
35019 */
35020 #ifdef CONFIG_SMP
35021- GET_THREAD_INFO(%eax)
35022- movl %ss:TI_cpu(%eax), %eax
35023- movl %ss:__per_cpu_offset(,%eax,4), %eax
35024- mov %ss:xen_vcpu(%eax), %eax
35025+ push %fs
35026+ mov $(__KERNEL_PERCPU), %eax
35027+ mov %eax, %fs
35028+ mov PER_CPU_VAR(xen_vcpu), %eax
35029+ pop %fs
35030 #else
35031 movl %ss:xen_vcpu, %eax
35032 #endif
35033diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35034index 7faed58..ba4427c 100644
35035--- a/arch/x86/xen/xen-head.S
35036+++ b/arch/x86/xen/xen-head.S
35037@@ -19,6 +19,17 @@ ENTRY(startup_xen)
35038 #ifdef CONFIG_X86_32
35039 mov %esi,xen_start_info
35040 mov $init_thread_union+THREAD_SIZE,%esp
35041+#ifdef CONFIG_SMP
35042+ movl $cpu_gdt_table,%edi
35043+ movl $__per_cpu_load,%eax
35044+ movw %ax,__KERNEL_PERCPU + 2(%edi)
35045+ rorl $16,%eax
35046+ movb %al,__KERNEL_PERCPU + 4(%edi)
35047+ movb %ah,__KERNEL_PERCPU + 7(%edi)
35048+ movl $__per_cpu_end - 1,%eax
35049+ subl $__per_cpu_start,%eax
35050+ movw %ax,__KERNEL_PERCPU + 0(%edi)
35051+#endif
35052 #else
35053 mov %rsi,xen_start_info
35054 mov $init_thread_union+THREAD_SIZE,%rsp
35055diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35056index 95f8c61..611d6e8 100644
35057--- a/arch/x86/xen/xen-ops.h
35058+++ b/arch/x86/xen/xen-ops.h
35059@@ -10,8 +10,6 @@
35060 extern const char xen_hypervisor_callback[];
35061 extern const char xen_failsafe_callback[];
35062
35063-extern void *xen_initial_gdt;
35064-
35065 struct trap_info;
35066 void xen_copy_trap_info(struct trap_info *traps);
35067
35068diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35069index 525bd3d..ef888b1 100644
35070--- a/arch/xtensa/variants/dc232b/include/variant/core.h
35071+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35072@@ -119,9 +119,9 @@
35073 ----------------------------------------------------------------------*/
35074
35075 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35076-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35077 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35078 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35079+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35080
35081 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35082 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35083diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35084index 2f33760..835e50a 100644
35085--- a/arch/xtensa/variants/fsf/include/variant/core.h
35086+++ b/arch/xtensa/variants/fsf/include/variant/core.h
35087@@ -11,6 +11,7 @@
35088 #ifndef _XTENSA_CORE_H
35089 #define _XTENSA_CORE_H
35090
35091+#include <linux/const.h>
35092
35093 /****************************************************************************
35094 Parameters Useful for Any Code, USER or PRIVILEGED
35095@@ -112,9 +113,9 @@
35096 ----------------------------------------------------------------------*/
35097
35098 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35099-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35100 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35101 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35102+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35103
35104 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35105 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35106diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35107index af00795..2bb8105 100644
35108--- a/arch/xtensa/variants/s6000/include/variant/core.h
35109+++ b/arch/xtensa/variants/s6000/include/variant/core.h
35110@@ -11,6 +11,7 @@
35111 #ifndef _XTENSA_CORE_CONFIGURATION_H
35112 #define _XTENSA_CORE_CONFIGURATION_H
35113
35114+#include <linux/const.h>
35115
35116 /****************************************************************************
35117 Parameters Useful for Any Code, USER or PRIVILEGED
35118@@ -118,9 +119,9 @@
35119 ----------------------------------------------------------------------*/
35120
35121 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35122-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35123 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35124 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35125+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35126
35127 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35128 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35129diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35130index 4e491d9..c8e18e4 100644
35131--- a/block/blk-cgroup.c
35132+++ b/block/blk-cgroup.c
35133@@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35134 static struct cgroup_subsys_state *
35135 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35136 {
35137- static atomic64_t id_seq = ATOMIC64_INIT(0);
35138+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35139 struct blkcg *blkcg;
35140
35141 if (!parent_css) {
35142@@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35143
35144 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35145 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35146- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35147+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35148 done:
35149 spin_lock_init(&blkcg->lock);
35150 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35151diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35152index 1855bf5..af12b06 100644
35153--- a/block/blk-iopoll.c
35154+++ b/block/blk-iopoll.c
35155@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35156 }
35157 EXPORT_SYMBOL(blk_iopoll_complete);
35158
35159-static void blk_iopoll_softirq(struct softirq_action *h)
35160+static __latent_entropy void blk_iopoll_softirq(void)
35161 {
35162 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35163 int rearm = 0, budget = blk_iopoll_budget;
35164diff --git a/block/blk-map.c b/block/blk-map.c
35165index 623e1cd..ca1e109 100644
35166--- a/block/blk-map.c
35167+++ b/block/blk-map.c
35168@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35169 if (!len || !kbuf)
35170 return -EINVAL;
35171
35172- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35173+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35174 if (do_copy)
35175 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35176 else
35177diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35178index 57790c1..5e988dd 100644
35179--- a/block/blk-softirq.c
35180+++ b/block/blk-softirq.c
35181@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35182 * Softirq action handler - move entries to local list and loop over them
35183 * while passing them to the queue registered handler.
35184 */
35185-static void blk_done_softirq(struct softirq_action *h)
35186+static __latent_entropy void blk_done_softirq(void)
35187 {
35188 struct list_head *cpu_list, local_list;
35189
35190diff --git a/block/bsg.c b/block/bsg.c
35191index 420a5a9..23834aa 100644
35192--- a/block/bsg.c
35193+++ b/block/bsg.c
35194@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35195 struct sg_io_v4 *hdr, struct bsg_device *bd,
35196 fmode_t has_write_perm)
35197 {
35198+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35199+ unsigned char *cmdptr;
35200+
35201 if (hdr->request_len > BLK_MAX_CDB) {
35202 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35203 if (!rq->cmd)
35204 return -ENOMEM;
35205- }
35206+ cmdptr = rq->cmd;
35207+ } else
35208+ cmdptr = tmpcmd;
35209
35210- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35211+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35212 hdr->request_len))
35213 return -EFAULT;
35214
35215+ if (cmdptr != rq->cmd)
35216+ memcpy(rq->cmd, cmdptr, hdr->request_len);
35217+
35218 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35219 if (blk_verify_command(rq->cmd, has_write_perm))
35220 return -EPERM;
35221diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35222index fbd5a67..f24fd95 100644
35223--- a/block/compat_ioctl.c
35224+++ b/block/compat_ioctl.c
35225@@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
35226 cgc = compat_alloc_user_space(sizeof(*cgc));
35227 cgc32 = compat_ptr(arg);
35228
35229- if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
35230+ if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
35231 get_user(data, &cgc32->buffer) ||
35232 put_user(compat_ptr(data), &cgc->buffer) ||
35233 copy_in_user(&cgc->buflen, &cgc32->buflen,
35234@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35235 err |= __get_user(f->spec1, &uf->spec1);
35236 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35237 err |= __get_user(name, &uf->name);
35238- f->name = compat_ptr(name);
35239+ f->name = (void __force_kernel *)compat_ptr(name);
35240 if (err) {
35241 err = -EFAULT;
35242 goto out;
35243diff --git a/block/genhd.c b/block/genhd.c
35244index 791f419..89f21c4 100644
35245--- a/block/genhd.c
35246+++ b/block/genhd.c
35247@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35248
35249 /*
35250 * Register device numbers dev..(dev+range-1)
35251- * range must be nonzero
35252+ * Noop if @range is zero.
35253 * The hash chain is sorted on range, so that subranges can override.
35254 */
35255 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35256 struct kobject *(*probe)(dev_t, int *, void *),
35257 int (*lock)(dev_t, void *), void *data)
35258 {
35259- kobj_map(bdev_map, devt, range, module, probe, lock, data);
35260+ if (range)
35261+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
35262 }
35263
35264 EXPORT_SYMBOL(blk_register_region);
35265
35266+/* undo blk_register_region(), noop if @range is zero */
35267 void blk_unregister_region(dev_t devt, unsigned long range)
35268 {
35269- kobj_unmap(bdev_map, devt, range);
35270+ if (range)
35271+ kobj_unmap(bdev_map, devt, range);
35272 }
35273
35274 EXPORT_SYMBOL(blk_unregister_region);
35275diff --git a/block/partitions/efi.c b/block/partitions/efi.c
35276index dc51f46..d5446a8 100644
35277--- a/block/partitions/efi.c
35278+++ b/block/partitions/efi.c
35279@@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
35280 if (!gpt)
35281 return NULL;
35282
35283+ if (!le32_to_cpu(gpt->num_partition_entries))
35284+ return NULL;
35285+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
35286+ if (!pte)
35287+ return NULL;
35288+
35289 count = le32_to_cpu(gpt->num_partition_entries) *
35290 le32_to_cpu(gpt->sizeof_partition_entry);
35291- if (!count)
35292- return NULL;
35293- pte = kmalloc(count, GFP_KERNEL);
35294- if (!pte)
35295- return NULL;
35296-
35297 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
35298 (u8 *) pte, count) < count) {
35299 kfree(pte);
35300diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
35301index 625e3e4..b5339f9 100644
35302--- a/block/scsi_ioctl.c
35303+++ b/block/scsi_ioctl.c
35304@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
35305 return put_user(0, p);
35306 }
35307
35308-static int sg_get_timeout(struct request_queue *q)
35309+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
35310 {
35311 return jiffies_to_clock_t(q->sg_timeout);
35312 }
35313@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
35314 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
35315 struct sg_io_hdr *hdr, fmode_t mode)
35316 {
35317- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
35318+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35319+ unsigned char *cmdptr;
35320+
35321+ if (rq->cmd != rq->__cmd)
35322+ cmdptr = rq->cmd;
35323+ else
35324+ cmdptr = tmpcmd;
35325+
35326+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
35327 return -EFAULT;
35328+
35329+ if (cmdptr != rq->cmd)
35330+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
35331+
35332 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
35333 return -EPERM;
35334
35335@@ -415,6 +427,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35336 int err;
35337 unsigned int in_len, out_len, bytes, opcode, cmdlen;
35338 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
35339+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35340+ unsigned char *cmdptr;
35341
35342 if (!sic)
35343 return -EINVAL;
35344@@ -448,9 +462,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35345 */
35346 err = -EFAULT;
35347 rq->cmd_len = cmdlen;
35348- if (copy_from_user(rq->cmd, sic->data, cmdlen))
35349+
35350+ if (rq->cmd != rq->__cmd)
35351+ cmdptr = rq->cmd;
35352+ else
35353+ cmdptr = tmpcmd;
35354+
35355+ if (copy_from_user(cmdptr, sic->data, cmdlen))
35356 goto error;
35357
35358+ if (rq->cmd != cmdptr)
35359+ memcpy(rq->cmd, cmdptr, cmdlen);
35360+
35361 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
35362 goto error;
35363
35364diff --git a/crypto/cryptd.c b/crypto/cryptd.c
35365index 7bdd61b..afec999 100644
35366--- a/crypto/cryptd.c
35367+++ b/crypto/cryptd.c
35368@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
35369
35370 struct cryptd_blkcipher_request_ctx {
35371 crypto_completion_t complete;
35372-};
35373+} __no_const;
35374
35375 struct cryptd_hash_ctx {
35376 struct crypto_shash *child;
35377@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
35378
35379 struct cryptd_aead_request_ctx {
35380 crypto_completion_t complete;
35381-};
35382+} __no_const;
35383
35384 static void cryptd_queue_worker(struct work_struct *work);
35385
35386diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
35387index f8c920c..ab2cb5a 100644
35388--- a/crypto/pcrypt.c
35389+++ b/crypto/pcrypt.c
35390@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
35391 int ret;
35392
35393 pinst->kobj.kset = pcrypt_kset;
35394- ret = kobject_add(&pinst->kobj, NULL, name);
35395+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
35396 if (!ret)
35397 kobject_uevent(&pinst->kobj, KOBJ_ADD);
35398
35399diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
35400index 15dddc1..b61cf0c 100644
35401--- a/drivers/acpi/acpica/hwxfsleep.c
35402+++ b/drivers/acpi/acpica/hwxfsleep.c
35403@@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
35404 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
35405
35406 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
35407- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35408- acpi_hw_extended_sleep},
35409- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35410- acpi_hw_extended_wake_prep},
35411- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
35412+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35413+ .extended_function = acpi_hw_extended_sleep},
35414+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35415+ .extended_function = acpi_hw_extended_wake_prep},
35416+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
35417+ .extended_function = acpi_hw_extended_wake}
35418 };
35419
35420 /*
35421diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
35422index 21ba34a..cb05966 100644
35423--- a/drivers/acpi/apei/apei-internal.h
35424+++ b/drivers/acpi/apei/apei-internal.h
35425@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
35426 struct apei_exec_ins_type {
35427 u32 flags;
35428 apei_exec_ins_func_t run;
35429-};
35430+} __do_const;
35431
35432 struct apei_exec_context {
35433 u32 ip;
35434diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
35435index a30bc31..b91c4d5 100644
35436--- a/drivers/acpi/apei/ghes.c
35437+++ b/drivers/acpi/apei/ghes.c
35438@@ -498,7 +498,7 @@ static void __ghes_print_estatus(const char *pfx,
35439 const struct acpi_hest_generic *generic,
35440 const struct acpi_generic_status *estatus)
35441 {
35442- static atomic_t seqno;
35443+ static atomic_unchecked_t seqno;
35444 unsigned int curr_seqno;
35445 char pfx_seq[64];
35446
35447@@ -509,7 +509,7 @@ static void __ghes_print_estatus(const char *pfx,
35448 else
35449 pfx = KERN_ERR;
35450 }
35451- curr_seqno = atomic_inc_return(&seqno);
35452+ curr_seqno = atomic_inc_return_unchecked(&seqno);
35453 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
35454 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
35455 pfx_seq, generic->header.source_id);
35456diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
35457index a83e3c6..c3d617f 100644
35458--- a/drivers/acpi/bgrt.c
35459+++ b/drivers/acpi/bgrt.c
35460@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
35461 if (!bgrt_image)
35462 return -ENODEV;
35463
35464- bin_attr_image.private = bgrt_image;
35465- bin_attr_image.size = bgrt_image_size;
35466+ pax_open_kernel();
35467+ *(void **)&bin_attr_image.private = bgrt_image;
35468+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
35469+ pax_close_kernel();
35470
35471 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
35472 if (!bgrt_kobj)
35473diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
35474index 078c4f7..410e272 100644
35475--- a/drivers/acpi/blacklist.c
35476+++ b/drivers/acpi/blacklist.c
35477@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
35478 u32 is_critical_error;
35479 };
35480
35481-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
35482+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
35483
35484 /*
35485 * POLICY: If *anything* doesn't work, put it on the blacklist.
35486@@ -164,7 +164,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
35487 return 0;
35488 }
35489
35490-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
35491+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
35492 {
35493 .callback = dmi_disable_osi_vista,
35494 .ident = "Fujitsu Siemens",
35495diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
35496index 12b62f2..dc2aac8 100644
35497--- a/drivers/acpi/custom_method.c
35498+++ b/drivers/acpi/custom_method.c
35499@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
35500 struct acpi_table_header table;
35501 acpi_status status;
35502
35503+#ifdef CONFIG_GRKERNSEC_KMEM
35504+ return -EPERM;
35505+#endif
35506+
35507 if (!(*ppos)) {
35508 /* parse the table header to get the table length */
35509 if (count <= sizeof(struct acpi_table_header))
35510diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
35511index 644516d..643937e 100644
35512--- a/drivers/acpi/processor_idle.c
35513+++ b/drivers/acpi/processor_idle.c
35514@@ -963,7 +963,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
35515 {
35516 int i, count = CPUIDLE_DRIVER_STATE_START;
35517 struct acpi_processor_cx *cx;
35518- struct cpuidle_state *state;
35519+ cpuidle_state_no_const *state;
35520 struct cpuidle_driver *drv = &acpi_idle_driver;
35521
35522 if (!pr->flags.power_setup_done)
35523diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
35524index 6dbc3ca..b8b59a0 100644
35525--- a/drivers/acpi/sysfs.c
35526+++ b/drivers/acpi/sysfs.c
35527@@ -425,11 +425,11 @@ static u32 num_counters;
35528 static struct attribute **all_attrs;
35529 static u32 acpi_gpe_count;
35530
35531-static struct attribute_group interrupt_stats_attr_group = {
35532+static attribute_group_no_const interrupt_stats_attr_group = {
35533 .name = "interrupts",
35534 };
35535
35536-static struct kobj_attribute *counter_attrs;
35537+static kobj_attribute_no_const *counter_attrs;
35538
35539 static void delete_gpe_attr_array(void)
35540 {
35541diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
35542index c482f8c..c832240 100644
35543--- a/drivers/ata/libahci.c
35544+++ b/drivers/ata/libahci.c
35545@@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
35546 }
35547 EXPORT_SYMBOL_GPL(ahci_kick_engine);
35548
35549-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
35550+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
35551 struct ata_taskfile *tf, int is_cmd, u16 flags,
35552 unsigned long timeout_msec)
35553 {
35554diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
35555index 1a3dbd1..dfc6e5c 100644
35556--- a/drivers/ata/libata-core.c
35557+++ b/drivers/ata/libata-core.c
35558@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
35559 static void ata_dev_xfermask(struct ata_device *dev);
35560 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
35561
35562-atomic_t ata_print_id = ATOMIC_INIT(0);
35563+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
35564
35565 struct ata_force_param {
35566 const char *name;
35567@@ -4850,7 +4850,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
35568 struct ata_port *ap;
35569 unsigned int tag;
35570
35571- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35572+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35573 ap = qc->ap;
35574
35575 qc->flags = 0;
35576@@ -4866,7 +4866,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
35577 struct ata_port *ap;
35578 struct ata_link *link;
35579
35580- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35581+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35582 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
35583 ap = qc->ap;
35584 link = qc->dev->link;
35585@@ -5985,6 +5985,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
35586 return;
35587
35588 spin_lock(&lock);
35589+ pax_open_kernel();
35590
35591 for (cur = ops->inherits; cur; cur = cur->inherits) {
35592 void **inherit = (void **)cur;
35593@@ -5998,8 +5999,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
35594 if (IS_ERR(*pp))
35595 *pp = NULL;
35596
35597- ops->inherits = NULL;
35598+ *(struct ata_port_operations **)&ops->inherits = NULL;
35599
35600+ pax_close_kernel();
35601 spin_unlock(&lock);
35602 }
35603
35604@@ -6192,7 +6194,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
35605
35606 /* give ports names and add SCSI hosts */
35607 for (i = 0; i < host->n_ports; i++) {
35608- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
35609+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
35610 host->ports[i]->local_port_no = i + 1;
35611 }
35612
35613diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
35614index ef8567d..8bdbd03 100644
35615--- a/drivers/ata/libata-scsi.c
35616+++ b/drivers/ata/libata-scsi.c
35617@@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
35618
35619 if (rc)
35620 return rc;
35621- ap->print_id = atomic_inc_return(&ata_print_id);
35622+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
35623 return 0;
35624 }
35625 EXPORT_SYMBOL_GPL(ata_sas_port_init);
35626diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
35627index 45b5ab3..98446b8 100644
35628--- a/drivers/ata/libata.h
35629+++ b/drivers/ata/libata.h
35630@@ -53,7 +53,7 @@ enum {
35631 ATA_DNXFER_QUIET = (1 << 31),
35632 };
35633
35634-extern atomic_t ata_print_id;
35635+extern atomic_unchecked_t ata_print_id;
35636 extern int atapi_passthru16;
35637 extern int libata_fua;
35638 extern int libata_noacpi;
35639diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
35640index 73492dd..ca2bff5 100644
35641--- a/drivers/ata/pata_arasan_cf.c
35642+++ b/drivers/ata/pata_arasan_cf.c
35643@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
35644 /* Handle platform specific quirks */
35645 if (quirk) {
35646 if (quirk & CF_BROKEN_PIO) {
35647- ap->ops->set_piomode = NULL;
35648+ pax_open_kernel();
35649+ *(void **)&ap->ops->set_piomode = NULL;
35650+ pax_close_kernel();
35651 ap->pio_mask = 0;
35652 }
35653 if (quirk & CF_BROKEN_MWDMA)
35654diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
35655index f9b983a..887b9d8 100644
35656--- a/drivers/atm/adummy.c
35657+++ b/drivers/atm/adummy.c
35658@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
35659 vcc->pop(vcc, skb);
35660 else
35661 dev_kfree_skb_any(skb);
35662- atomic_inc(&vcc->stats->tx);
35663+ atomic_inc_unchecked(&vcc->stats->tx);
35664
35665 return 0;
35666 }
35667diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
35668index 62a7607..cc4be104 100644
35669--- a/drivers/atm/ambassador.c
35670+++ b/drivers/atm/ambassador.c
35671@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
35672 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
35673
35674 // VC layer stats
35675- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35676+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35677
35678 // free the descriptor
35679 kfree (tx_descr);
35680@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
35681 dump_skb ("<<<", vc, skb);
35682
35683 // VC layer stats
35684- atomic_inc(&atm_vcc->stats->rx);
35685+ atomic_inc_unchecked(&atm_vcc->stats->rx);
35686 __net_timestamp(skb);
35687 // end of our responsibility
35688 atm_vcc->push (atm_vcc, skb);
35689@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
35690 } else {
35691 PRINTK (KERN_INFO, "dropped over-size frame");
35692 // should we count this?
35693- atomic_inc(&atm_vcc->stats->rx_drop);
35694+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35695 }
35696
35697 } else {
35698@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
35699 }
35700
35701 if (check_area (skb->data, skb->len)) {
35702- atomic_inc(&atm_vcc->stats->tx_err);
35703+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
35704 return -ENOMEM; // ?
35705 }
35706
35707diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
35708index 0e3f8f9..765a7a5 100644
35709--- a/drivers/atm/atmtcp.c
35710+++ b/drivers/atm/atmtcp.c
35711@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35712 if (vcc->pop) vcc->pop(vcc,skb);
35713 else dev_kfree_skb(skb);
35714 if (dev_data) return 0;
35715- atomic_inc(&vcc->stats->tx_err);
35716+ atomic_inc_unchecked(&vcc->stats->tx_err);
35717 return -ENOLINK;
35718 }
35719 size = skb->len+sizeof(struct atmtcp_hdr);
35720@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35721 if (!new_skb) {
35722 if (vcc->pop) vcc->pop(vcc,skb);
35723 else dev_kfree_skb(skb);
35724- atomic_inc(&vcc->stats->tx_err);
35725+ atomic_inc_unchecked(&vcc->stats->tx_err);
35726 return -ENOBUFS;
35727 }
35728 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
35729@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35730 if (vcc->pop) vcc->pop(vcc,skb);
35731 else dev_kfree_skb(skb);
35732 out_vcc->push(out_vcc,new_skb);
35733- atomic_inc(&vcc->stats->tx);
35734- atomic_inc(&out_vcc->stats->rx);
35735+ atomic_inc_unchecked(&vcc->stats->tx);
35736+ atomic_inc_unchecked(&out_vcc->stats->rx);
35737 return 0;
35738 }
35739
35740@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
35741 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
35742 read_unlock(&vcc_sklist_lock);
35743 if (!out_vcc) {
35744- atomic_inc(&vcc->stats->tx_err);
35745+ atomic_inc_unchecked(&vcc->stats->tx_err);
35746 goto done;
35747 }
35748 skb_pull(skb,sizeof(struct atmtcp_hdr));
35749@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
35750 __net_timestamp(new_skb);
35751 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
35752 out_vcc->push(out_vcc,new_skb);
35753- atomic_inc(&vcc->stats->tx);
35754- atomic_inc(&out_vcc->stats->rx);
35755+ atomic_inc_unchecked(&vcc->stats->tx);
35756+ atomic_inc_unchecked(&out_vcc->stats->rx);
35757 done:
35758 if (vcc->pop) vcc->pop(vcc,skb);
35759 else dev_kfree_skb(skb);
35760diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
35761index b1955ba..b179940 100644
35762--- a/drivers/atm/eni.c
35763+++ b/drivers/atm/eni.c
35764@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
35765 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
35766 vcc->dev->number);
35767 length = 0;
35768- atomic_inc(&vcc->stats->rx_err);
35769+ atomic_inc_unchecked(&vcc->stats->rx_err);
35770 }
35771 else {
35772 length = ATM_CELL_SIZE-1; /* no HEC */
35773@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
35774 size);
35775 }
35776 eff = length = 0;
35777- atomic_inc(&vcc->stats->rx_err);
35778+ atomic_inc_unchecked(&vcc->stats->rx_err);
35779 }
35780 else {
35781 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
35782@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
35783 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
35784 vcc->dev->number,vcc->vci,length,size << 2,descr);
35785 length = eff = 0;
35786- atomic_inc(&vcc->stats->rx_err);
35787+ atomic_inc_unchecked(&vcc->stats->rx_err);
35788 }
35789 }
35790 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
35791@@ -767,7 +767,7 @@ rx_dequeued++;
35792 vcc->push(vcc,skb);
35793 pushed++;
35794 }
35795- atomic_inc(&vcc->stats->rx);
35796+ atomic_inc_unchecked(&vcc->stats->rx);
35797 }
35798 wake_up(&eni_dev->rx_wait);
35799 }
35800@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
35801 PCI_DMA_TODEVICE);
35802 if (vcc->pop) vcc->pop(vcc,skb);
35803 else dev_kfree_skb_irq(skb);
35804- atomic_inc(&vcc->stats->tx);
35805+ atomic_inc_unchecked(&vcc->stats->tx);
35806 wake_up(&eni_dev->tx_wait);
35807 dma_complete++;
35808 }
35809diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
35810index b41c948..a002b17 100644
35811--- a/drivers/atm/firestream.c
35812+++ b/drivers/atm/firestream.c
35813@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
35814 }
35815 }
35816
35817- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35818+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35819
35820 fs_dprintk (FS_DEBUG_TXMEM, "i");
35821 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
35822@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
35823 #endif
35824 skb_put (skb, qe->p1 & 0xffff);
35825 ATM_SKB(skb)->vcc = atm_vcc;
35826- atomic_inc(&atm_vcc->stats->rx);
35827+ atomic_inc_unchecked(&atm_vcc->stats->rx);
35828 __net_timestamp(skb);
35829 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
35830 atm_vcc->push (atm_vcc, skb);
35831@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
35832 kfree (pe);
35833 }
35834 if (atm_vcc)
35835- atomic_inc(&atm_vcc->stats->rx_drop);
35836+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35837 break;
35838 case 0x1f: /* Reassembly abort: no buffers. */
35839 /* Silently increment error counter. */
35840 if (atm_vcc)
35841- atomic_inc(&atm_vcc->stats->rx_drop);
35842+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35843 break;
35844 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
35845 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
35846diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
35847index 204814e..cede831 100644
35848--- a/drivers/atm/fore200e.c
35849+++ b/drivers/atm/fore200e.c
35850@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
35851 #endif
35852 /* check error condition */
35853 if (*entry->status & STATUS_ERROR)
35854- atomic_inc(&vcc->stats->tx_err);
35855+ atomic_inc_unchecked(&vcc->stats->tx_err);
35856 else
35857- atomic_inc(&vcc->stats->tx);
35858+ atomic_inc_unchecked(&vcc->stats->tx);
35859 }
35860 }
35861
35862@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35863 if (skb == NULL) {
35864 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
35865
35866- atomic_inc(&vcc->stats->rx_drop);
35867+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35868 return -ENOMEM;
35869 }
35870
35871@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35872
35873 dev_kfree_skb_any(skb);
35874
35875- atomic_inc(&vcc->stats->rx_drop);
35876+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35877 return -ENOMEM;
35878 }
35879
35880 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35881
35882 vcc->push(vcc, skb);
35883- atomic_inc(&vcc->stats->rx);
35884+ atomic_inc_unchecked(&vcc->stats->rx);
35885
35886 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35887
35888@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
35889 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
35890 fore200e->atm_dev->number,
35891 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
35892- atomic_inc(&vcc->stats->rx_err);
35893+ atomic_inc_unchecked(&vcc->stats->rx_err);
35894 }
35895 }
35896
35897@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
35898 goto retry_here;
35899 }
35900
35901- atomic_inc(&vcc->stats->tx_err);
35902+ atomic_inc_unchecked(&vcc->stats->tx_err);
35903
35904 fore200e->tx_sat++;
35905 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
35906diff --git a/drivers/atm/he.c b/drivers/atm/he.c
35907index 8557adc..3fb5d55 100644
35908--- a/drivers/atm/he.c
35909+++ b/drivers/atm/he.c
35910@@ -1691,7 +1691,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35911
35912 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
35913 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
35914- atomic_inc(&vcc->stats->rx_drop);
35915+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35916 goto return_host_buffers;
35917 }
35918
35919@@ -1718,7 +1718,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35920 RBRQ_LEN_ERR(he_dev->rbrq_head)
35921 ? "LEN_ERR" : "",
35922 vcc->vpi, vcc->vci);
35923- atomic_inc(&vcc->stats->rx_err);
35924+ atomic_inc_unchecked(&vcc->stats->rx_err);
35925 goto return_host_buffers;
35926 }
35927
35928@@ -1770,7 +1770,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35929 vcc->push(vcc, skb);
35930 spin_lock(&he_dev->global_lock);
35931
35932- atomic_inc(&vcc->stats->rx);
35933+ atomic_inc_unchecked(&vcc->stats->rx);
35934
35935 return_host_buffers:
35936 ++pdus_assembled;
35937@@ -2096,7 +2096,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
35938 tpd->vcc->pop(tpd->vcc, tpd->skb);
35939 else
35940 dev_kfree_skb_any(tpd->skb);
35941- atomic_inc(&tpd->vcc->stats->tx_err);
35942+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
35943 }
35944 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
35945 return;
35946@@ -2508,7 +2508,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35947 vcc->pop(vcc, skb);
35948 else
35949 dev_kfree_skb_any(skb);
35950- atomic_inc(&vcc->stats->tx_err);
35951+ atomic_inc_unchecked(&vcc->stats->tx_err);
35952 return -EINVAL;
35953 }
35954
35955@@ -2519,7 +2519,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35956 vcc->pop(vcc, skb);
35957 else
35958 dev_kfree_skb_any(skb);
35959- atomic_inc(&vcc->stats->tx_err);
35960+ atomic_inc_unchecked(&vcc->stats->tx_err);
35961 return -EINVAL;
35962 }
35963 #endif
35964@@ -2531,7 +2531,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35965 vcc->pop(vcc, skb);
35966 else
35967 dev_kfree_skb_any(skb);
35968- atomic_inc(&vcc->stats->tx_err);
35969+ atomic_inc_unchecked(&vcc->stats->tx_err);
35970 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35971 return -ENOMEM;
35972 }
35973@@ -2573,7 +2573,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35974 vcc->pop(vcc, skb);
35975 else
35976 dev_kfree_skb_any(skb);
35977- atomic_inc(&vcc->stats->tx_err);
35978+ atomic_inc_unchecked(&vcc->stats->tx_err);
35979 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35980 return -ENOMEM;
35981 }
35982@@ -2604,7 +2604,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35983 __enqueue_tpd(he_dev, tpd, cid);
35984 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35985
35986- atomic_inc(&vcc->stats->tx);
35987+ atomic_inc_unchecked(&vcc->stats->tx);
35988
35989 return 0;
35990 }
35991diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
35992index 1dc0519..1aadaf7 100644
35993--- a/drivers/atm/horizon.c
35994+++ b/drivers/atm/horizon.c
35995@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
35996 {
35997 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
35998 // VC layer stats
35999- atomic_inc(&vcc->stats->rx);
36000+ atomic_inc_unchecked(&vcc->stats->rx);
36001 __net_timestamp(skb);
36002 // end of our responsibility
36003 vcc->push (vcc, skb);
36004@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36005 dev->tx_iovec = NULL;
36006
36007 // VC layer stats
36008- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36009+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36010
36011 // free the skb
36012 hrz_kfree_skb (skb);
36013diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36014index 1bdf104..9dc44b1 100644
36015--- a/drivers/atm/idt77252.c
36016+++ b/drivers/atm/idt77252.c
36017@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36018 else
36019 dev_kfree_skb(skb);
36020
36021- atomic_inc(&vcc->stats->tx);
36022+ atomic_inc_unchecked(&vcc->stats->tx);
36023 }
36024
36025 atomic_dec(&scq->used);
36026@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36027 if ((sb = dev_alloc_skb(64)) == NULL) {
36028 printk("%s: Can't allocate buffers for aal0.\n",
36029 card->name);
36030- atomic_add(i, &vcc->stats->rx_drop);
36031+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36032 break;
36033 }
36034 if (!atm_charge(vcc, sb->truesize)) {
36035 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36036 card->name);
36037- atomic_add(i - 1, &vcc->stats->rx_drop);
36038+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36039 dev_kfree_skb(sb);
36040 break;
36041 }
36042@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36043 ATM_SKB(sb)->vcc = vcc;
36044 __net_timestamp(sb);
36045 vcc->push(vcc, sb);
36046- atomic_inc(&vcc->stats->rx);
36047+ atomic_inc_unchecked(&vcc->stats->rx);
36048
36049 cell += ATM_CELL_PAYLOAD;
36050 }
36051@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36052 "(CDC: %08x)\n",
36053 card->name, len, rpp->len, readl(SAR_REG_CDC));
36054 recycle_rx_pool_skb(card, rpp);
36055- atomic_inc(&vcc->stats->rx_err);
36056+ atomic_inc_unchecked(&vcc->stats->rx_err);
36057 return;
36058 }
36059 if (stat & SAR_RSQE_CRC) {
36060 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36061 recycle_rx_pool_skb(card, rpp);
36062- atomic_inc(&vcc->stats->rx_err);
36063+ atomic_inc_unchecked(&vcc->stats->rx_err);
36064 return;
36065 }
36066 if (skb_queue_len(&rpp->queue) > 1) {
36067@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36068 RXPRINTK("%s: Can't alloc RX skb.\n",
36069 card->name);
36070 recycle_rx_pool_skb(card, rpp);
36071- atomic_inc(&vcc->stats->rx_err);
36072+ atomic_inc_unchecked(&vcc->stats->rx_err);
36073 return;
36074 }
36075 if (!atm_charge(vcc, skb->truesize)) {
36076@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36077 __net_timestamp(skb);
36078
36079 vcc->push(vcc, skb);
36080- atomic_inc(&vcc->stats->rx);
36081+ atomic_inc_unchecked(&vcc->stats->rx);
36082
36083 return;
36084 }
36085@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36086 __net_timestamp(skb);
36087
36088 vcc->push(vcc, skb);
36089- atomic_inc(&vcc->stats->rx);
36090+ atomic_inc_unchecked(&vcc->stats->rx);
36091
36092 if (skb->truesize > SAR_FB_SIZE_3)
36093 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36094@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36095 if (vcc->qos.aal != ATM_AAL0) {
36096 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36097 card->name, vpi, vci);
36098- atomic_inc(&vcc->stats->rx_drop);
36099+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36100 goto drop;
36101 }
36102
36103 if ((sb = dev_alloc_skb(64)) == NULL) {
36104 printk("%s: Can't allocate buffers for AAL0.\n",
36105 card->name);
36106- atomic_inc(&vcc->stats->rx_err);
36107+ atomic_inc_unchecked(&vcc->stats->rx_err);
36108 goto drop;
36109 }
36110
36111@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36112 ATM_SKB(sb)->vcc = vcc;
36113 __net_timestamp(sb);
36114 vcc->push(vcc, sb);
36115- atomic_inc(&vcc->stats->rx);
36116+ atomic_inc_unchecked(&vcc->stats->rx);
36117
36118 drop:
36119 skb_pull(queue, 64);
36120@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36121
36122 if (vc == NULL) {
36123 printk("%s: NULL connection in send().\n", card->name);
36124- atomic_inc(&vcc->stats->tx_err);
36125+ atomic_inc_unchecked(&vcc->stats->tx_err);
36126 dev_kfree_skb(skb);
36127 return -EINVAL;
36128 }
36129 if (!test_bit(VCF_TX, &vc->flags)) {
36130 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36131- atomic_inc(&vcc->stats->tx_err);
36132+ atomic_inc_unchecked(&vcc->stats->tx_err);
36133 dev_kfree_skb(skb);
36134 return -EINVAL;
36135 }
36136@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36137 break;
36138 default:
36139 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36140- atomic_inc(&vcc->stats->tx_err);
36141+ atomic_inc_unchecked(&vcc->stats->tx_err);
36142 dev_kfree_skb(skb);
36143 return -EINVAL;
36144 }
36145
36146 if (skb_shinfo(skb)->nr_frags != 0) {
36147 printk("%s: No scatter-gather yet.\n", card->name);
36148- atomic_inc(&vcc->stats->tx_err);
36149+ atomic_inc_unchecked(&vcc->stats->tx_err);
36150 dev_kfree_skb(skb);
36151 return -EINVAL;
36152 }
36153@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36154
36155 err = queue_skb(card, vc, skb, oam);
36156 if (err) {
36157- atomic_inc(&vcc->stats->tx_err);
36158+ atomic_inc_unchecked(&vcc->stats->tx_err);
36159 dev_kfree_skb(skb);
36160 return err;
36161 }
36162@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36163 skb = dev_alloc_skb(64);
36164 if (!skb) {
36165 printk("%s: Out of memory in send_oam().\n", card->name);
36166- atomic_inc(&vcc->stats->tx_err);
36167+ atomic_inc_unchecked(&vcc->stats->tx_err);
36168 return -ENOMEM;
36169 }
36170 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36171diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36172index 4217f29..88f547a 100644
36173--- a/drivers/atm/iphase.c
36174+++ b/drivers/atm/iphase.c
36175@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36176 status = (u_short) (buf_desc_ptr->desc_mode);
36177 if (status & (RX_CER | RX_PTE | RX_OFL))
36178 {
36179- atomic_inc(&vcc->stats->rx_err);
36180+ atomic_inc_unchecked(&vcc->stats->rx_err);
36181 IF_ERR(printk("IA: bad packet, dropping it");)
36182 if (status & RX_CER) {
36183 IF_ERR(printk(" cause: packet CRC error\n");)
36184@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36185 len = dma_addr - buf_addr;
36186 if (len > iadev->rx_buf_sz) {
36187 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36188- atomic_inc(&vcc->stats->rx_err);
36189+ atomic_inc_unchecked(&vcc->stats->rx_err);
36190 goto out_free_desc;
36191 }
36192
36193@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36194 ia_vcc = INPH_IA_VCC(vcc);
36195 if (ia_vcc == NULL)
36196 {
36197- atomic_inc(&vcc->stats->rx_err);
36198+ atomic_inc_unchecked(&vcc->stats->rx_err);
36199 atm_return(vcc, skb->truesize);
36200 dev_kfree_skb_any(skb);
36201 goto INCR_DLE;
36202@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36203 if ((length > iadev->rx_buf_sz) || (length >
36204 (skb->len - sizeof(struct cpcs_trailer))))
36205 {
36206- atomic_inc(&vcc->stats->rx_err);
36207+ atomic_inc_unchecked(&vcc->stats->rx_err);
36208 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36209 length, skb->len);)
36210 atm_return(vcc, skb->truesize);
36211@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36212
36213 IF_RX(printk("rx_dle_intr: skb push");)
36214 vcc->push(vcc,skb);
36215- atomic_inc(&vcc->stats->rx);
36216+ atomic_inc_unchecked(&vcc->stats->rx);
36217 iadev->rx_pkt_cnt++;
36218 }
36219 INCR_DLE:
36220@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36221 {
36222 struct k_sonet_stats *stats;
36223 stats = &PRIV(_ia_dev[board])->sonet_stats;
36224- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36225- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36226- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36227- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36228- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36229- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36230- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36231- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36232- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36233+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36234+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36235+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36236+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36237+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36238+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36239+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36240+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36241+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36242 }
36243 ia_cmds.status = 0;
36244 break;
36245@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36246 if ((desc == 0) || (desc > iadev->num_tx_desc))
36247 {
36248 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36249- atomic_inc(&vcc->stats->tx);
36250+ atomic_inc_unchecked(&vcc->stats->tx);
36251 if (vcc->pop)
36252 vcc->pop(vcc, skb);
36253 else
36254@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36255 ATM_DESC(skb) = vcc->vci;
36256 skb_queue_tail(&iadev->tx_dma_q, skb);
36257
36258- atomic_inc(&vcc->stats->tx);
36259+ atomic_inc_unchecked(&vcc->stats->tx);
36260 iadev->tx_pkt_cnt++;
36261 /* Increment transaction counter */
36262 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36263
36264 #if 0
36265 /* add flow control logic */
36266- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36267+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
36268 if (iavcc->vc_desc_cnt > 10) {
36269 vcc->tx_quota = vcc->tx_quota * 3 / 4;
36270 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
36271diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
36272index fa7d701..1e404c7 100644
36273--- a/drivers/atm/lanai.c
36274+++ b/drivers/atm/lanai.c
36275@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
36276 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
36277 lanai_endtx(lanai, lvcc);
36278 lanai_free_skb(lvcc->tx.atmvcc, skb);
36279- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
36280+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
36281 }
36282
36283 /* Try to fill the buffer - don't call unless there is backlog */
36284@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
36285 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
36286 __net_timestamp(skb);
36287 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
36288- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
36289+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
36290 out:
36291 lvcc->rx.buf.ptr = end;
36292 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
36293@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36294 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
36295 "vcc %d\n", lanai->number, (unsigned int) s, vci);
36296 lanai->stats.service_rxnotaal5++;
36297- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36298+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36299 return 0;
36300 }
36301 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
36302@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36303 int bytes;
36304 read_unlock(&vcc_sklist_lock);
36305 DPRINTK("got trashed rx pdu on vci %d\n", vci);
36306- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36307+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36308 lvcc->stats.x.aal5.service_trash++;
36309 bytes = (SERVICE_GET_END(s) * 16) -
36310 (((unsigned long) lvcc->rx.buf.ptr) -
36311@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36312 }
36313 if (s & SERVICE_STREAM) {
36314 read_unlock(&vcc_sklist_lock);
36315- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36316+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36317 lvcc->stats.x.aal5.service_stream++;
36318 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
36319 "PDU on VCI %d!\n", lanai->number, vci);
36320@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36321 return 0;
36322 }
36323 DPRINTK("got rx crc error on vci %d\n", vci);
36324- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36325+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36326 lvcc->stats.x.aal5.service_rxcrc++;
36327 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
36328 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
36329diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
36330index 5aca5f4..ce3a6b0 100644
36331--- a/drivers/atm/nicstar.c
36332+++ b/drivers/atm/nicstar.c
36333@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36334 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
36335 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
36336 card->index);
36337- atomic_inc(&vcc->stats->tx_err);
36338+ atomic_inc_unchecked(&vcc->stats->tx_err);
36339 dev_kfree_skb_any(skb);
36340 return -EINVAL;
36341 }
36342@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36343 if (!vc->tx) {
36344 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
36345 card->index);
36346- atomic_inc(&vcc->stats->tx_err);
36347+ atomic_inc_unchecked(&vcc->stats->tx_err);
36348 dev_kfree_skb_any(skb);
36349 return -EINVAL;
36350 }
36351@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36352 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
36353 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
36354 card->index);
36355- atomic_inc(&vcc->stats->tx_err);
36356+ atomic_inc_unchecked(&vcc->stats->tx_err);
36357 dev_kfree_skb_any(skb);
36358 return -EINVAL;
36359 }
36360
36361 if (skb_shinfo(skb)->nr_frags != 0) {
36362 printk("nicstar%d: No scatter-gather yet.\n", card->index);
36363- atomic_inc(&vcc->stats->tx_err);
36364+ atomic_inc_unchecked(&vcc->stats->tx_err);
36365 dev_kfree_skb_any(skb);
36366 return -EINVAL;
36367 }
36368@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36369 }
36370
36371 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
36372- atomic_inc(&vcc->stats->tx_err);
36373+ atomic_inc_unchecked(&vcc->stats->tx_err);
36374 dev_kfree_skb_any(skb);
36375 return -EIO;
36376 }
36377- atomic_inc(&vcc->stats->tx);
36378+ atomic_inc_unchecked(&vcc->stats->tx);
36379
36380 return 0;
36381 }
36382@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36383 printk
36384 ("nicstar%d: Can't allocate buffers for aal0.\n",
36385 card->index);
36386- atomic_add(i, &vcc->stats->rx_drop);
36387+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36388 break;
36389 }
36390 if (!atm_charge(vcc, sb->truesize)) {
36391 RXPRINTK
36392 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
36393 card->index);
36394- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36395+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36396 dev_kfree_skb_any(sb);
36397 break;
36398 }
36399@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36400 ATM_SKB(sb)->vcc = vcc;
36401 __net_timestamp(sb);
36402 vcc->push(vcc, sb);
36403- atomic_inc(&vcc->stats->rx);
36404+ atomic_inc_unchecked(&vcc->stats->rx);
36405 cell += ATM_CELL_PAYLOAD;
36406 }
36407
36408@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36409 if (iovb == NULL) {
36410 printk("nicstar%d: Out of iovec buffers.\n",
36411 card->index);
36412- atomic_inc(&vcc->stats->rx_drop);
36413+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36414 recycle_rx_buf(card, skb);
36415 return;
36416 }
36417@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36418 small or large buffer itself. */
36419 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
36420 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
36421- atomic_inc(&vcc->stats->rx_err);
36422+ atomic_inc_unchecked(&vcc->stats->rx_err);
36423 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36424 NS_MAX_IOVECS);
36425 NS_PRV_IOVCNT(iovb) = 0;
36426@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36427 ("nicstar%d: Expected a small buffer, and this is not one.\n",
36428 card->index);
36429 which_list(card, skb);
36430- atomic_inc(&vcc->stats->rx_err);
36431+ atomic_inc_unchecked(&vcc->stats->rx_err);
36432 recycle_rx_buf(card, skb);
36433 vc->rx_iov = NULL;
36434 recycle_iov_buf(card, iovb);
36435@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36436 ("nicstar%d: Expected a large buffer, and this is not one.\n",
36437 card->index);
36438 which_list(card, skb);
36439- atomic_inc(&vcc->stats->rx_err);
36440+ atomic_inc_unchecked(&vcc->stats->rx_err);
36441 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36442 NS_PRV_IOVCNT(iovb));
36443 vc->rx_iov = NULL;
36444@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36445 printk(" - PDU size mismatch.\n");
36446 else
36447 printk(".\n");
36448- atomic_inc(&vcc->stats->rx_err);
36449+ atomic_inc_unchecked(&vcc->stats->rx_err);
36450 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36451 NS_PRV_IOVCNT(iovb));
36452 vc->rx_iov = NULL;
36453@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36454 /* skb points to a small buffer */
36455 if (!atm_charge(vcc, skb->truesize)) {
36456 push_rxbufs(card, skb);
36457- atomic_inc(&vcc->stats->rx_drop);
36458+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36459 } else {
36460 skb_put(skb, len);
36461 dequeue_sm_buf(card, skb);
36462@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36463 ATM_SKB(skb)->vcc = vcc;
36464 __net_timestamp(skb);
36465 vcc->push(vcc, skb);
36466- atomic_inc(&vcc->stats->rx);
36467+ atomic_inc_unchecked(&vcc->stats->rx);
36468 }
36469 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
36470 struct sk_buff *sb;
36471@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36472 if (len <= NS_SMBUFSIZE) {
36473 if (!atm_charge(vcc, sb->truesize)) {
36474 push_rxbufs(card, sb);
36475- atomic_inc(&vcc->stats->rx_drop);
36476+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36477 } else {
36478 skb_put(sb, len);
36479 dequeue_sm_buf(card, sb);
36480@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36481 ATM_SKB(sb)->vcc = vcc;
36482 __net_timestamp(sb);
36483 vcc->push(vcc, sb);
36484- atomic_inc(&vcc->stats->rx);
36485+ atomic_inc_unchecked(&vcc->stats->rx);
36486 }
36487
36488 push_rxbufs(card, skb);
36489@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36490
36491 if (!atm_charge(vcc, skb->truesize)) {
36492 push_rxbufs(card, skb);
36493- atomic_inc(&vcc->stats->rx_drop);
36494+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36495 } else {
36496 dequeue_lg_buf(card, skb);
36497 #ifdef NS_USE_DESTRUCTORS
36498@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36499 ATM_SKB(skb)->vcc = vcc;
36500 __net_timestamp(skb);
36501 vcc->push(vcc, skb);
36502- atomic_inc(&vcc->stats->rx);
36503+ atomic_inc_unchecked(&vcc->stats->rx);
36504 }
36505
36506 push_rxbufs(card, sb);
36507@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36508 printk
36509 ("nicstar%d: Out of huge buffers.\n",
36510 card->index);
36511- atomic_inc(&vcc->stats->rx_drop);
36512+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36513 recycle_iovec_rx_bufs(card,
36514 (struct iovec *)
36515 iovb->data,
36516@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36517 card->hbpool.count++;
36518 } else
36519 dev_kfree_skb_any(hb);
36520- atomic_inc(&vcc->stats->rx_drop);
36521+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36522 } else {
36523 /* Copy the small buffer to the huge buffer */
36524 sb = (struct sk_buff *)iov->iov_base;
36525@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36526 #endif /* NS_USE_DESTRUCTORS */
36527 __net_timestamp(hb);
36528 vcc->push(vcc, hb);
36529- atomic_inc(&vcc->stats->rx);
36530+ atomic_inc_unchecked(&vcc->stats->rx);
36531 }
36532 }
36533
36534diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
36535index 32784d1..4a8434a 100644
36536--- a/drivers/atm/solos-pci.c
36537+++ b/drivers/atm/solos-pci.c
36538@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
36539 }
36540 atm_charge(vcc, skb->truesize);
36541 vcc->push(vcc, skb);
36542- atomic_inc(&vcc->stats->rx);
36543+ atomic_inc_unchecked(&vcc->stats->rx);
36544 break;
36545
36546 case PKT_STATUS:
36547@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
36548 vcc = SKB_CB(oldskb)->vcc;
36549
36550 if (vcc) {
36551- atomic_inc(&vcc->stats->tx);
36552+ atomic_inc_unchecked(&vcc->stats->tx);
36553 solos_pop(vcc, oldskb);
36554 } else {
36555 dev_kfree_skb_irq(oldskb);
36556diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
36557index 0215934..ce9f5b1 100644
36558--- a/drivers/atm/suni.c
36559+++ b/drivers/atm/suni.c
36560@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
36561
36562
36563 #define ADD_LIMITED(s,v) \
36564- atomic_add((v),&stats->s); \
36565- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
36566+ atomic_add_unchecked((v),&stats->s); \
36567+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
36568
36569
36570 static void suni_hz(unsigned long from_timer)
36571diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
36572index 5120a96..e2572bd 100644
36573--- a/drivers/atm/uPD98402.c
36574+++ b/drivers/atm/uPD98402.c
36575@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
36576 struct sonet_stats tmp;
36577 int error = 0;
36578
36579- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
36580+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
36581 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
36582 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
36583 if (zero && !error) {
36584@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
36585
36586
36587 #define ADD_LIMITED(s,v) \
36588- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
36589- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
36590- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
36591+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
36592+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
36593+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
36594
36595
36596 static void stat_event(struct atm_dev *dev)
36597@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
36598 if (reason & uPD98402_INT_PFM) stat_event(dev);
36599 if (reason & uPD98402_INT_PCO) {
36600 (void) GET(PCOCR); /* clear interrupt cause */
36601- atomic_add(GET(HECCT),
36602+ atomic_add_unchecked(GET(HECCT),
36603 &PRIV(dev)->sonet_stats.uncorr_hcs);
36604 }
36605 if ((reason & uPD98402_INT_RFO) &&
36606@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
36607 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
36608 uPD98402_INT_LOS),PIMR); /* enable them */
36609 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
36610- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
36611- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
36612- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
36613+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
36614+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
36615+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
36616 return 0;
36617 }
36618
36619diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
36620index 969c3c2..9b72956 100644
36621--- a/drivers/atm/zatm.c
36622+++ b/drivers/atm/zatm.c
36623@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
36624 }
36625 if (!size) {
36626 dev_kfree_skb_irq(skb);
36627- if (vcc) atomic_inc(&vcc->stats->rx_err);
36628+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
36629 continue;
36630 }
36631 if (!atm_charge(vcc,skb->truesize)) {
36632@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
36633 skb->len = size;
36634 ATM_SKB(skb)->vcc = vcc;
36635 vcc->push(vcc,skb);
36636- atomic_inc(&vcc->stats->rx);
36637+ atomic_inc_unchecked(&vcc->stats->rx);
36638 }
36639 zout(pos & 0xffff,MTA(mbx));
36640 #if 0 /* probably a stupid idea */
36641@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
36642 skb_queue_head(&zatm_vcc->backlog,skb);
36643 break;
36644 }
36645- atomic_inc(&vcc->stats->tx);
36646+ atomic_inc_unchecked(&vcc->stats->tx);
36647 wake_up(&zatm_vcc->tx_wait);
36648 }
36649
36650diff --git a/drivers/base/bus.c b/drivers/base/bus.c
36651index 73f6c29..b0c0e13 100644
36652--- a/drivers/base/bus.c
36653+++ b/drivers/base/bus.c
36654@@ -1115,7 +1115,7 @@ int subsys_interface_register(struct subsys_interface *sif)
36655 return -EINVAL;
36656
36657 mutex_lock(&subsys->p->mutex);
36658- list_add_tail(&sif->node, &subsys->p->interfaces);
36659+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
36660 if (sif->add_dev) {
36661 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
36662 while ((dev = subsys_dev_iter_next(&iter)))
36663@@ -1140,7 +1140,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
36664 subsys = sif->subsys;
36665
36666 mutex_lock(&subsys->p->mutex);
36667- list_del_init(&sif->node);
36668+ pax_list_del_init((struct list_head *)&sif->node);
36669 if (sif->remove_dev) {
36670 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
36671 while ((dev = subsys_dev_iter_next(&iter)))
36672diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
36673index 0f38201..6c2b444 100644
36674--- a/drivers/base/devtmpfs.c
36675+++ b/drivers/base/devtmpfs.c
36676@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
36677 if (!thread)
36678 return 0;
36679
36680- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
36681+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
36682 if (err)
36683 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
36684 else
36685@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
36686 *err = sys_unshare(CLONE_NEWNS);
36687 if (*err)
36688 goto out;
36689- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
36690+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
36691 if (*err)
36692 goto out;
36693- sys_chdir("/.."); /* will traverse into overmounted root */
36694- sys_chroot(".");
36695+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
36696+ sys_chroot((char __force_user *)".");
36697 complete(&setup_done);
36698 while (1) {
36699 spin_lock(&req_lock);
36700diff --git a/drivers/base/node.c b/drivers/base/node.c
36701index bc9f43b..29703b8 100644
36702--- a/drivers/base/node.c
36703+++ b/drivers/base/node.c
36704@@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
36705 struct node_attr {
36706 struct device_attribute attr;
36707 enum node_states state;
36708-};
36709+} __do_const;
36710
36711 static ssize_t show_node_state(struct device *dev,
36712 struct device_attribute *attr, char *buf)
36713diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
36714index bfb8955..42c9b9a 100644
36715--- a/drivers/base/power/domain.c
36716+++ b/drivers/base/power/domain.c
36717@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
36718 {
36719 struct cpuidle_driver *cpuidle_drv;
36720 struct gpd_cpu_data *cpu_data;
36721- struct cpuidle_state *idle_state;
36722+ cpuidle_state_no_const *idle_state;
36723 int ret = 0;
36724
36725 if (IS_ERR_OR_NULL(genpd) || state < 0)
36726@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
36727 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
36728 {
36729 struct gpd_cpu_data *cpu_data;
36730- struct cpuidle_state *idle_state;
36731+ cpuidle_state_no_const *idle_state;
36732 int ret = 0;
36733
36734 if (IS_ERR_OR_NULL(genpd))
36735diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
36736index 03e089a..0e9560c 100644
36737--- a/drivers/base/power/sysfs.c
36738+++ b/drivers/base/power/sysfs.c
36739@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
36740 return -EIO;
36741 }
36742 }
36743- return sprintf(buf, p);
36744+ return sprintf(buf, "%s", p);
36745 }
36746
36747 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
36748diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
36749index 2d56f41..8830f19 100644
36750--- a/drivers/base/power/wakeup.c
36751+++ b/drivers/base/power/wakeup.c
36752@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
36753 * They need to be modified together atomically, so it's better to use one
36754 * atomic variable to hold them both.
36755 */
36756-static atomic_t combined_event_count = ATOMIC_INIT(0);
36757+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
36758
36759 #define IN_PROGRESS_BITS (sizeof(int) * 4)
36760 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
36761
36762 static void split_counters(unsigned int *cnt, unsigned int *inpr)
36763 {
36764- unsigned int comb = atomic_read(&combined_event_count);
36765+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
36766
36767 *cnt = (comb >> IN_PROGRESS_BITS);
36768 *inpr = comb & MAX_IN_PROGRESS;
36769@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
36770 ws->start_prevent_time = ws->last_time;
36771
36772 /* Increment the counter of events in progress. */
36773- cec = atomic_inc_return(&combined_event_count);
36774+ cec = atomic_inc_return_unchecked(&combined_event_count);
36775
36776 trace_wakeup_source_activate(ws->name, cec);
36777 }
36778@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
36779 * Increment the counter of registered wakeup events and decrement the
36780 * couter of wakeup events in progress simultaneously.
36781 */
36782- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
36783+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
36784 trace_wakeup_source_deactivate(ws->name, cec);
36785
36786 split_counters(&cnt, &inpr);
36787diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
36788index e8d11b6..7b1b36f 100644
36789--- a/drivers/base/syscore.c
36790+++ b/drivers/base/syscore.c
36791@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
36792 void register_syscore_ops(struct syscore_ops *ops)
36793 {
36794 mutex_lock(&syscore_ops_lock);
36795- list_add_tail(&ops->node, &syscore_ops_list);
36796+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
36797 mutex_unlock(&syscore_ops_lock);
36798 }
36799 EXPORT_SYMBOL_GPL(register_syscore_ops);
36800@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
36801 void unregister_syscore_ops(struct syscore_ops *ops)
36802 {
36803 mutex_lock(&syscore_ops_lock);
36804- list_del(&ops->node);
36805+ pax_list_del((struct list_head *)&ops->node);
36806 mutex_unlock(&syscore_ops_lock);
36807 }
36808 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
36809diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
36810index b35fc4f..c902870 100644
36811--- a/drivers/block/cciss.c
36812+++ b/drivers/block/cciss.c
36813@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
36814 while (!list_empty(&h->reqQ)) {
36815 c = list_entry(h->reqQ.next, CommandList_struct, list);
36816 /* can't do anything if fifo is full */
36817- if ((h->access.fifo_full(h))) {
36818+ if ((h->access->fifo_full(h))) {
36819 dev_warn(&h->pdev->dev, "fifo full\n");
36820 break;
36821 }
36822@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
36823 h->Qdepth--;
36824
36825 /* Tell the controller execute command */
36826- h->access.submit_command(h, c);
36827+ h->access->submit_command(h, c);
36828
36829 /* Put job onto the completed Q */
36830 addQ(&h->cmpQ, c);
36831@@ -3447,17 +3447,17 @@ startio:
36832
36833 static inline unsigned long get_next_completion(ctlr_info_t *h)
36834 {
36835- return h->access.command_completed(h);
36836+ return h->access->command_completed(h);
36837 }
36838
36839 static inline int interrupt_pending(ctlr_info_t *h)
36840 {
36841- return h->access.intr_pending(h);
36842+ return h->access->intr_pending(h);
36843 }
36844
36845 static inline long interrupt_not_for_us(ctlr_info_t *h)
36846 {
36847- return ((h->access.intr_pending(h) == 0) ||
36848+ return ((h->access->intr_pending(h) == 0) ||
36849 (h->interrupts_enabled == 0));
36850 }
36851
36852@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
36853 u32 a;
36854
36855 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36856- return h->access.command_completed(h);
36857+ return h->access->command_completed(h);
36858
36859 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36860 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36861@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
36862 trans_support & CFGTBL_Trans_use_short_tags);
36863
36864 /* Change the access methods to the performant access methods */
36865- h->access = SA5_performant_access;
36866+ h->access = &SA5_performant_access;
36867 h->transMethod = CFGTBL_Trans_Performant;
36868
36869 return;
36870@@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
36871 if (prod_index < 0)
36872 return -ENODEV;
36873 h->product_name = products[prod_index].product_name;
36874- h->access = *(products[prod_index].access);
36875+ h->access = products[prod_index].access;
36876
36877 if (cciss_board_disabled(h)) {
36878 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36879@@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
36880 }
36881
36882 /* make sure the board interrupts are off */
36883- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36884+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36885 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
36886 if (rc)
36887 goto clean2;
36888@@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
36889 * fake ones to scoop up any residual completions.
36890 */
36891 spin_lock_irqsave(&h->lock, flags);
36892- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36893+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36894 spin_unlock_irqrestore(&h->lock, flags);
36895 free_irq(h->intr[h->intr_mode], h);
36896 rc = cciss_request_irq(h, cciss_msix_discard_completions,
36897@@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
36898 dev_info(&h->pdev->dev, "Board READY.\n");
36899 dev_info(&h->pdev->dev,
36900 "Waiting for stale completions to drain.\n");
36901- h->access.set_intr_mask(h, CCISS_INTR_ON);
36902+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36903 msleep(10000);
36904- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36905+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36906
36907 rc = controller_reset_failed(h->cfgtable);
36908 if (rc)
36909@@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
36910 cciss_scsi_setup(h);
36911
36912 /* Turn the interrupts on so we can service requests */
36913- h->access.set_intr_mask(h, CCISS_INTR_ON);
36914+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36915
36916 /* Get the firmware version */
36917 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
36918@@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
36919 kfree(flush_buf);
36920 if (return_code != IO_OK)
36921 dev_warn(&h->pdev->dev, "Error flushing cache\n");
36922- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36923+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36924 free_irq(h->intr[h->intr_mode], h);
36925 }
36926
36927diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
36928index 7fda30e..2f27946 100644
36929--- a/drivers/block/cciss.h
36930+++ b/drivers/block/cciss.h
36931@@ -101,7 +101,7 @@ struct ctlr_info
36932 /* information about each logical volume */
36933 drive_info_struct *drv[CISS_MAX_LUN];
36934
36935- struct access_method access;
36936+ struct access_method *access;
36937
36938 /* queue and queue Info */
36939 struct list_head reqQ;
36940@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
36941 }
36942
36943 static struct access_method SA5_access = {
36944- SA5_submit_command,
36945- SA5_intr_mask,
36946- SA5_fifo_full,
36947- SA5_intr_pending,
36948- SA5_completed,
36949+ .submit_command = SA5_submit_command,
36950+ .set_intr_mask = SA5_intr_mask,
36951+ .fifo_full = SA5_fifo_full,
36952+ .intr_pending = SA5_intr_pending,
36953+ .command_completed = SA5_completed,
36954 };
36955
36956 static struct access_method SA5B_access = {
36957- SA5_submit_command,
36958- SA5B_intr_mask,
36959- SA5_fifo_full,
36960- SA5B_intr_pending,
36961- SA5_completed,
36962+ .submit_command = SA5_submit_command,
36963+ .set_intr_mask = SA5B_intr_mask,
36964+ .fifo_full = SA5_fifo_full,
36965+ .intr_pending = SA5B_intr_pending,
36966+ .command_completed = SA5_completed,
36967 };
36968
36969 static struct access_method SA5_performant_access = {
36970- SA5_submit_command,
36971- SA5_performant_intr_mask,
36972- SA5_fifo_full,
36973- SA5_performant_intr_pending,
36974- SA5_performant_completed,
36975+ .submit_command = SA5_submit_command,
36976+ .set_intr_mask = SA5_performant_intr_mask,
36977+ .fifo_full = SA5_fifo_full,
36978+ .intr_pending = SA5_performant_intr_pending,
36979+ .command_completed = SA5_performant_completed,
36980 };
36981
36982 struct board_type {
36983diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
36984index 2b94403..fd6ad1f 100644
36985--- a/drivers/block/cpqarray.c
36986+++ b/drivers/block/cpqarray.c
36987@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36988 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
36989 goto Enomem4;
36990 }
36991- hba[i]->access.set_intr_mask(hba[i], 0);
36992+ hba[i]->access->set_intr_mask(hba[i], 0);
36993 if (request_irq(hba[i]->intr, do_ida_intr,
36994 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
36995 {
36996@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36997 add_timer(&hba[i]->timer);
36998
36999 /* Enable IRQ now that spinlock and rate limit timer are set up */
37000- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37001+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37002
37003 for(j=0; j<NWD; j++) {
37004 struct gendisk *disk = ida_gendisk[i][j];
37005@@ -694,7 +694,7 @@ DBGINFO(
37006 for(i=0; i<NR_PRODUCTS; i++) {
37007 if (board_id == products[i].board_id) {
37008 c->product_name = products[i].product_name;
37009- c->access = *(products[i].access);
37010+ c->access = products[i].access;
37011 break;
37012 }
37013 }
37014@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37015 hba[ctlr]->intr = intr;
37016 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37017 hba[ctlr]->product_name = products[j].product_name;
37018- hba[ctlr]->access = *(products[j].access);
37019+ hba[ctlr]->access = products[j].access;
37020 hba[ctlr]->ctlr = ctlr;
37021 hba[ctlr]->board_id = board_id;
37022 hba[ctlr]->pci_dev = NULL; /* not PCI */
37023@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37024
37025 while((c = h->reqQ) != NULL) {
37026 /* Can't do anything if we're busy */
37027- if (h->access.fifo_full(h) == 0)
37028+ if (h->access->fifo_full(h) == 0)
37029 return;
37030
37031 /* Get the first entry from the request Q */
37032@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37033 h->Qdepth--;
37034
37035 /* Tell the controller to do our bidding */
37036- h->access.submit_command(h, c);
37037+ h->access->submit_command(h, c);
37038
37039 /* Get onto the completion Q */
37040 addQ(&h->cmpQ, c);
37041@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37042 unsigned long flags;
37043 __u32 a,a1;
37044
37045- istat = h->access.intr_pending(h);
37046+ istat = h->access->intr_pending(h);
37047 /* Is this interrupt for us? */
37048 if (istat == 0)
37049 return IRQ_NONE;
37050@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37051 */
37052 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37053 if (istat & FIFO_NOT_EMPTY) {
37054- while((a = h->access.command_completed(h))) {
37055+ while((a = h->access->command_completed(h))) {
37056 a1 = a; a &= ~3;
37057 if ((c = h->cmpQ) == NULL)
37058 {
37059@@ -1448,11 +1448,11 @@ static int sendcmd(
37060 /*
37061 * Disable interrupt
37062 */
37063- info_p->access.set_intr_mask(info_p, 0);
37064+ info_p->access->set_intr_mask(info_p, 0);
37065 /* Make sure there is room in the command FIFO */
37066 /* Actually it should be completely empty at this time. */
37067 for (i = 200000; i > 0; i--) {
37068- temp = info_p->access.fifo_full(info_p);
37069+ temp = info_p->access->fifo_full(info_p);
37070 if (temp != 0) {
37071 break;
37072 }
37073@@ -1465,7 +1465,7 @@ DBG(
37074 /*
37075 * Send the cmd
37076 */
37077- info_p->access.submit_command(info_p, c);
37078+ info_p->access->submit_command(info_p, c);
37079 complete = pollcomplete(ctlr);
37080
37081 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37082@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37083 * we check the new geometry. Then turn interrupts back on when
37084 * we're done.
37085 */
37086- host->access.set_intr_mask(host, 0);
37087+ host->access->set_intr_mask(host, 0);
37088 getgeometry(ctlr);
37089- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37090+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37091
37092 for(i=0; i<NWD; i++) {
37093 struct gendisk *disk = ida_gendisk[ctlr][i];
37094@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37095 /* Wait (up to 2 seconds) for a command to complete */
37096
37097 for (i = 200000; i > 0; i--) {
37098- done = hba[ctlr]->access.command_completed(hba[ctlr]);
37099+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
37100 if (done == 0) {
37101 udelay(10); /* a short fixed delay */
37102 } else
37103diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37104index be73e9d..7fbf140 100644
37105--- a/drivers/block/cpqarray.h
37106+++ b/drivers/block/cpqarray.h
37107@@ -99,7 +99,7 @@ struct ctlr_info {
37108 drv_info_t drv[NWD];
37109 struct proc_dir_entry *proc;
37110
37111- struct access_method access;
37112+ struct access_method *access;
37113
37114 cmdlist_t *reqQ;
37115 cmdlist_t *cmpQ;
37116diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37117index 0e06f0c..c47b81d 100644
37118--- a/drivers/block/drbd/drbd_int.h
37119+++ b/drivers/block/drbd/drbd_int.h
37120@@ -582,7 +582,7 @@ struct drbd_epoch {
37121 struct drbd_tconn *tconn;
37122 struct list_head list;
37123 unsigned int barrier_nr;
37124- atomic_t epoch_size; /* increased on every request added. */
37125+ atomic_unchecked_t epoch_size; /* increased on every request added. */
37126 atomic_t active; /* increased on every req. added, and dec on every finished. */
37127 unsigned long flags;
37128 };
37129@@ -1022,7 +1022,7 @@ struct drbd_conf {
37130 unsigned int al_tr_number;
37131 int al_tr_cycle;
37132 wait_queue_head_t seq_wait;
37133- atomic_t packet_seq;
37134+ atomic_unchecked_t packet_seq;
37135 unsigned int peer_seq;
37136 spinlock_t peer_seq_lock;
37137 unsigned int minor;
37138@@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37139 char __user *uoptval;
37140 int err;
37141
37142- uoptval = (char __user __force *)optval;
37143+ uoptval = (char __force_user *)optval;
37144
37145 set_fs(KERNEL_DS);
37146 if (level == SOL_SOCKET)
37147diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37148index 89c497c..9c736ae 100644
37149--- a/drivers/block/drbd/drbd_interval.c
37150+++ b/drivers/block/drbd/drbd_interval.c
37151@@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37152 }
37153
37154 static const struct rb_augment_callbacks augment_callbacks = {
37155- augment_propagate,
37156- augment_copy,
37157- augment_rotate,
37158+ .propagate = augment_propagate,
37159+ .copy = augment_copy,
37160+ .rotate = augment_rotate,
37161 };
37162
37163 /**
37164diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37165index 9e3818b..7b64c92 100644
37166--- a/drivers/block/drbd/drbd_main.c
37167+++ b/drivers/block/drbd/drbd_main.c
37168@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
37169 p->sector = sector;
37170 p->block_id = block_id;
37171 p->blksize = blksize;
37172- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37173+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37174 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
37175 }
37176
37177@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
37178 return -EIO;
37179 p->sector = cpu_to_be64(req->i.sector);
37180 p->block_id = (unsigned long)req;
37181- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37182+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37183 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
37184 if (mdev->state.conn >= C_SYNC_SOURCE &&
37185 mdev->state.conn <= C_PAUSED_SYNC_T)
37186@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
37187 {
37188 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
37189
37190- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
37191- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
37192+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
37193+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
37194 kfree(tconn->current_epoch);
37195
37196 idr_destroy(&tconn->volumes);
37197diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37198index c706d50..5e1b472 100644
37199--- a/drivers/block/drbd/drbd_nl.c
37200+++ b/drivers/block/drbd/drbd_nl.c
37201@@ -3440,7 +3440,7 @@ out:
37202
37203 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37204 {
37205- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37206+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37207 struct sk_buff *msg;
37208 struct drbd_genlmsghdr *d_out;
37209 unsigned seq;
37210@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37211 return;
37212 }
37213
37214- seq = atomic_inc_return(&drbd_genl_seq);
37215+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37216 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37217 if (!msg)
37218 goto failed;
37219diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37220index 6fa6673..b7f97e9 100644
37221--- a/drivers/block/drbd/drbd_receiver.c
37222+++ b/drivers/block/drbd/drbd_receiver.c
37223@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
37224 {
37225 int err;
37226
37227- atomic_set(&mdev->packet_seq, 0);
37228+ atomic_set_unchecked(&mdev->packet_seq, 0);
37229 mdev->peer_seq = 0;
37230
37231 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
37232@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37233 do {
37234 next_epoch = NULL;
37235
37236- epoch_size = atomic_read(&epoch->epoch_size);
37237+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37238
37239 switch (ev & ~EV_CLEANUP) {
37240 case EV_PUT:
37241@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37242 rv = FE_DESTROYED;
37243 } else {
37244 epoch->flags = 0;
37245- atomic_set(&epoch->epoch_size, 0);
37246+ atomic_set_unchecked(&epoch->epoch_size, 0);
37247 /* atomic_set(&epoch->active, 0); is already zero */
37248 if (rv == FE_STILL_LIVE)
37249 rv = FE_RECYCLED;
37250@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37251 conn_wait_active_ee_empty(tconn);
37252 drbd_flush(tconn);
37253
37254- if (atomic_read(&tconn->current_epoch->epoch_size)) {
37255+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37256 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
37257 if (epoch)
37258 break;
37259@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37260 }
37261
37262 epoch->flags = 0;
37263- atomic_set(&epoch->epoch_size, 0);
37264+ atomic_set_unchecked(&epoch->epoch_size, 0);
37265 atomic_set(&epoch->active, 0);
37266
37267 spin_lock(&tconn->epoch_lock);
37268- if (atomic_read(&tconn->current_epoch->epoch_size)) {
37269+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37270 list_add(&epoch->list, &tconn->current_epoch->list);
37271 tconn->current_epoch = epoch;
37272 tconn->epochs++;
37273@@ -2163,7 +2163,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37274
37275 err = wait_for_and_update_peer_seq(mdev, peer_seq);
37276 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
37277- atomic_inc(&tconn->current_epoch->epoch_size);
37278+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
37279 err2 = drbd_drain_block(mdev, pi->size);
37280 if (!err)
37281 err = err2;
37282@@ -2197,7 +2197,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37283
37284 spin_lock(&tconn->epoch_lock);
37285 peer_req->epoch = tconn->current_epoch;
37286- atomic_inc(&peer_req->epoch->epoch_size);
37287+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
37288 atomic_inc(&peer_req->epoch->active);
37289 spin_unlock(&tconn->epoch_lock);
37290
37291@@ -4344,7 +4344,7 @@ struct data_cmd {
37292 int expect_payload;
37293 size_t pkt_size;
37294 int (*fn)(struct drbd_tconn *, struct packet_info *);
37295-};
37296+} __do_const;
37297
37298 static struct data_cmd drbd_cmd_handler[] = {
37299 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
37300@@ -4464,7 +4464,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
37301 if (!list_empty(&tconn->current_epoch->list))
37302 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
37303 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
37304- atomic_set(&tconn->current_epoch->epoch_size, 0);
37305+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
37306 tconn->send.seen_any_write_yet = false;
37307
37308 conn_info(tconn, "Connection closed\n");
37309@@ -5220,7 +5220,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
37310 struct asender_cmd {
37311 size_t pkt_size;
37312 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
37313-};
37314+} __do_const;
37315
37316 static struct asender_cmd asender_tbl[] = {
37317 [P_PING] = { 0, got_Ping },
37318diff --git a/drivers/block/loop.c b/drivers/block/loop.c
37319index c8dac73..1800093 100644
37320--- a/drivers/block/loop.c
37321+++ b/drivers/block/loop.c
37322@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
37323
37324 file_start_write(file);
37325 set_fs(get_ds());
37326- bw = file->f_op->write(file, buf, len, &pos);
37327+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
37328 set_fs(old_fs);
37329 file_end_write(file);
37330 if (likely(bw == len))
37331diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
37332index 83a598e..2de5ce3 100644
37333--- a/drivers/block/null_blk.c
37334+++ b/drivers/block/null_blk.c
37335@@ -407,14 +407,24 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
37336 return 0;
37337 }
37338
37339-static struct blk_mq_ops null_mq_ops = {
37340- .queue_rq = null_queue_rq,
37341- .map_queue = blk_mq_map_queue,
37342+static struct blk_mq_ops null_mq_single_ops = {
37343+ .queue_rq = null_queue_rq,
37344+ .map_queue = blk_mq_map_queue,
37345 .init_hctx = null_init_hctx,
37346+ .alloc_hctx = blk_mq_alloc_single_hw_queue,
37347+ .free_hctx = blk_mq_free_single_hw_queue,
37348+};
37349+
37350+static struct blk_mq_ops null_mq_per_node_ops = {
37351+ .queue_rq = null_queue_rq,
37352+ .map_queue = blk_mq_map_queue,
37353+ .init_hctx = null_init_hctx,
37354+ .alloc_hctx = null_alloc_hctx,
37355+ .free_hctx = null_free_hctx,
37356 };
37357
37358 static struct blk_mq_reg null_mq_reg = {
37359- .ops = &null_mq_ops,
37360+ .ops = &null_mq_single_ops,
37361 .queue_depth = 64,
37362 .cmd_size = sizeof(struct nullb_cmd),
37363 .flags = BLK_MQ_F_SHOULD_MERGE,
37364@@ -545,13 +555,8 @@ static int null_add_dev(void)
37365 null_mq_reg.queue_depth = hw_queue_depth;
37366 null_mq_reg.nr_hw_queues = submit_queues;
37367
37368- if (use_per_node_hctx) {
37369- null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
37370- null_mq_reg.ops->free_hctx = null_free_hctx;
37371- } else {
37372- null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
37373- null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
37374- }
37375+ if (use_per_node_hctx)
37376+ null_mq_reg.ops = &null_mq_per_node_ops;
37377
37378 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
37379 } else if (queue_mode == NULL_Q_BIO) {
37380diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
37381index ff8668c..f62167a 100644
37382--- a/drivers/block/pktcdvd.c
37383+++ b/drivers/block/pktcdvd.c
37384@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
37385
37386 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
37387 {
37388- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
37389+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
37390 }
37391
37392 /*
37393@@ -1883,7 +1883,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
37394 return -EROFS;
37395 }
37396 pd->settings.fp = ti.fp;
37397- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
37398+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
37399
37400 if (ti.nwa_v) {
37401 pd->nwa = be32_to_cpu(ti.next_writable);
37402diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
37403index e5565fb..71be10b4 100644
37404--- a/drivers/block/smart1,2.h
37405+++ b/drivers/block/smart1,2.h
37406@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
37407 }
37408
37409 static struct access_method smart4_access = {
37410- smart4_submit_command,
37411- smart4_intr_mask,
37412- smart4_fifo_full,
37413- smart4_intr_pending,
37414- smart4_completed,
37415+ .submit_command = smart4_submit_command,
37416+ .set_intr_mask = smart4_intr_mask,
37417+ .fifo_full = smart4_fifo_full,
37418+ .intr_pending = smart4_intr_pending,
37419+ .command_completed = smart4_completed,
37420 };
37421
37422 /*
37423@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
37424 }
37425
37426 static struct access_method smart2_access = {
37427- smart2_submit_command,
37428- smart2_intr_mask,
37429- smart2_fifo_full,
37430- smart2_intr_pending,
37431- smart2_completed,
37432+ .submit_command = smart2_submit_command,
37433+ .set_intr_mask = smart2_intr_mask,
37434+ .fifo_full = smart2_fifo_full,
37435+ .intr_pending = smart2_intr_pending,
37436+ .command_completed = smart2_completed,
37437 };
37438
37439 /*
37440@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
37441 }
37442
37443 static struct access_method smart2e_access = {
37444- smart2e_submit_command,
37445- smart2e_intr_mask,
37446- smart2e_fifo_full,
37447- smart2e_intr_pending,
37448- smart2e_completed,
37449+ .submit_command = smart2e_submit_command,
37450+ .set_intr_mask = smart2e_intr_mask,
37451+ .fifo_full = smart2e_fifo_full,
37452+ .intr_pending = smart2e_intr_pending,
37453+ .command_completed = smart2e_completed,
37454 };
37455
37456 /*
37457@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
37458 }
37459
37460 static struct access_method smart1_access = {
37461- smart1_submit_command,
37462- smart1_intr_mask,
37463- smart1_fifo_full,
37464- smart1_intr_pending,
37465- smart1_completed,
37466+ .submit_command = smart1_submit_command,
37467+ .set_intr_mask = smart1_intr_mask,
37468+ .fifo_full = smart1_fifo_full,
37469+ .intr_pending = smart1_intr_pending,
37470+ .command_completed = smart1_completed,
37471 };
37472diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
37473index f038dba..bb74c08 100644
37474--- a/drivers/bluetooth/btwilink.c
37475+++ b/drivers/bluetooth/btwilink.c
37476@@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
37477
37478 static int bt_ti_probe(struct platform_device *pdev)
37479 {
37480- static struct ti_st *hst;
37481+ struct ti_st *hst;
37482 struct hci_dev *hdev;
37483 int err;
37484
37485diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
37486index b6739cb..962fd35 100644
37487--- a/drivers/bus/arm-cci.c
37488+++ b/drivers/bus/arm-cci.c
37489@@ -979,7 +979,7 @@ static int cci_probe(void)
37490
37491 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
37492
37493- ports = kcalloc(sizeof(*ports), nb_cci_ports, GFP_KERNEL);
37494+ ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
37495 if (!ports)
37496 return -ENOMEM;
37497
37498diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
37499index 8a3aff7..d7538c2 100644
37500--- a/drivers/cdrom/cdrom.c
37501+++ b/drivers/cdrom/cdrom.c
37502@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
37503 ENSURE(reset, CDC_RESET);
37504 ENSURE(generic_packet, CDC_GENERIC_PACKET);
37505 cdi->mc_flags = 0;
37506- cdo->n_minors = 0;
37507 cdi->options = CDO_USE_FFLAGS;
37508
37509 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
37510@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
37511 else
37512 cdi->cdda_method = CDDA_OLD;
37513
37514- if (!cdo->generic_packet)
37515- cdo->generic_packet = cdrom_dummy_generic_packet;
37516+ if (!cdo->generic_packet) {
37517+ pax_open_kernel();
37518+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
37519+ pax_close_kernel();
37520+ }
37521
37522 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
37523 mutex_lock(&cdrom_mutex);
37524@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
37525 if (cdi->exit)
37526 cdi->exit(cdi);
37527
37528- cdi->ops->n_minors--;
37529 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
37530 }
37531
37532@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
37533 */
37534 nr = nframes;
37535 do {
37536- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
37537+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
37538 if (cgc.buffer)
37539 break;
37540
37541@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
37542 struct cdrom_device_info *cdi;
37543 int ret;
37544
37545- ret = scnprintf(info + *pos, max_size - *pos, header);
37546+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
37547 if (!ret)
37548 return 1;
37549
37550diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
37551index 5980cb9..6d7bd7e 100644
37552--- a/drivers/cdrom/gdrom.c
37553+++ b/drivers/cdrom/gdrom.c
37554@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
37555 .audio_ioctl = gdrom_audio_ioctl,
37556 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
37557 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
37558- .n_minors = 1,
37559 };
37560
37561 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
37562diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
37563index fa3243d..8c98297 100644
37564--- a/drivers/char/Kconfig
37565+++ b/drivers/char/Kconfig
37566@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
37567
37568 config DEVKMEM
37569 bool "/dev/kmem virtual device support"
37570- default y
37571+ default n
37572+ depends on !GRKERNSEC_KMEM
37573 help
37574 Say Y here if you want to support the /dev/kmem device. The
37575 /dev/kmem device is rarely used, but can be used for certain
37576@@ -576,6 +577,7 @@ config DEVPORT
37577 bool
37578 depends on !M68K
37579 depends on ISA || PCI
37580+ depends on !GRKERNSEC_KMEM
37581 default y
37582
37583 source "drivers/s390/char/Kconfig"
37584diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
37585index a48e05b..6bac831 100644
37586--- a/drivers/char/agp/compat_ioctl.c
37587+++ b/drivers/char/agp/compat_ioctl.c
37588@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
37589 return -ENOMEM;
37590 }
37591
37592- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
37593+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
37594 sizeof(*usegment) * ureserve.seg_count)) {
37595 kfree(usegment);
37596 kfree(ksegment);
37597diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
37598index 1b19239..b87b143 100644
37599--- a/drivers/char/agp/frontend.c
37600+++ b/drivers/char/agp/frontend.c
37601@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
37602 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
37603 return -EFAULT;
37604
37605- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
37606+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
37607 return -EFAULT;
37608
37609 client = agp_find_client_by_pid(reserve.pid);
37610@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
37611 if (segment == NULL)
37612 return -ENOMEM;
37613
37614- if (copy_from_user(segment, (void __user *) reserve.seg_list,
37615+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
37616 sizeof(struct agp_segment) * reserve.seg_count)) {
37617 kfree(segment);
37618 return -EFAULT;
37619diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
37620index 4f94375..413694e 100644
37621--- a/drivers/char/genrtc.c
37622+++ b/drivers/char/genrtc.c
37623@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
37624 switch (cmd) {
37625
37626 case RTC_PLL_GET:
37627+ memset(&pll, 0, sizeof(pll));
37628 if (get_rtc_pll(&pll))
37629 return -EINVAL;
37630 else
37631diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
37632index 5d9c31d..c94ccb5 100644
37633--- a/drivers/char/hpet.c
37634+++ b/drivers/char/hpet.c
37635@@ -578,7 +578,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
37636 }
37637
37638 static int
37639-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
37640+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
37641 struct hpet_info *info)
37642 {
37643 struct hpet_timer __iomem *timer;
37644diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
37645index 86fe45c..c0ea948 100644
37646--- a/drivers/char/hw_random/intel-rng.c
37647+++ b/drivers/char/hw_random/intel-rng.c
37648@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
37649
37650 if (no_fwh_detect)
37651 return -ENODEV;
37652- printk(warning);
37653+ printk("%s", warning);
37654 return -EBUSY;
37655 }
37656
37657diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
37658index ec4e10f..f2a763b 100644
37659--- a/drivers/char/ipmi/ipmi_msghandler.c
37660+++ b/drivers/char/ipmi/ipmi_msghandler.c
37661@@ -420,7 +420,7 @@ struct ipmi_smi {
37662 struct proc_dir_entry *proc_dir;
37663 char proc_dir_name[10];
37664
37665- atomic_t stats[IPMI_NUM_STATS];
37666+ atomic_unchecked_t stats[IPMI_NUM_STATS];
37667
37668 /*
37669 * run_to_completion duplicate of smb_info, smi_info
37670@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
37671
37672
37673 #define ipmi_inc_stat(intf, stat) \
37674- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
37675+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
37676 #define ipmi_get_stat(intf, stat) \
37677- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
37678+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
37679
37680 static int is_lan_addr(struct ipmi_addr *addr)
37681 {
37682@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
37683 INIT_LIST_HEAD(&intf->cmd_rcvrs);
37684 init_waitqueue_head(&intf->waitq);
37685 for (i = 0; i < IPMI_NUM_STATS; i++)
37686- atomic_set(&intf->stats[i], 0);
37687+ atomic_set_unchecked(&intf->stats[i], 0);
37688
37689 intf->proc_dir = NULL;
37690
37691diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
37692index 15e4a60..b046093 100644
37693--- a/drivers/char/ipmi/ipmi_si_intf.c
37694+++ b/drivers/char/ipmi/ipmi_si_intf.c
37695@@ -280,7 +280,7 @@ struct smi_info {
37696 unsigned char slave_addr;
37697
37698 /* Counters and things for the proc filesystem. */
37699- atomic_t stats[SI_NUM_STATS];
37700+ atomic_unchecked_t stats[SI_NUM_STATS];
37701
37702 struct task_struct *thread;
37703
37704@@ -289,9 +289,9 @@ struct smi_info {
37705 };
37706
37707 #define smi_inc_stat(smi, stat) \
37708- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
37709+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
37710 #define smi_get_stat(smi, stat) \
37711- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
37712+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
37713
37714 #define SI_MAX_PARMS 4
37715
37716@@ -3324,7 +3324,7 @@ static int try_smi_init(struct smi_info *new_smi)
37717 atomic_set(&new_smi->req_events, 0);
37718 new_smi->run_to_completion = 0;
37719 for (i = 0; i < SI_NUM_STATS; i++)
37720- atomic_set(&new_smi->stats[i], 0);
37721+ atomic_set_unchecked(&new_smi->stats[i], 0);
37722
37723 new_smi->interrupt_disabled = 1;
37724 atomic_set(&new_smi->stop_operation, 0);
37725diff --git a/drivers/char/mem.c b/drivers/char/mem.c
37726index f895a8c..2bc9147 100644
37727--- a/drivers/char/mem.c
37728+++ b/drivers/char/mem.c
37729@@ -18,6 +18,7 @@
37730 #include <linux/raw.h>
37731 #include <linux/tty.h>
37732 #include <linux/capability.h>
37733+#include <linux/security.h>
37734 #include <linux/ptrace.h>
37735 #include <linux/device.h>
37736 #include <linux/highmem.h>
37737@@ -37,6 +38,10 @@
37738
37739 #define DEVPORT_MINOR 4
37740
37741+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
37742+extern const struct file_operations grsec_fops;
37743+#endif
37744+
37745 static inline unsigned long size_inside_page(unsigned long start,
37746 unsigned long size)
37747 {
37748@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37749
37750 while (cursor < to) {
37751 if (!devmem_is_allowed(pfn)) {
37752+#ifdef CONFIG_GRKERNSEC_KMEM
37753+ gr_handle_mem_readwrite(from, to);
37754+#else
37755 printk(KERN_INFO
37756 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
37757 current->comm, from, to);
37758+#endif
37759 return 0;
37760 }
37761 cursor += PAGE_SIZE;
37762@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37763 }
37764 return 1;
37765 }
37766+#elif defined(CONFIG_GRKERNSEC_KMEM)
37767+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37768+{
37769+ return 0;
37770+}
37771 #else
37772 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37773 {
37774@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
37775
37776 while (count > 0) {
37777 unsigned long remaining;
37778+ char *temp;
37779
37780 sz = size_inside_page(p, count);
37781
37782@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
37783 if (!ptr)
37784 return -EFAULT;
37785
37786- remaining = copy_to_user(buf, ptr, sz);
37787+#ifdef CONFIG_PAX_USERCOPY
37788+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
37789+ if (!temp) {
37790+ unxlate_dev_mem_ptr(p, ptr);
37791+ return -ENOMEM;
37792+ }
37793+ memcpy(temp, ptr, sz);
37794+#else
37795+ temp = ptr;
37796+#endif
37797+
37798+ remaining = copy_to_user(buf, temp, sz);
37799+
37800+#ifdef CONFIG_PAX_USERCOPY
37801+ kfree(temp);
37802+#endif
37803+
37804 unxlate_dev_mem_ptr(p, ptr);
37805 if (remaining)
37806 return -EFAULT;
37807@@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37808 size_t count, loff_t *ppos)
37809 {
37810 unsigned long p = *ppos;
37811- ssize_t low_count, read, sz;
37812+ ssize_t low_count, read, sz, err = 0;
37813 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
37814- int err = 0;
37815
37816 read = 0;
37817 if (p < (unsigned long) high_memory) {
37818@@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37819 }
37820 #endif
37821 while (low_count > 0) {
37822+ char *temp;
37823+
37824 sz = size_inside_page(p, low_count);
37825
37826 /*
37827@@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37828 */
37829 kbuf = xlate_dev_kmem_ptr((char *)p);
37830
37831- if (copy_to_user(buf, kbuf, sz))
37832+#ifdef CONFIG_PAX_USERCOPY
37833+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
37834+ if (!temp)
37835+ return -ENOMEM;
37836+ memcpy(temp, kbuf, sz);
37837+#else
37838+ temp = kbuf;
37839+#endif
37840+
37841+ err = copy_to_user(buf, temp, sz);
37842+
37843+#ifdef CONFIG_PAX_USERCOPY
37844+ kfree(temp);
37845+#endif
37846+
37847+ if (err)
37848 return -EFAULT;
37849 buf += sz;
37850 p += sz;
37851@@ -822,6 +869,9 @@ static const struct memdev {
37852 #ifdef CONFIG_PRINTK
37853 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
37854 #endif
37855+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
37856+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
37857+#endif
37858 };
37859
37860 static int memory_open(struct inode *inode, struct file *filp)
37861@@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
37862 continue;
37863
37864 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
37865- NULL, devlist[minor].name);
37866+ NULL, "%s", devlist[minor].name);
37867 }
37868
37869 return tty_init();
37870diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
37871index 9df78e2..01ba9ae 100644
37872--- a/drivers/char/nvram.c
37873+++ b/drivers/char/nvram.c
37874@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
37875
37876 spin_unlock_irq(&rtc_lock);
37877
37878- if (copy_to_user(buf, contents, tmp - contents))
37879+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
37880 return -EFAULT;
37881
37882 *ppos = i;
37883diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
37884index d39cca6..8c1e269 100644
37885--- a/drivers/char/pcmcia/synclink_cs.c
37886+++ b/drivers/char/pcmcia/synclink_cs.c
37887@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
37888
37889 if (debug_level >= DEBUG_LEVEL_INFO)
37890 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
37891- __FILE__, __LINE__, info->device_name, port->count);
37892+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
37893
37894- WARN_ON(!port->count);
37895+ WARN_ON(!atomic_read(&port->count));
37896
37897 if (tty_port_close_start(port, tty, filp) == 0)
37898 goto cleanup;
37899@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
37900 cleanup:
37901 if (debug_level >= DEBUG_LEVEL_INFO)
37902 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
37903- tty->driver->name, port->count);
37904+ tty->driver->name, atomic_read(&port->count));
37905 }
37906
37907 /* Wait until the transmitter is empty.
37908@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
37909
37910 if (debug_level >= DEBUG_LEVEL_INFO)
37911 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
37912- __FILE__, __LINE__, tty->driver->name, port->count);
37913+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
37914
37915 /* If port is closing, signal caller to try again */
37916 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
37917@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
37918 goto cleanup;
37919 }
37920 spin_lock(&port->lock);
37921- port->count++;
37922+ atomic_inc(&port->count);
37923 spin_unlock(&port->lock);
37924 spin_unlock_irqrestore(&info->netlock, flags);
37925
37926- if (port->count == 1) {
37927+ if (atomic_read(&port->count) == 1) {
37928 /* 1st open on this device, init hardware */
37929 retval = startup(info, tty);
37930 if (retval < 0)
37931@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
37932 unsigned short new_crctype;
37933
37934 /* return error if TTY interface open */
37935- if (info->port.count)
37936+ if (atomic_read(&info->port.count))
37937 return -EBUSY;
37938
37939 switch (encoding)
37940@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
37941
37942 /* arbitrate between network and tty opens */
37943 spin_lock_irqsave(&info->netlock, flags);
37944- if (info->port.count != 0 || info->netcount != 0) {
37945+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
37946 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
37947 spin_unlock_irqrestore(&info->netlock, flags);
37948 return -EBUSY;
37949@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37950 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
37951
37952 /* return error if TTY interface open */
37953- if (info->port.count)
37954+ if (atomic_read(&info->port.count))
37955 return -EBUSY;
37956
37957 if (cmd != SIOCWANDEV)
37958diff --git a/drivers/char/random.c b/drivers/char/random.c
37959index 429b75b..a4f540d 100644
37960--- a/drivers/char/random.c
37961+++ b/drivers/char/random.c
37962@@ -270,10 +270,17 @@
37963 /*
37964 * Configuration information
37965 */
37966+#ifdef CONFIG_GRKERNSEC_RANDNET
37967+#define INPUT_POOL_SHIFT 14
37968+#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
37969+#define OUTPUT_POOL_SHIFT 12
37970+#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
37971+#else
37972 #define INPUT_POOL_SHIFT 12
37973 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
37974 #define OUTPUT_POOL_SHIFT 10
37975 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
37976+#endif
37977 #define SEC_XFER_SIZE 512
37978 #define EXTRACT_SIZE 10
37979
37980@@ -284,9 +291,6 @@
37981 /*
37982 * To allow fractional bits to be tracked, the entropy_count field is
37983 * denominated in units of 1/8th bits.
37984- *
37985- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
37986- * credit_entropy_bits() needs to be 64 bits wide.
37987 */
37988 #define ENTROPY_SHIFT 3
37989 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
37990@@ -361,12 +365,19 @@ static struct poolinfo {
37991 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
37992 int tap1, tap2, tap3, tap4, tap5;
37993 } poolinfo_table[] = {
37994+#ifdef CONFIG_GRKERNSEC_RANDNET
37995+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
37996+ { S(512), 411, 308, 208, 104, 1 },
37997+ /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
37998+ { S(128), 104, 76, 51, 25, 1 },
37999+#else
38000 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
38001 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
38002 { S(128), 104, 76, 51, 25, 1 },
38003 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
38004 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
38005 { S(32), 26, 19, 14, 7, 1 },
38006+#endif
38007 #if 0
38008 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
38009 { S(2048), 1638, 1231, 819, 411, 1 },
38010@@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38011 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38012 }
38013
38014- ACCESS_ONCE(r->input_rotate) = input_rotate;
38015- ACCESS_ONCE(r->add_ptr) = i;
38016+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38017+ ACCESS_ONCE_RW(r->add_ptr) = i;
38018 smp_wmb();
38019
38020 if (out)
38021@@ -632,7 +643,7 @@ retry:
38022 /* The +2 corresponds to the /4 in the denominator */
38023
38024 do {
38025- unsigned int anfrac = min(pnfrac, pool_size/2);
38026+ u64 anfrac = min(pnfrac, pool_size/2);
38027 unsigned int add =
38028 ((pool_size - entropy_count)*anfrac*3) >> s;
38029
38030@@ -1151,7 +1162,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38031
38032 extract_buf(r, tmp);
38033 i = min_t(int, nbytes, EXTRACT_SIZE);
38034- if (copy_to_user(buf, tmp, i)) {
38035+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38036 ret = -EFAULT;
38037 break;
38038 }
38039@@ -1507,7 +1518,7 @@ EXPORT_SYMBOL(generate_random_uuid);
38040 #include <linux/sysctl.h>
38041
38042 static int min_read_thresh = 8, min_write_thresh;
38043-static int max_read_thresh = INPUT_POOL_WORDS * 32;
38044+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
38045 static int max_write_thresh = INPUT_POOL_WORDS * 32;
38046 static char sysctl_bootid[16];
38047
38048@@ -1523,7 +1534,7 @@ static char sysctl_bootid[16];
38049 static int proc_do_uuid(struct ctl_table *table, int write,
38050 void __user *buffer, size_t *lenp, loff_t *ppos)
38051 {
38052- struct ctl_table fake_table;
38053+ ctl_table_no_const fake_table;
38054 unsigned char buf[64], tmp_uuid[16], *uuid;
38055
38056 uuid = table->data;
38057@@ -1553,7 +1564,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38058 static int proc_do_entropy(ctl_table *table, int write,
38059 void __user *buffer, size_t *lenp, loff_t *ppos)
38060 {
38061- ctl_table fake_table;
38062+ ctl_table_no_const fake_table;
38063 int entropy_count;
38064
38065 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38066diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38067index 7cc1fe22..b602d6b 100644
38068--- a/drivers/char/sonypi.c
38069+++ b/drivers/char/sonypi.c
38070@@ -54,6 +54,7 @@
38071
38072 #include <asm/uaccess.h>
38073 #include <asm/io.h>
38074+#include <asm/local.h>
38075
38076 #include <linux/sonypi.h>
38077
38078@@ -490,7 +491,7 @@ static struct sonypi_device {
38079 spinlock_t fifo_lock;
38080 wait_queue_head_t fifo_proc_list;
38081 struct fasync_struct *fifo_async;
38082- int open_count;
38083+ local_t open_count;
38084 int model;
38085 struct input_dev *input_jog_dev;
38086 struct input_dev *input_key_dev;
38087@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38088 static int sonypi_misc_release(struct inode *inode, struct file *file)
38089 {
38090 mutex_lock(&sonypi_device.lock);
38091- sonypi_device.open_count--;
38092+ local_dec(&sonypi_device.open_count);
38093 mutex_unlock(&sonypi_device.lock);
38094 return 0;
38095 }
38096@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38097 {
38098 mutex_lock(&sonypi_device.lock);
38099 /* Flush input queue on first open */
38100- if (!sonypi_device.open_count)
38101+ if (!local_read(&sonypi_device.open_count))
38102 kfifo_reset(&sonypi_device.fifo);
38103- sonypi_device.open_count++;
38104+ local_inc(&sonypi_device.open_count);
38105 mutex_unlock(&sonypi_device.lock);
38106
38107 return 0;
38108diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38109index 64420b3..5c40b56 100644
38110--- a/drivers/char/tpm/tpm_acpi.c
38111+++ b/drivers/char/tpm/tpm_acpi.c
38112@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38113 virt = acpi_os_map_memory(start, len);
38114 if (!virt) {
38115 kfree(log->bios_event_log);
38116+ log->bios_event_log = NULL;
38117 printk("%s: ERROR - Unable to map memory\n", __func__);
38118 return -EIO;
38119 }
38120
38121- memcpy_fromio(log->bios_event_log, virt, len);
38122+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38123
38124 acpi_os_unmap_memory(virt, len);
38125 return 0;
38126diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38127index 59f7cb2..bac8b6d 100644
38128--- a/drivers/char/tpm/tpm_eventlog.c
38129+++ b/drivers/char/tpm/tpm_eventlog.c
38130@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38131 event = addr;
38132
38133 if ((event->event_type == 0 && event->event_size == 0) ||
38134- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38135+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38136 return NULL;
38137
38138 return addr;
38139@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38140 return NULL;
38141
38142 if ((event->event_type == 0 && event->event_size == 0) ||
38143- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38144+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38145 return NULL;
38146
38147 (*pos)++;
38148@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38149 int i;
38150
38151 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38152- seq_putc(m, data[i]);
38153+ if (!seq_putc(m, data[i]))
38154+ return -EFAULT;
38155
38156 return 0;
38157 }
38158diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38159index feea87c..18aefff 100644
38160--- a/drivers/char/virtio_console.c
38161+++ b/drivers/char/virtio_console.c
38162@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38163 if (to_user) {
38164 ssize_t ret;
38165
38166- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38167+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38168 if (ret)
38169 return -EFAULT;
38170 } else {
38171@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38172 if (!port_has_data(port) && !port->host_connected)
38173 return 0;
38174
38175- return fill_readbuf(port, ubuf, count, true);
38176+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38177 }
38178
38179 static int wait_port_writable(struct port *port, bool nonblock)
38180diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38181index a33f46f..a720eed 100644
38182--- a/drivers/clk/clk-composite.c
38183+++ b/drivers/clk/clk-composite.c
38184@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38185 struct clk *clk;
38186 struct clk_init_data init;
38187 struct clk_composite *composite;
38188- struct clk_ops *clk_composite_ops;
38189+ clk_ops_no_const *clk_composite_ops;
38190
38191 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38192 if (!composite) {
38193diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
38194index 81dd31a..ef5c542 100644
38195--- a/drivers/clk/socfpga/clk.c
38196+++ b/drivers/clk/socfpga/clk.c
38197@@ -22,6 +22,7 @@
38198 #include <linux/clk-provider.h>
38199 #include <linux/io.h>
38200 #include <linux/of.h>
38201+#include <asm/pgtable.h>
38202
38203 /* Clock Manager offsets */
38204 #define CLKMGR_CTRL 0x0
38205@@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
38206 streq(clk_name, "periph_pll") ||
38207 streq(clk_name, "sdram_pll")) {
38208 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
38209- clk_pll_ops.enable = clk_gate_ops.enable;
38210- clk_pll_ops.disable = clk_gate_ops.disable;
38211+ pax_open_kernel();
38212+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
38213+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
38214+ pax_close_kernel();
38215 }
38216
38217 clk = clk_register(NULL, &socfpga_clk->hw.hw);
38218@@ -244,7 +247,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
38219 return parent_rate / div;
38220 }
38221
38222-static struct clk_ops gateclk_ops = {
38223+static clk_ops_no_const gateclk_ops __read_only = {
38224 .recalc_rate = socfpga_clk_recalc_rate,
38225 .get_parent = socfpga_clk_get_parent,
38226 .set_parent = socfpga_clk_set_parent,
38227diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
38228index caf41eb..223d27a 100644
38229--- a/drivers/cpufreq/acpi-cpufreq.c
38230+++ b/drivers/cpufreq/acpi-cpufreq.c
38231@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
38232 return sprintf(buf, "%u\n", boost_enabled);
38233 }
38234
38235-static struct global_attr global_boost = __ATTR(boost, 0644,
38236+static global_attr_no_const global_boost = __ATTR(boost, 0644,
38237 show_global_boost,
38238 store_global_boost);
38239
38240@@ -693,8 +693,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38241 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
38242 per_cpu(acfreq_data, cpu) = data;
38243
38244- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
38245- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38246+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
38247+ pax_open_kernel();
38248+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38249+ pax_close_kernel();
38250+ }
38251
38252 result = acpi_processor_register_performance(data->acpi_data, cpu);
38253 if (result)
38254@@ -827,7 +830,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38255 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
38256 break;
38257 case ACPI_ADR_SPACE_FIXED_HARDWARE:
38258- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38259+ pax_open_kernel();
38260+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38261+ pax_close_kernel();
38262 break;
38263 default:
38264 break;
38265diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
38266index 8d19f7c..6bc2daa 100644
38267--- a/drivers/cpufreq/cpufreq.c
38268+++ b/drivers/cpufreq/cpufreq.c
38269@@ -1885,7 +1885,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
38270 #endif
38271
38272 mutex_lock(&cpufreq_governor_mutex);
38273- list_del(&governor->governor_list);
38274+ pax_list_del(&governor->governor_list);
38275 mutex_unlock(&cpufreq_governor_mutex);
38276 return;
38277 }
38278@@ -2115,7 +2115,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
38279 return NOTIFY_OK;
38280 }
38281
38282-static struct notifier_block __refdata cpufreq_cpu_notifier = {
38283+static struct notifier_block cpufreq_cpu_notifier = {
38284 .notifier_call = cpufreq_cpu_callback,
38285 };
38286
38287@@ -2148,8 +2148,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38288
38289 pr_debug("trying to register driver %s\n", driver_data->name);
38290
38291- if (driver_data->setpolicy)
38292- driver_data->flags |= CPUFREQ_CONST_LOOPS;
38293+ if (driver_data->setpolicy) {
38294+ pax_open_kernel();
38295+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
38296+ pax_close_kernel();
38297+ }
38298
38299 write_lock_irqsave(&cpufreq_driver_lock, flags);
38300 if (cpufreq_driver) {
38301diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
38302index e6be635..f8a90dc 100644
38303--- a/drivers/cpufreq/cpufreq_governor.c
38304+++ b/drivers/cpufreq/cpufreq_governor.c
38305@@ -187,7 +187,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38306 struct dbs_data *dbs_data;
38307 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
38308 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
38309- struct od_ops *od_ops = NULL;
38310+ const struct od_ops *od_ops = NULL;
38311 struct od_dbs_tuners *od_tuners = NULL;
38312 struct cs_dbs_tuners *cs_tuners = NULL;
38313 struct cpu_dbs_common_info *cpu_cdbs;
38314@@ -253,7 +253,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38315
38316 if ((cdata->governor == GOV_CONSERVATIVE) &&
38317 (!policy->governor->initialized)) {
38318- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38319+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38320
38321 cpufreq_register_notifier(cs_ops->notifier_block,
38322 CPUFREQ_TRANSITION_NOTIFIER);
38323@@ -273,7 +273,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38324
38325 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
38326 (policy->governor->initialized == 1)) {
38327- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38328+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38329
38330 cpufreq_unregister_notifier(cs_ops->notifier_block,
38331 CPUFREQ_TRANSITION_NOTIFIER);
38332diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
38333index b5f2b86..daa801b 100644
38334--- a/drivers/cpufreq/cpufreq_governor.h
38335+++ b/drivers/cpufreq/cpufreq_governor.h
38336@@ -205,7 +205,7 @@ struct common_dbs_data {
38337 void (*exit)(struct dbs_data *dbs_data);
38338
38339 /* Governor specific ops, see below */
38340- void *gov_ops;
38341+ const void *gov_ops;
38342 };
38343
38344 /* Governor Per policy data */
38345@@ -225,7 +225,7 @@ struct od_ops {
38346 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
38347 unsigned int freq_next, unsigned int relation);
38348 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
38349-};
38350+} __no_const;
38351
38352 struct cs_ops {
38353 struct notifier_block *notifier_block;
38354diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
38355index 18d4091..434be15 100644
38356--- a/drivers/cpufreq/cpufreq_ondemand.c
38357+++ b/drivers/cpufreq/cpufreq_ondemand.c
38358@@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
38359
38360 define_get_cpu_dbs_routines(od_cpu_dbs_info);
38361
38362-static struct od_ops od_ops = {
38363+static struct od_ops od_ops __read_only = {
38364 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
38365 .powersave_bias_target = generic_powersave_bias_target,
38366 .freq_increase = dbs_freq_increase,
38367@@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
38368 (struct cpufreq_policy *, unsigned int, unsigned int),
38369 unsigned int powersave_bias)
38370 {
38371- od_ops.powersave_bias_target = f;
38372+ pax_open_kernel();
38373+ *(void **)&od_ops.powersave_bias_target = f;
38374+ pax_close_kernel();
38375 od_set_powersave_bias(powersave_bias);
38376 }
38377 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
38378
38379 void od_unregister_powersave_bias_handler(void)
38380 {
38381- od_ops.powersave_bias_target = generic_powersave_bias_target;
38382+ pax_open_kernel();
38383+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
38384+ pax_close_kernel();
38385 od_set_powersave_bias(0);
38386 }
38387 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
38388diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
38389index 4cf0d28..5830372 100644
38390--- a/drivers/cpufreq/cpufreq_stats.c
38391+++ b/drivers/cpufreq/cpufreq_stats.c
38392@@ -352,7 +352,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
38393 }
38394
38395 /* priority=1 so this will get called before cpufreq_remove_dev */
38396-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
38397+static struct notifier_block cpufreq_stat_cpu_notifier = {
38398 .notifier_call = cpufreq_stat_cpu_callback,
38399 .priority = 1,
38400 };
38401diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
38402index d51f17ed..9f43b15 100644
38403--- a/drivers/cpufreq/intel_pstate.c
38404+++ b/drivers/cpufreq/intel_pstate.c
38405@@ -112,10 +112,10 @@ struct pstate_funcs {
38406 struct cpu_defaults {
38407 struct pstate_adjust_policy pid_policy;
38408 struct pstate_funcs funcs;
38409-};
38410+} __do_const;
38411
38412 static struct pstate_adjust_policy pid_params;
38413-static struct pstate_funcs pstate_funcs;
38414+static struct pstate_funcs *pstate_funcs;
38415
38416 struct perf_limits {
38417 int no_turbo;
38418@@ -462,7 +462,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
38419
38420 cpu->pstate.current_pstate = pstate;
38421
38422- pstate_funcs.set(pstate);
38423+ pstate_funcs->set(pstate);
38424 }
38425
38426 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
38427@@ -484,9 +484,9 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
38428 {
38429 sprintf(cpu->name, "Intel 2nd generation core");
38430
38431- cpu->pstate.min_pstate = pstate_funcs.get_min();
38432- cpu->pstate.max_pstate = pstate_funcs.get_max();
38433- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
38434+ cpu->pstate.min_pstate = pstate_funcs->get_min();
38435+ cpu->pstate.max_pstate = pstate_funcs->get_max();
38436+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
38437
38438 /*
38439 * goto max pstate so we don't slow up boot if we are built-in if we are
38440@@ -750,9 +750,9 @@ static int intel_pstate_msrs_not_valid(void)
38441 rdmsrl(MSR_IA32_APERF, aperf);
38442 rdmsrl(MSR_IA32_MPERF, mperf);
38443
38444- if (!pstate_funcs.get_max() ||
38445- !pstate_funcs.get_min() ||
38446- !pstate_funcs.get_turbo())
38447+ if (!pstate_funcs->get_max() ||
38448+ !pstate_funcs->get_min() ||
38449+ !pstate_funcs->get_turbo())
38450 return -ENODEV;
38451
38452 rdmsrl(MSR_IA32_APERF, tmp);
38453@@ -766,7 +766,7 @@ static int intel_pstate_msrs_not_valid(void)
38454 return 0;
38455 }
38456
38457-static void copy_pid_params(struct pstate_adjust_policy *policy)
38458+static void copy_pid_params(const struct pstate_adjust_policy *policy)
38459 {
38460 pid_params.sample_rate_ms = policy->sample_rate_ms;
38461 pid_params.p_gain_pct = policy->p_gain_pct;
38462@@ -778,10 +778,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
38463
38464 static void copy_cpu_funcs(struct pstate_funcs *funcs)
38465 {
38466- pstate_funcs.get_max = funcs->get_max;
38467- pstate_funcs.get_min = funcs->get_min;
38468- pstate_funcs.get_turbo = funcs->get_turbo;
38469- pstate_funcs.set = funcs->set;
38470+ pstate_funcs = funcs;
38471 }
38472
38473 #if IS_ENABLED(CONFIG_ACPI)
38474diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
38475index 3d1cba9..0ab21d2 100644
38476--- a/drivers/cpufreq/p4-clockmod.c
38477+++ b/drivers/cpufreq/p4-clockmod.c
38478@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
38479 case 0x0F: /* Core Duo */
38480 case 0x16: /* Celeron Core */
38481 case 0x1C: /* Atom */
38482- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38483+ pax_open_kernel();
38484+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38485+ pax_close_kernel();
38486 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
38487 case 0x0D: /* Pentium M (Dothan) */
38488- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38489+ pax_open_kernel();
38490+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38491+ pax_close_kernel();
38492 /* fall through */
38493 case 0x09: /* Pentium M (Banias) */
38494 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
38495@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
38496
38497 /* on P-4s, the TSC runs with constant frequency independent whether
38498 * throttling is active or not. */
38499- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38500+ pax_open_kernel();
38501+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38502+ pax_close_kernel();
38503
38504 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
38505 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
38506diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
38507index 724ffbd..ad83692 100644
38508--- a/drivers/cpufreq/sparc-us3-cpufreq.c
38509+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
38510@@ -18,14 +18,12 @@
38511 #include <asm/head.h>
38512 #include <asm/timer.h>
38513
38514-static struct cpufreq_driver *cpufreq_us3_driver;
38515-
38516 struct us3_freq_percpu_info {
38517 struct cpufreq_frequency_table table[4];
38518 };
38519
38520 /* Indexed by cpu number. */
38521-static struct us3_freq_percpu_info *us3_freq_table;
38522+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
38523
38524 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
38525 * in the Safari config register.
38526@@ -156,14 +154,26 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
38527
38528 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
38529 {
38530- if (cpufreq_us3_driver) {
38531- cpufreq_frequency_table_put_attr(policy->cpu);
38532- us3_freq_target(policy, 0);
38533- }
38534+ cpufreq_frequency_table_put_attr(policy->cpu);
38535+ us3_freq_target(policy, 0);
38536
38537 return 0;
38538 }
38539
38540+static int __init us3_freq_init(void);
38541+static void __exit us3_freq_exit(void);
38542+
38543+static struct cpufreq_driver cpufreq_us3_driver = {
38544+ .init = us3_freq_cpu_init,
38545+ .verify = cpufreq_generic_frequency_table_verify,
38546+ .target_index = us3_freq_target,
38547+ .get = us3_freq_get,
38548+ .exit = us3_freq_cpu_exit,
38549+ .owner = THIS_MODULE,
38550+ .name = "UltraSPARC-III",
38551+
38552+};
38553+
38554 static int __init us3_freq_init(void)
38555 {
38556 unsigned long manuf, impl, ver;
38557@@ -180,55 +190,15 @@ static int __init us3_freq_init(void)
38558 (impl == CHEETAH_IMPL ||
38559 impl == CHEETAH_PLUS_IMPL ||
38560 impl == JAGUAR_IMPL ||
38561- impl == PANTHER_IMPL)) {
38562- struct cpufreq_driver *driver;
38563-
38564- ret = -ENOMEM;
38565- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
38566- if (!driver)
38567- goto err_out;
38568-
38569- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
38570- GFP_KERNEL);
38571- if (!us3_freq_table)
38572- goto err_out;
38573-
38574- driver->init = us3_freq_cpu_init;
38575- driver->verify = cpufreq_generic_frequency_table_verify;
38576- driver->target_index = us3_freq_target;
38577- driver->get = us3_freq_get;
38578- driver->exit = us3_freq_cpu_exit;
38579- strcpy(driver->name, "UltraSPARC-III");
38580-
38581- cpufreq_us3_driver = driver;
38582- ret = cpufreq_register_driver(driver);
38583- if (ret)
38584- goto err_out;
38585-
38586- return 0;
38587-
38588-err_out:
38589- if (driver) {
38590- kfree(driver);
38591- cpufreq_us3_driver = NULL;
38592- }
38593- kfree(us3_freq_table);
38594- us3_freq_table = NULL;
38595- return ret;
38596- }
38597+ impl == PANTHER_IMPL))
38598+ return cpufreq_register_driver(&cpufreq_us3_driver);
38599
38600 return -ENODEV;
38601 }
38602
38603 static void __exit us3_freq_exit(void)
38604 {
38605- if (cpufreq_us3_driver) {
38606- cpufreq_unregister_driver(cpufreq_us3_driver);
38607- kfree(cpufreq_us3_driver);
38608- cpufreq_us3_driver = NULL;
38609- kfree(us3_freq_table);
38610- us3_freq_table = NULL;
38611- }
38612+ cpufreq_unregister_driver(&cpufreq_us3_driver);
38613 }
38614
38615 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
38616diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
38617index 4e1daca..e707b61 100644
38618--- a/drivers/cpufreq/speedstep-centrino.c
38619+++ b/drivers/cpufreq/speedstep-centrino.c
38620@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
38621 !cpu_has(cpu, X86_FEATURE_EST))
38622 return -ENODEV;
38623
38624- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
38625- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
38626+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
38627+ pax_open_kernel();
38628+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
38629+ pax_close_kernel();
38630+ }
38631
38632 if (policy->cpu != 0)
38633 return -ENODEV;
38634diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
38635index 06dbe7c..c2c8671 100644
38636--- a/drivers/cpuidle/driver.c
38637+++ b/drivers/cpuidle/driver.c
38638@@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
38639
38640 static void poll_idle_init(struct cpuidle_driver *drv)
38641 {
38642- struct cpuidle_state *state = &drv->states[0];
38643+ cpuidle_state_no_const *state = &drv->states[0];
38644
38645 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
38646 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
38647diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
38648index ca89412..a7b9c49 100644
38649--- a/drivers/cpuidle/governor.c
38650+++ b/drivers/cpuidle/governor.c
38651@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
38652 mutex_lock(&cpuidle_lock);
38653 if (__cpuidle_find_governor(gov->name) == NULL) {
38654 ret = 0;
38655- list_add_tail(&gov->governor_list, &cpuidle_governors);
38656+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
38657 if (!cpuidle_curr_governor ||
38658 cpuidle_curr_governor->rating < gov->rating)
38659 cpuidle_switch_governor(gov);
38660diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
38661index e918b6d..f87ea80 100644
38662--- a/drivers/cpuidle/sysfs.c
38663+++ b/drivers/cpuidle/sysfs.c
38664@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
38665 NULL
38666 };
38667
38668-static struct attribute_group cpuidle_attr_group = {
38669+static attribute_group_no_const cpuidle_attr_group = {
38670 .attrs = cpuidle_default_attrs,
38671 .name = "cpuidle",
38672 };
38673diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
38674index 12fea3e..1e28f47 100644
38675--- a/drivers/crypto/hifn_795x.c
38676+++ b/drivers/crypto/hifn_795x.c
38677@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
38678 MODULE_PARM_DESC(hifn_pll_ref,
38679 "PLL reference clock (pci[freq] or ext[freq], default ext)");
38680
38681-static atomic_t hifn_dev_number;
38682+static atomic_unchecked_t hifn_dev_number;
38683
38684 #define ACRYPTO_OP_DECRYPT 0
38685 #define ACRYPTO_OP_ENCRYPT 1
38686@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
38687 goto err_out_disable_pci_device;
38688
38689 snprintf(name, sizeof(name), "hifn%d",
38690- atomic_inc_return(&hifn_dev_number)-1);
38691+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
38692
38693 err = pci_request_regions(pdev, name);
38694 if (err)
38695diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
38696index a0b2f7e..1b6f028 100644
38697--- a/drivers/devfreq/devfreq.c
38698+++ b/drivers/devfreq/devfreq.c
38699@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
38700 goto err_out;
38701 }
38702
38703- list_add(&governor->node, &devfreq_governor_list);
38704+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
38705
38706 list_for_each_entry(devfreq, &devfreq_list, node) {
38707 int ret = 0;
38708@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
38709 }
38710 }
38711
38712- list_del(&governor->node);
38713+ pax_list_del((struct list_head *)&governor->node);
38714 err_out:
38715 mutex_unlock(&devfreq_list_lock);
38716
38717diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
38718index 0d765c0..60b7480 100644
38719--- a/drivers/dma/sh/shdmac.c
38720+++ b/drivers/dma/sh/shdmac.c
38721@@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
38722 return ret;
38723 }
38724
38725-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
38726+static struct notifier_block sh_dmae_nmi_notifier = {
38727 .notifier_call = sh_dmae_nmi_handler,
38728
38729 /* Run before NMI debug handler and KGDB */
38730diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
38731index 1026743..80b081c 100644
38732--- a/drivers/edac/edac_device.c
38733+++ b/drivers/edac/edac_device.c
38734@@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
38735 */
38736 int edac_device_alloc_index(void)
38737 {
38738- static atomic_t device_indexes = ATOMIC_INIT(0);
38739+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
38740
38741- return atomic_inc_return(&device_indexes) - 1;
38742+ return atomic_inc_return_unchecked(&device_indexes) - 1;
38743 }
38744 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
38745
38746diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
38747index 9f7e0e60..348c875 100644
38748--- a/drivers/edac/edac_mc_sysfs.c
38749+++ b/drivers/edac/edac_mc_sysfs.c
38750@@ -150,7 +150,7 @@ static const char * const edac_caps[] = {
38751 struct dev_ch_attribute {
38752 struct device_attribute attr;
38753 int channel;
38754-};
38755+} __do_const;
38756
38757 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
38758 struct dev_ch_attribute dev_attr_legacy_##_name = \
38759@@ -1007,14 +1007,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
38760 }
38761
38762 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
38763+ pax_open_kernel();
38764 if (mci->get_sdram_scrub_rate) {
38765- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
38766- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
38767+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
38768+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
38769 }
38770 if (mci->set_sdram_scrub_rate) {
38771- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
38772- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
38773+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
38774+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
38775 }
38776+ pax_close_kernel();
38777 err = device_create_file(&mci->dev,
38778 &dev_attr_sdram_scrub_rate);
38779 if (err) {
38780diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
38781index 2cf44b4d..6dd2dc7 100644
38782--- a/drivers/edac/edac_pci.c
38783+++ b/drivers/edac/edac_pci.c
38784@@ -29,7 +29,7 @@
38785
38786 static DEFINE_MUTEX(edac_pci_ctls_mutex);
38787 static LIST_HEAD(edac_pci_list);
38788-static atomic_t pci_indexes = ATOMIC_INIT(0);
38789+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
38790
38791 /*
38792 * edac_pci_alloc_ctl_info
38793@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
38794 */
38795 int edac_pci_alloc_index(void)
38796 {
38797- return atomic_inc_return(&pci_indexes) - 1;
38798+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
38799 }
38800 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
38801
38802diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
38803index e8658e4..22746d6 100644
38804--- a/drivers/edac/edac_pci_sysfs.c
38805+++ b/drivers/edac/edac_pci_sysfs.c
38806@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
38807 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
38808 static int edac_pci_poll_msec = 1000; /* one second workq period */
38809
38810-static atomic_t pci_parity_count = ATOMIC_INIT(0);
38811-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
38812+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
38813+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
38814
38815 static struct kobject *edac_pci_top_main_kobj;
38816 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
38817@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
38818 void *value;
38819 ssize_t(*show) (void *, char *);
38820 ssize_t(*store) (void *, const char *, size_t);
38821-};
38822+} __do_const;
38823
38824 /* Set of show/store abstract level functions for PCI Parity object */
38825 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
38826@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38827 edac_printk(KERN_CRIT, EDAC_PCI,
38828 "Signaled System Error on %s\n",
38829 pci_name(dev));
38830- atomic_inc(&pci_nonparity_count);
38831+ atomic_inc_unchecked(&pci_nonparity_count);
38832 }
38833
38834 if (status & (PCI_STATUS_PARITY)) {
38835@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38836 "Master Data Parity Error on %s\n",
38837 pci_name(dev));
38838
38839- atomic_inc(&pci_parity_count);
38840+ atomic_inc_unchecked(&pci_parity_count);
38841 }
38842
38843 if (status & (PCI_STATUS_DETECTED_PARITY)) {
38844@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38845 "Detected Parity Error on %s\n",
38846 pci_name(dev));
38847
38848- atomic_inc(&pci_parity_count);
38849+ atomic_inc_unchecked(&pci_parity_count);
38850 }
38851 }
38852
38853@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38854 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
38855 "Signaled System Error on %s\n",
38856 pci_name(dev));
38857- atomic_inc(&pci_nonparity_count);
38858+ atomic_inc_unchecked(&pci_nonparity_count);
38859 }
38860
38861 if (status & (PCI_STATUS_PARITY)) {
38862@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38863 "Master Data Parity Error on "
38864 "%s\n", pci_name(dev));
38865
38866- atomic_inc(&pci_parity_count);
38867+ atomic_inc_unchecked(&pci_parity_count);
38868 }
38869
38870 if (status & (PCI_STATUS_DETECTED_PARITY)) {
38871@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38872 "Detected Parity Error on %s\n",
38873 pci_name(dev));
38874
38875- atomic_inc(&pci_parity_count);
38876+ atomic_inc_unchecked(&pci_parity_count);
38877 }
38878 }
38879 }
38880@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
38881 if (!check_pci_errors)
38882 return;
38883
38884- before_count = atomic_read(&pci_parity_count);
38885+ before_count = atomic_read_unchecked(&pci_parity_count);
38886
38887 /* scan all PCI devices looking for a Parity Error on devices and
38888 * bridges.
38889@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
38890 /* Only if operator has selected panic on PCI Error */
38891 if (edac_pci_get_panic_on_pe()) {
38892 /* If the count is different 'after' from 'before' */
38893- if (before_count != atomic_read(&pci_parity_count))
38894+ if (before_count != atomic_read_unchecked(&pci_parity_count))
38895 panic("EDAC: PCI Parity Error");
38896 }
38897 }
38898diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
38899index 51b7e3a..aa8a3e8 100644
38900--- a/drivers/edac/mce_amd.h
38901+++ b/drivers/edac/mce_amd.h
38902@@ -77,7 +77,7 @@ struct amd_decoder_ops {
38903 bool (*mc0_mce)(u16, u8);
38904 bool (*mc1_mce)(u16, u8);
38905 bool (*mc2_mce)(u16, u8);
38906-};
38907+} __no_const;
38908
38909 void amd_report_gart_errors(bool);
38910 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
38911diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
38912index 57ea7f4..af06b76 100644
38913--- a/drivers/firewire/core-card.c
38914+++ b/drivers/firewire/core-card.c
38915@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
38916 const struct fw_card_driver *driver,
38917 struct device *device)
38918 {
38919- static atomic_t index = ATOMIC_INIT(-1);
38920+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
38921
38922- card->index = atomic_inc_return(&index);
38923+ card->index = atomic_inc_return_unchecked(&index);
38924 card->driver = driver;
38925 card->device = device;
38926 card->current_tlabel = 0;
38927@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
38928
38929 void fw_core_remove_card(struct fw_card *card)
38930 {
38931- struct fw_card_driver dummy_driver = dummy_driver_template;
38932+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
38933
38934 card->driver->update_phy_reg(card, 4,
38935 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
38936diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
38937index de4aa40..49ab1f2 100644
38938--- a/drivers/firewire/core-device.c
38939+++ b/drivers/firewire/core-device.c
38940@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
38941 struct config_rom_attribute {
38942 struct device_attribute attr;
38943 u32 key;
38944-};
38945+} __do_const;
38946
38947 static ssize_t show_immediate(struct device *dev,
38948 struct device_attribute *dattr, char *buf)
38949diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
38950index 0e79951..b180217 100644
38951--- a/drivers/firewire/core-transaction.c
38952+++ b/drivers/firewire/core-transaction.c
38953@@ -38,6 +38,7 @@
38954 #include <linux/timer.h>
38955 #include <linux/types.h>
38956 #include <linux/workqueue.h>
38957+#include <linux/sched.h>
38958
38959 #include <asm/byteorder.h>
38960
38961diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
38962index 515a42c..5ecf3ba 100644
38963--- a/drivers/firewire/core.h
38964+++ b/drivers/firewire/core.h
38965@@ -111,6 +111,7 @@ struct fw_card_driver {
38966
38967 int (*stop_iso)(struct fw_iso_context *ctx);
38968 };
38969+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
38970
38971 void fw_card_initialize(struct fw_card *card,
38972 const struct fw_card_driver *driver, struct device *device);
38973diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
38974index 94a58a0..f5eba42 100644
38975--- a/drivers/firmware/dmi-id.c
38976+++ b/drivers/firmware/dmi-id.c
38977@@ -16,7 +16,7 @@
38978 struct dmi_device_attribute{
38979 struct device_attribute dev_attr;
38980 int field;
38981-};
38982+} __do_const;
38983 #define to_dmi_dev_attr(_dev_attr) \
38984 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
38985
38986diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
38987index c7e81ff..94a7401 100644
38988--- a/drivers/firmware/dmi_scan.c
38989+++ b/drivers/firmware/dmi_scan.c
38990@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
38991 if (buf == NULL)
38992 return -1;
38993
38994- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
38995+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
38996
38997 iounmap(buf);
38998 return 0;
38999diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39000index 1491dd4..aa910db 100644
39001--- a/drivers/firmware/efi/cper.c
39002+++ b/drivers/firmware/efi/cper.c
39003@@ -41,12 +41,12 @@
39004 */
39005 u64 cper_next_record_id(void)
39006 {
39007- static atomic64_t seq;
39008+ static atomic64_unchecked_t seq;
39009
39010- if (!atomic64_read(&seq))
39011- atomic64_set(&seq, ((u64)get_seconds()) << 32);
39012+ if (!atomic64_read_unchecked(&seq))
39013+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39014
39015- return atomic64_inc_return(&seq);
39016+ return atomic64_inc_return_unchecked(&seq);
39017 }
39018 EXPORT_SYMBOL_GPL(cper_next_record_id);
39019
39020diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39021index 2e2fbde..7676c8b 100644
39022--- a/drivers/firmware/efi/efi.c
39023+++ b/drivers/firmware/efi/efi.c
39024@@ -81,14 +81,16 @@ static struct attribute_group efi_subsys_attr_group = {
39025 };
39026
39027 static struct efivars generic_efivars;
39028-static struct efivar_operations generic_ops;
39029+static efivar_operations_no_const generic_ops __read_only;
39030
39031 static int generic_ops_register(void)
39032 {
39033- generic_ops.get_variable = efi.get_variable;
39034- generic_ops.set_variable = efi.set_variable;
39035- generic_ops.get_next_variable = efi.get_next_variable;
39036- generic_ops.query_variable_store = efi_query_variable_store;
39037+ pax_open_kernel();
39038+ *(void **)&generic_ops.get_variable = efi.get_variable;
39039+ *(void **)&generic_ops.set_variable = efi.set_variable;
39040+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39041+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39042+ pax_close_kernel();
39043
39044 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39045 }
39046diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39047index 3dc2482..7bd2f61 100644
39048--- a/drivers/firmware/efi/efivars.c
39049+++ b/drivers/firmware/efi/efivars.c
39050@@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39051 static int
39052 create_efivars_bin_attributes(void)
39053 {
39054- struct bin_attribute *attr;
39055+ bin_attribute_no_const *attr;
39056 int error;
39057
39058 /* new_var */
39059diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39060index 2a90ba6..07f3733 100644
39061--- a/drivers/firmware/google/memconsole.c
39062+++ b/drivers/firmware/google/memconsole.c
39063@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
39064 if (!found_memconsole())
39065 return -ENODEV;
39066
39067- memconsole_bin_attr.size = memconsole_length;
39068+ pax_open_kernel();
39069+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39070+ pax_close_kernel();
39071
39072 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39073
39074diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39075index 814addb..0937d7f 100644
39076--- a/drivers/gpio/gpio-ich.c
39077+++ b/drivers/gpio/gpio-ich.c
39078@@ -71,7 +71,7 @@ struct ichx_desc {
39079 /* Some chipsets have quirks, let these use their own request/get */
39080 int (*request)(struct gpio_chip *chip, unsigned offset);
39081 int (*get)(struct gpio_chip *chip, unsigned offset);
39082-};
39083+} __do_const;
39084
39085 static struct {
39086 spinlock_t lock;
39087diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39088index 9902732..64b62dd 100644
39089--- a/drivers/gpio/gpio-vr41xx.c
39090+++ b/drivers/gpio/gpio-vr41xx.c
39091@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
39092 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39093 maskl, pendl, maskh, pendh);
39094
39095- atomic_inc(&irq_err_count);
39096+ atomic_inc_unchecked(&irq_err_count);
39097
39098 return -EINVAL;
39099 }
39100diff --git a/drivers/gpu/drm/armada/armada_drv.c b/drivers/gpu/drm/armada/armada_drv.c
39101index 62d0ff3..073dbf3 100644
39102--- a/drivers/gpu/drm/armada/armada_drv.c
39103+++ b/drivers/gpu/drm/armada/armada_drv.c
39104@@ -68,15 +68,7 @@ void __armada_drm_queue_unref_work(struct drm_device *dev,
39105 {
39106 struct armada_private *priv = dev->dev_private;
39107
39108- /*
39109- * Yes, we really must jump through these hoops just to store a
39110- * _pointer_ to something into the kfifo. This is utterly insane
39111- * and idiotic, because it kfifo requires the _data_ pointed to by
39112- * the pointer const, not the pointer itself. Not only that, but
39113- * you have to pass a pointer _to_ the pointer you want stored.
39114- */
39115- const struct drm_framebuffer *silly_api_alert = fb;
39116- WARN_ON(!kfifo_put(&priv->fb_unref, &silly_api_alert));
39117+ WARN_ON(!kfifo_put(&priv->fb_unref, fb));
39118 schedule_work(&priv->fb_unref_work);
39119 }
39120
39121diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
39122index d6cf77c..2842146 100644
39123--- a/drivers/gpu/drm/drm_crtc.c
39124+++ b/drivers/gpu/drm/drm_crtc.c
39125@@ -3102,7 +3102,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
39126 goto done;
39127 }
39128
39129- if (copy_to_user(&enum_ptr[copied].name,
39130+ if (copy_to_user(enum_ptr[copied].name,
39131 &prop_enum->name, DRM_PROP_NAME_LEN)) {
39132 ret = -EFAULT;
39133 goto done;
39134diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
39135index 01361ab..891e821 100644
39136--- a/drivers/gpu/drm/drm_crtc_helper.c
39137+++ b/drivers/gpu/drm/drm_crtc_helper.c
39138@@ -338,7 +338,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
39139 struct drm_crtc *tmp;
39140 int crtc_mask = 1;
39141
39142- WARN(!crtc, "checking null crtc?\n");
39143+ BUG_ON(!crtc);
39144
39145 dev = crtc->dev;
39146
39147diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
39148index d9137e4..69b73a0 100644
39149--- a/drivers/gpu/drm/drm_drv.c
39150+++ b/drivers/gpu/drm/drm_drv.c
39151@@ -233,7 +233,7 @@ module_exit(drm_core_exit);
39152 /**
39153 * Copy and IOCTL return string to user space
39154 */
39155-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
39156+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
39157 {
39158 int len;
39159
39160@@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
39161 struct drm_file *file_priv = filp->private_data;
39162 struct drm_device *dev;
39163 const struct drm_ioctl_desc *ioctl = NULL;
39164- drm_ioctl_t *func;
39165+ drm_ioctl_no_const_t func;
39166 unsigned int nr = DRM_IOCTL_NR(cmd);
39167 int retcode = -EINVAL;
39168 char stack_kdata[128];
39169diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
39170index c5b929c..8a3b8be 100644
39171--- a/drivers/gpu/drm/drm_fops.c
39172+++ b/drivers/gpu/drm/drm_fops.c
39173@@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
39174 if (drm_device_is_unplugged(dev))
39175 return -ENODEV;
39176
39177- if (!dev->open_count++)
39178+ if (local_inc_return(&dev->open_count) == 1)
39179 need_setup = 1;
39180 mutex_lock(&dev->struct_mutex);
39181 old_imapping = inode->i_mapping;
39182@@ -127,7 +127,7 @@ err_undo:
39183 iput(container_of(dev->dev_mapping, struct inode, i_data));
39184 dev->dev_mapping = old_mapping;
39185 mutex_unlock(&dev->struct_mutex);
39186- dev->open_count--;
39187+ local_dec(&dev->open_count);
39188 return retcode;
39189 }
39190 EXPORT_SYMBOL(drm_open);
39191@@ -467,7 +467,7 @@ int drm_release(struct inode *inode, struct file *filp)
39192
39193 mutex_lock(&drm_global_mutex);
39194
39195- DRM_DEBUG("open_count = %d\n", dev->open_count);
39196+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
39197
39198 if (dev->driver->preclose)
39199 dev->driver->preclose(dev, file_priv);
39200@@ -476,10 +476,10 @@ int drm_release(struct inode *inode, struct file *filp)
39201 * Begin inline drm_release
39202 */
39203
39204- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
39205+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
39206 task_pid_nr(current),
39207 (long)old_encode_dev(file_priv->minor->device),
39208- dev->open_count);
39209+ local_read(&dev->open_count));
39210
39211 /* Release any auth tokens that might point to this file_priv,
39212 (do that under the drm_global_mutex) */
39213@@ -577,7 +577,7 @@ int drm_release(struct inode *inode, struct file *filp)
39214 * End inline drm_release
39215 */
39216
39217- if (!--dev->open_count) {
39218+ if (local_dec_and_test(&dev->open_count)) {
39219 if (atomic_read(&dev->ioctl_count)) {
39220 DRM_ERROR("Device busy: %d\n",
39221 atomic_read(&dev->ioctl_count));
39222diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
39223index 3d2e91c..d31c4c9 100644
39224--- a/drivers/gpu/drm/drm_global.c
39225+++ b/drivers/gpu/drm/drm_global.c
39226@@ -36,7 +36,7 @@
39227 struct drm_global_item {
39228 struct mutex mutex;
39229 void *object;
39230- int refcount;
39231+ atomic_t refcount;
39232 };
39233
39234 static struct drm_global_item glob[DRM_GLOBAL_NUM];
39235@@ -49,7 +49,7 @@ void drm_global_init(void)
39236 struct drm_global_item *item = &glob[i];
39237 mutex_init(&item->mutex);
39238 item->object = NULL;
39239- item->refcount = 0;
39240+ atomic_set(&item->refcount, 0);
39241 }
39242 }
39243
39244@@ -59,7 +59,7 @@ void drm_global_release(void)
39245 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
39246 struct drm_global_item *item = &glob[i];
39247 BUG_ON(item->object != NULL);
39248- BUG_ON(item->refcount != 0);
39249+ BUG_ON(atomic_read(&item->refcount) != 0);
39250 }
39251 }
39252
39253@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39254 struct drm_global_item *item = &glob[ref->global_type];
39255
39256 mutex_lock(&item->mutex);
39257- if (item->refcount == 0) {
39258+ if (atomic_read(&item->refcount) == 0) {
39259 item->object = kzalloc(ref->size, GFP_KERNEL);
39260 if (unlikely(item->object == NULL)) {
39261 ret = -ENOMEM;
39262@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39263 goto out_err;
39264
39265 }
39266- ++item->refcount;
39267+ atomic_inc(&item->refcount);
39268 ref->object = item->object;
39269 mutex_unlock(&item->mutex);
39270 return 0;
39271@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
39272 struct drm_global_item *item = &glob[ref->global_type];
39273
39274 mutex_lock(&item->mutex);
39275- BUG_ON(item->refcount == 0);
39276+ BUG_ON(atomic_read(&item->refcount) == 0);
39277 BUG_ON(ref->object != item->object);
39278- if (--item->refcount == 0) {
39279+ if (atomic_dec_and_test(&item->refcount)) {
39280 ref->release(ref);
39281 item->object = NULL;
39282 }
39283diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
39284index 7d5a152..d7186da 100644
39285--- a/drivers/gpu/drm/drm_info.c
39286+++ b/drivers/gpu/drm/drm_info.c
39287@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
39288 struct drm_local_map *map;
39289 struct drm_map_list *r_list;
39290
39291- /* Hardcoded from _DRM_FRAME_BUFFER,
39292- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
39293- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
39294- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
39295+ static const char * const types[] = {
39296+ [_DRM_FRAME_BUFFER] = "FB",
39297+ [_DRM_REGISTERS] = "REG",
39298+ [_DRM_SHM] = "SHM",
39299+ [_DRM_AGP] = "AGP",
39300+ [_DRM_SCATTER_GATHER] = "SG",
39301+ [_DRM_CONSISTENT] = "PCI",
39302+ [_DRM_GEM] = "GEM" };
39303 const char *type;
39304 int i;
39305
39306@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
39307 map = r_list->map;
39308 if (!map)
39309 continue;
39310- if (map->type < 0 || map->type > 5)
39311+ if (map->type >= ARRAY_SIZE(types))
39312 type = "??";
39313 else
39314 type = types[map->type];
39315@@ -257,7 +261,11 @@ int drm_vma_info(struct seq_file *m, void *data)
39316 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
39317 vma->vm_flags & VM_LOCKED ? 'l' : '-',
39318 vma->vm_flags & VM_IO ? 'i' : '-',
39319+#ifdef CONFIG_GRKERNSEC_HIDESYM
39320+ 0);
39321+#else
39322 vma->vm_pgoff);
39323+#endif
39324
39325 #if defined(__i386__)
39326 pgprot = pgprot_val(vma->vm_page_prot);
39327diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
39328index 2f4c434..dd12cd2 100644
39329--- a/drivers/gpu/drm/drm_ioc32.c
39330+++ b/drivers/gpu/drm/drm_ioc32.c
39331@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
39332 request = compat_alloc_user_space(nbytes);
39333 if (!access_ok(VERIFY_WRITE, request, nbytes))
39334 return -EFAULT;
39335- list = (struct drm_buf_desc *) (request + 1);
39336+ list = (struct drm_buf_desc __user *) (request + 1);
39337
39338 if (__put_user(count, &request->count)
39339 || __put_user(list, &request->list))
39340@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
39341 request = compat_alloc_user_space(nbytes);
39342 if (!access_ok(VERIFY_WRITE, request, nbytes))
39343 return -EFAULT;
39344- list = (struct drm_buf_pub *) (request + 1);
39345+ list = (struct drm_buf_pub __user *) (request + 1);
39346
39347 if (__put_user(count, &request->count)
39348 || __put_user(list, &request->list))
39349@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
39350 return 0;
39351 }
39352
39353-drm_ioctl_compat_t *drm_compat_ioctls[] = {
39354+drm_ioctl_compat_t drm_compat_ioctls[] = {
39355 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
39356 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
39357 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
39358@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
39359 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39360 {
39361 unsigned int nr = DRM_IOCTL_NR(cmd);
39362- drm_ioctl_compat_t *fn;
39363 int ret;
39364
39365 /* Assume that ioctls without an explicit compat routine will just
39366@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39367 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
39368 return drm_ioctl(filp, cmd, arg);
39369
39370- fn = drm_compat_ioctls[nr];
39371-
39372- if (fn != NULL)
39373- ret = (*fn) (filp, cmd, arg);
39374+ if (drm_compat_ioctls[nr] != NULL)
39375+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
39376 else
39377 ret = drm_ioctl(filp, cmd, arg);
39378
39379diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
39380index 66dd3a0..3bed6c4 100644
39381--- a/drivers/gpu/drm/drm_stub.c
39382+++ b/drivers/gpu/drm/drm_stub.c
39383@@ -403,7 +403,7 @@ void drm_unplug_dev(struct drm_device *dev)
39384
39385 drm_device_set_unplugged(dev);
39386
39387- if (dev->open_count == 0) {
39388+ if (local_read(&dev->open_count) == 0) {
39389 drm_put_dev(dev);
39390 }
39391 mutex_unlock(&drm_global_mutex);
39392diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
39393index c22c309..ae758c3 100644
39394--- a/drivers/gpu/drm/drm_sysfs.c
39395+++ b/drivers/gpu/drm/drm_sysfs.c
39396@@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
39397 */
39398 int drm_sysfs_device_add(struct drm_minor *minor)
39399 {
39400- char *minor_str;
39401+ const char *minor_str;
39402 int r;
39403
39404 if (minor->type == DRM_MINOR_CONTROL)
39405diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
39406index d4d16ed..8fb0b51 100644
39407--- a/drivers/gpu/drm/i810/i810_drv.h
39408+++ b/drivers/gpu/drm/i810/i810_drv.h
39409@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
39410 int page_flipping;
39411
39412 wait_queue_head_t irq_queue;
39413- atomic_t irq_received;
39414- atomic_t irq_emitted;
39415+ atomic_unchecked_t irq_received;
39416+ atomic_unchecked_t irq_emitted;
39417
39418 int front_offset;
39419 } drm_i810_private_t;
39420diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
39421index 6ed45a9..eb6dc41 100644
39422--- a/drivers/gpu/drm/i915/i915_debugfs.c
39423+++ b/drivers/gpu/drm/i915/i915_debugfs.c
39424@@ -702,7 +702,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
39425 I915_READ(GTIMR));
39426 }
39427 seq_printf(m, "Interrupts received: %d\n",
39428- atomic_read(&dev_priv->irq_received));
39429+ atomic_read_unchecked(&dev_priv->irq_received));
39430 for_each_ring(ring, dev_priv, i) {
39431 if (INTEL_INFO(dev)->gen >= 6) {
39432 seq_printf(m,
39433diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
39434index 5c64842..f14bdf8 100644
39435--- a/drivers/gpu/drm/i915/i915_dma.c
39436+++ b/drivers/gpu/drm/i915/i915_dma.c
39437@@ -1271,7 +1271,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
39438 bool can_switch;
39439
39440 spin_lock(&dev->count_lock);
39441- can_switch = (dev->open_count == 0);
39442+ can_switch = (local_read(&dev->open_count) == 0);
39443 spin_unlock(&dev->count_lock);
39444 return can_switch;
39445 }
39446diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
39447index 90fcccb..b8aabc9 100644
39448--- a/drivers/gpu/drm/i915/i915_drv.h
39449+++ b/drivers/gpu/drm/i915/i915_drv.h
39450@@ -1325,7 +1325,7 @@ typedef struct drm_i915_private {
39451 drm_dma_handle_t *status_page_dmah;
39452 struct resource mch_res;
39453
39454- atomic_t irq_received;
39455+ atomic_unchecked_t irq_received;
39456
39457 /* protects the irq masks */
39458 spinlock_t irq_lock;
39459diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
39460index a3ba9a8..ee52ddd 100644
39461--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
39462+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
39463@@ -861,9 +861,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
39464
39465 static int
39466 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
39467- int count)
39468+ unsigned int count)
39469 {
39470- int i;
39471+ unsigned int i;
39472 unsigned relocs_total = 0;
39473 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
39474
39475diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
39476index 3c59584..500f2e9 100644
39477--- a/drivers/gpu/drm/i915/i915_ioc32.c
39478+++ b/drivers/gpu/drm/i915/i915_ioc32.c
39479@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
39480 (unsigned long)request);
39481 }
39482
39483-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
39484+static drm_ioctl_compat_t i915_compat_ioctls[] = {
39485 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
39486 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
39487 [DRM_I915_GETPARAM] = compat_i915_getparam,
39488@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
39489 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39490 {
39491 unsigned int nr = DRM_IOCTL_NR(cmd);
39492- drm_ioctl_compat_t *fn = NULL;
39493 int ret;
39494
39495 if (nr < DRM_COMMAND_BASE)
39496 return drm_compat_ioctl(filp, cmd, arg);
39497
39498- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
39499- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
39500-
39501- if (fn != NULL)
39502+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
39503+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
39504 ret = (*fn) (filp, cmd, arg);
39505- else
39506+ } else
39507 ret = drm_ioctl(filp, cmd, arg);
39508
39509 return ret;
39510diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
39511index f13d5ed..8e6f36d 100644
39512--- a/drivers/gpu/drm/i915/i915_irq.c
39513+++ b/drivers/gpu/drm/i915/i915_irq.c
39514@@ -1420,7 +1420,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
39515 int pipe;
39516 u32 pipe_stats[I915_MAX_PIPES];
39517
39518- atomic_inc(&dev_priv->irq_received);
39519+ atomic_inc_unchecked(&dev_priv->irq_received);
39520
39521 while (true) {
39522 iir = I915_READ(VLV_IIR);
39523@@ -1730,7 +1730,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
39524 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
39525 irqreturn_t ret = IRQ_NONE;
39526
39527- atomic_inc(&dev_priv->irq_received);
39528+ atomic_inc_unchecked(&dev_priv->irq_received);
39529
39530 /* We get interrupts on unclaimed registers, so check for this before we
39531 * do any I915_{READ,WRITE}. */
39532@@ -1800,7 +1800,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
39533 uint32_t tmp = 0;
39534 enum pipe pipe;
39535
39536- atomic_inc(&dev_priv->irq_received);
39537+ atomic_inc_unchecked(&dev_priv->irq_received);
39538
39539 master_ctl = I915_READ(GEN8_MASTER_IRQ);
39540 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
39541@@ -2624,7 +2624,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
39542 {
39543 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39544
39545- atomic_set(&dev_priv->irq_received, 0);
39546+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39547
39548 I915_WRITE(HWSTAM, 0xeffe);
39549
39550@@ -2642,7 +2642,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
39551 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39552 int pipe;
39553
39554- atomic_set(&dev_priv->irq_received, 0);
39555+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39556
39557 /* VLV magic */
39558 I915_WRITE(VLV_IMR, 0);
39559@@ -2673,7 +2673,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
39560 struct drm_i915_private *dev_priv = dev->dev_private;
39561 int pipe;
39562
39563- atomic_set(&dev_priv->irq_received, 0);
39564+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39565
39566 I915_WRITE(GEN8_MASTER_IRQ, 0);
39567 POSTING_READ(GEN8_MASTER_IRQ);
39568@@ -2999,7 +2999,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
39569 if (!dev_priv)
39570 return;
39571
39572- atomic_set(&dev_priv->irq_received, 0);
39573+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39574
39575 I915_WRITE(GEN8_MASTER_IRQ, 0);
39576
39577@@ -3093,7 +3093,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
39578 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39579 int pipe;
39580
39581- atomic_set(&dev_priv->irq_received, 0);
39582+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39583
39584 for_each_pipe(pipe)
39585 I915_WRITE(PIPESTAT(pipe), 0);
39586@@ -3179,7 +3179,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
39587 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
39588 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39589
39590- atomic_inc(&dev_priv->irq_received);
39591+ atomic_inc_unchecked(&dev_priv->irq_received);
39592
39593 iir = I915_READ16(IIR);
39594 if (iir == 0)
39595@@ -3254,7 +3254,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
39596 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39597 int pipe;
39598
39599- atomic_set(&dev_priv->irq_received, 0);
39600+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39601
39602 if (I915_HAS_HOTPLUG(dev)) {
39603 I915_WRITE(PORT_HOTPLUG_EN, 0);
39604@@ -3361,7 +3361,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
39605 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39606 int pipe, ret = IRQ_NONE;
39607
39608- atomic_inc(&dev_priv->irq_received);
39609+ atomic_inc_unchecked(&dev_priv->irq_received);
39610
39611 iir = I915_READ(IIR);
39612 do {
39613@@ -3488,7 +3488,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
39614 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39615 int pipe;
39616
39617- atomic_set(&dev_priv->irq_received, 0);
39618+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39619
39620 I915_WRITE(PORT_HOTPLUG_EN, 0);
39621 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
39622@@ -3604,7 +3604,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
39623 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
39624 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39625
39626- atomic_inc(&dev_priv->irq_received);
39627+ atomic_inc_unchecked(&dev_priv->irq_received);
39628
39629 iir = I915_READ(IIR);
39630
39631diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
39632index 2bde35d..529646c 100644
39633--- a/drivers/gpu/drm/i915/intel_display.c
39634+++ b/drivers/gpu/drm/i915/intel_display.c
39635@@ -10492,13 +10492,13 @@ struct intel_quirk {
39636 int subsystem_vendor;
39637 int subsystem_device;
39638 void (*hook)(struct drm_device *dev);
39639-};
39640+} __do_const;
39641
39642 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
39643 struct intel_dmi_quirk {
39644 void (*hook)(struct drm_device *dev);
39645 const struct dmi_system_id (*dmi_id_list)[];
39646-};
39647+} __do_const;
39648
39649 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
39650 {
39651@@ -10506,18 +10506,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
39652 return 1;
39653 }
39654
39655-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
39656+static const struct dmi_system_id intel_dmi_quirks_table[] = {
39657 {
39658- .dmi_id_list = &(const struct dmi_system_id[]) {
39659- {
39660- .callback = intel_dmi_reverse_brightness,
39661- .ident = "NCR Corporation",
39662- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
39663- DMI_MATCH(DMI_PRODUCT_NAME, ""),
39664- },
39665- },
39666- { } /* terminating entry */
39667+ .callback = intel_dmi_reverse_brightness,
39668+ .ident = "NCR Corporation",
39669+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
39670+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
39671 },
39672+ },
39673+ { } /* terminating entry */
39674+};
39675+
39676+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
39677+ {
39678+ .dmi_id_list = &intel_dmi_quirks_table,
39679 .hook = quirk_invert_brightness,
39680 },
39681 };
39682diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
39683index ca4bc54..ee598a2 100644
39684--- a/drivers/gpu/drm/mga/mga_drv.h
39685+++ b/drivers/gpu/drm/mga/mga_drv.h
39686@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
39687 u32 clear_cmd;
39688 u32 maccess;
39689
39690- atomic_t vbl_received; /**< Number of vblanks received. */
39691+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
39692 wait_queue_head_t fence_queue;
39693- atomic_t last_fence_retired;
39694+ atomic_unchecked_t last_fence_retired;
39695 u32 next_fence_to_post;
39696
39697 unsigned int fb_cpp;
39698diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
39699index 709e90d..89a1c0d 100644
39700--- a/drivers/gpu/drm/mga/mga_ioc32.c
39701+++ b/drivers/gpu/drm/mga/mga_ioc32.c
39702@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
39703 return 0;
39704 }
39705
39706-drm_ioctl_compat_t *mga_compat_ioctls[] = {
39707+drm_ioctl_compat_t mga_compat_ioctls[] = {
39708 [DRM_MGA_INIT] = compat_mga_init,
39709 [DRM_MGA_GETPARAM] = compat_mga_getparam,
39710 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
39711@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
39712 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39713 {
39714 unsigned int nr = DRM_IOCTL_NR(cmd);
39715- drm_ioctl_compat_t *fn = NULL;
39716 int ret;
39717
39718 if (nr < DRM_COMMAND_BASE)
39719 return drm_compat_ioctl(filp, cmd, arg);
39720
39721- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
39722- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
39723-
39724- if (fn != NULL)
39725+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
39726+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
39727 ret = (*fn) (filp, cmd, arg);
39728- else
39729+ } else
39730 ret = drm_ioctl(filp, cmd, arg);
39731
39732 return ret;
39733diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
39734index 2b0ceb8..517e99e 100644
39735--- a/drivers/gpu/drm/mga/mga_irq.c
39736+++ b/drivers/gpu/drm/mga/mga_irq.c
39737@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
39738 if (crtc != 0)
39739 return 0;
39740
39741- return atomic_read(&dev_priv->vbl_received);
39742+ return atomic_read_unchecked(&dev_priv->vbl_received);
39743 }
39744
39745
39746@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
39747 /* VBLANK interrupt */
39748 if (status & MGA_VLINEPEN) {
39749 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
39750- atomic_inc(&dev_priv->vbl_received);
39751+ atomic_inc_unchecked(&dev_priv->vbl_received);
39752 drm_handle_vblank(dev, 0);
39753 handled = 1;
39754 }
39755@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
39756 if ((prim_start & ~0x03) != (prim_end & ~0x03))
39757 MGA_WRITE(MGA_PRIMEND, prim_end);
39758
39759- atomic_inc(&dev_priv->last_fence_retired);
39760+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
39761 DRM_WAKEUP(&dev_priv->fence_queue);
39762 handled = 1;
39763 }
39764@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
39765 * using fences.
39766 */
39767 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
39768- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
39769+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
39770 - *sequence) <= (1 << 23)));
39771
39772 *sequence = cur_fence;
39773diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
39774index 4c3feaa..26391ce 100644
39775--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
39776+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
39777@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
39778 struct bit_table {
39779 const char id;
39780 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
39781-};
39782+} __no_const;
39783
39784 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
39785
39786diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
39787index 4b0fb6c..67667a9 100644
39788--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
39789+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
39790@@ -96,7 +96,6 @@ struct nouveau_drm {
39791 struct drm_global_reference mem_global_ref;
39792 struct ttm_bo_global_ref bo_global_ref;
39793 struct ttm_bo_device bdev;
39794- atomic_t validate_sequence;
39795 int (*move)(struct nouveau_channel *,
39796 struct ttm_buffer_object *,
39797 struct ttm_mem_reg *, struct ttm_mem_reg *);
39798diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39799index c1a7e5a..38b8539 100644
39800--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39801+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39802@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
39803 unsigned long arg)
39804 {
39805 unsigned int nr = DRM_IOCTL_NR(cmd);
39806- drm_ioctl_compat_t *fn = NULL;
39807+ drm_ioctl_compat_t fn = NULL;
39808 int ret;
39809
39810 if (nr < DRM_COMMAND_BASE)
39811diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
39812index 19e3757..ad16478 100644
39813--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
39814+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
39815@@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
39816 }
39817
39818 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
39819- nouveau_vram_manager_init,
39820- nouveau_vram_manager_fini,
39821- nouveau_vram_manager_new,
39822- nouveau_vram_manager_del,
39823- nouveau_vram_manager_debug
39824+ .init = nouveau_vram_manager_init,
39825+ .takedown = nouveau_vram_manager_fini,
39826+ .get_node = nouveau_vram_manager_new,
39827+ .put_node = nouveau_vram_manager_del,
39828+ .debug = nouveau_vram_manager_debug
39829 };
39830
39831 static int
39832@@ -198,11 +198,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
39833 }
39834
39835 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
39836- nouveau_gart_manager_init,
39837- nouveau_gart_manager_fini,
39838- nouveau_gart_manager_new,
39839- nouveau_gart_manager_del,
39840- nouveau_gart_manager_debug
39841+ .init = nouveau_gart_manager_init,
39842+ .takedown = nouveau_gart_manager_fini,
39843+ .get_node = nouveau_gart_manager_new,
39844+ .put_node = nouveau_gart_manager_del,
39845+ .debug = nouveau_gart_manager_debug
39846 };
39847
39848 #include <core/subdev/vm/nv04.h>
39849@@ -270,11 +270,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
39850 }
39851
39852 const struct ttm_mem_type_manager_func nv04_gart_manager = {
39853- nv04_gart_manager_init,
39854- nv04_gart_manager_fini,
39855- nv04_gart_manager_new,
39856- nv04_gart_manager_del,
39857- nv04_gart_manager_debug
39858+ .init = nv04_gart_manager_init,
39859+ .takedown = nv04_gart_manager_fini,
39860+ .get_node = nv04_gart_manager_new,
39861+ .put_node = nv04_gart_manager_del,
39862+ .debug = nv04_gart_manager_debug
39863 };
39864
39865 int
39866diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
39867index 81638d7..2e45854 100644
39868--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
39869+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
39870@@ -65,7 +65,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
39871 bool can_switch;
39872
39873 spin_lock(&dev->count_lock);
39874- can_switch = (dev->open_count == 0);
39875+ can_switch = (local_read(&dev->open_count) == 0);
39876 spin_unlock(&dev->count_lock);
39877 return can_switch;
39878 }
39879diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
39880index eb89653..613cf71 100644
39881--- a/drivers/gpu/drm/qxl/qxl_cmd.c
39882+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
39883@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
39884 int ret;
39885
39886 mutex_lock(&qdev->async_io_mutex);
39887- irq_num = atomic_read(&qdev->irq_received_io_cmd);
39888+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
39889 if (qdev->last_sent_io_cmd > irq_num) {
39890 if (intr)
39891 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
39892- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39893+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39894 else
39895 ret = wait_event_timeout(qdev->io_cmd_event,
39896- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39897+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39898 /* 0 is timeout, just bail the "hw" has gone away */
39899 if (ret <= 0)
39900 goto out;
39901- irq_num = atomic_read(&qdev->irq_received_io_cmd);
39902+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
39903 }
39904 outb(val, addr);
39905 qdev->last_sent_io_cmd = irq_num + 1;
39906 if (intr)
39907 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
39908- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39909+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39910 else
39911 ret = wait_event_timeout(qdev->io_cmd_event,
39912- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39913+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39914 out:
39915 if (ret > 0)
39916 ret = 0;
39917diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
39918index c3c2bbd..bc3c0fb 100644
39919--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
39920+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
39921@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
39922 struct drm_info_node *node = (struct drm_info_node *) m->private;
39923 struct qxl_device *qdev = node->minor->dev->dev_private;
39924
39925- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
39926- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
39927- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
39928- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
39929+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
39930+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
39931+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
39932+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
39933 seq_printf(m, "%d\n", qdev->irq_received_error);
39934 return 0;
39935 }
39936diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
39937index 7bda32f..dd98fc5 100644
39938--- a/drivers/gpu/drm/qxl/qxl_drv.h
39939+++ b/drivers/gpu/drm/qxl/qxl_drv.h
39940@@ -290,10 +290,10 @@ struct qxl_device {
39941 unsigned int last_sent_io_cmd;
39942
39943 /* interrupt handling */
39944- atomic_t irq_received;
39945- atomic_t irq_received_display;
39946- atomic_t irq_received_cursor;
39947- atomic_t irq_received_io_cmd;
39948+ atomic_unchecked_t irq_received;
39949+ atomic_unchecked_t irq_received_display;
39950+ atomic_unchecked_t irq_received_cursor;
39951+ atomic_unchecked_t irq_received_io_cmd;
39952 unsigned irq_received_error;
39953 wait_queue_head_t display_event;
39954 wait_queue_head_t cursor_event;
39955diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
39956index 7b95c75..9cffb4f 100644
39957--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
39958+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
39959@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
39960
39961 /* TODO copy slow path code from i915 */
39962 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
39963- 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);
39964+ 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);
39965
39966 {
39967 struct qxl_drawable *draw = fb_cmd;
39968@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
39969 struct drm_qxl_reloc reloc;
39970
39971 if (DRM_COPY_FROM_USER(&reloc,
39972- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
39973+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
39974 sizeof(reloc))) {
39975 ret = -EFAULT;
39976 goto out_free_bos;
39977@@ -297,7 +297,7 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
39978 struct drm_qxl_command *commands =
39979 (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
39980
39981- if (DRM_COPY_FROM_USER(&user_cmd, &commands[cmd_num],
39982+ if (DRM_COPY_FROM_USER(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
39983 sizeof(user_cmd)))
39984 return -EFAULT;
39985
39986diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
39987index 21393dc..329f3a9 100644
39988--- a/drivers/gpu/drm/qxl/qxl_irq.c
39989+++ b/drivers/gpu/drm/qxl/qxl_irq.c
39990@@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(DRM_IRQ_ARGS)
39991
39992 pending = xchg(&qdev->ram_header->int_pending, 0);
39993
39994- atomic_inc(&qdev->irq_received);
39995+ atomic_inc_unchecked(&qdev->irq_received);
39996
39997 if (pending & QXL_INTERRUPT_DISPLAY) {
39998- atomic_inc(&qdev->irq_received_display);
39999+ atomic_inc_unchecked(&qdev->irq_received_display);
40000 wake_up_all(&qdev->display_event);
40001 qxl_queue_garbage_collect(qdev, false);
40002 }
40003 if (pending & QXL_INTERRUPT_CURSOR) {
40004- atomic_inc(&qdev->irq_received_cursor);
40005+ atomic_inc_unchecked(&qdev->irq_received_cursor);
40006 wake_up_all(&qdev->cursor_event);
40007 }
40008 if (pending & QXL_INTERRUPT_IO_CMD) {
40009- atomic_inc(&qdev->irq_received_io_cmd);
40010+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40011 wake_up_all(&qdev->io_cmd_event);
40012 }
40013 if (pending & QXL_INTERRUPT_ERROR) {
40014@@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40015 init_waitqueue_head(&qdev->io_cmd_event);
40016 INIT_WORK(&qdev->client_monitors_config_work,
40017 qxl_client_monitors_config_work_func);
40018- atomic_set(&qdev->irq_received, 0);
40019- atomic_set(&qdev->irq_received_display, 0);
40020- atomic_set(&qdev->irq_received_cursor, 0);
40021- atomic_set(&qdev->irq_received_io_cmd, 0);
40022+ atomic_set_unchecked(&qdev->irq_received, 0);
40023+ atomic_set_unchecked(&qdev->irq_received_display, 0);
40024+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40025+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40026 qdev->irq_received_error = 0;
40027 ret = drm_irq_install(qdev->ddev);
40028 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40029diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40030index c7e7e65..7dddd4d 100644
40031--- a/drivers/gpu/drm/qxl/qxl_ttm.c
40032+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40033@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40034 }
40035 }
40036
40037-static struct vm_operations_struct qxl_ttm_vm_ops;
40038+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40039 static const struct vm_operations_struct *ttm_vm_ops;
40040
40041 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40042@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40043 return r;
40044 if (unlikely(ttm_vm_ops == NULL)) {
40045 ttm_vm_ops = vma->vm_ops;
40046+ pax_open_kernel();
40047 qxl_ttm_vm_ops = *ttm_vm_ops;
40048 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40049+ pax_close_kernel();
40050 }
40051 vma->vm_ops = &qxl_ttm_vm_ops;
40052 return 0;
40053@@ -560,25 +562,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40054 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40055 {
40056 #if defined(CONFIG_DEBUG_FS)
40057- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40058- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40059- unsigned i;
40060+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40061+ {
40062+ .name = "qxl_mem_mm",
40063+ .show = &qxl_mm_dump_table,
40064+ },
40065+ {
40066+ .name = "qxl_surf_mm",
40067+ .show = &qxl_mm_dump_table,
40068+ }
40069+ };
40070
40071- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40072- if (i == 0)
40073- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40074- else
40075- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40076- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40077- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40078- qxl_mem_types_list[i].driver_features = 0;
40079- if (i == 0)
40080- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40081- else
40082- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40083+ pax_open_kernel();
40084+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40085+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40086+ pax_close_kernel();
40087
40088- }
40089- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40090+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40091 #else
40092 return 0;
40093 #endif
40094diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40095index c451257..0ad2134 100644
40096--- a/drivers/gpu/drm/r128/r128_cce.c
40097+++ b/drivers/gpu/drm/r128/r128_cce.c
40098@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40099
40100 /* GH: Simple idle check.
40101 */
40102- atomic_set(&dev_priv->idle_count, 0);
40103+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40104
40105 /* We don't support anything other than bus-mastering ring mode,
40106 * but the ring can be in either AGP or PCI space for the ring
40107diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40108index 56eb5e3..c4ec43d 100644
40109--- a/drivers/gpu/drm/r128/r128_drv.h
40110+++ b/drivers/gpu/drm/r128/r128_drv.h
40111@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40112 int is_pci;
40113 unsigned long cce_buffers_offset;
40114
40115- atomic_t idle_count;
40116+ atomic_unchecked_t idle_count;
40117
40118 int page_flipping;
40119 int current_page;
40120 u32 crtc_offset;
40121 u32 crtc_offset_cntl;
40122
40123- atomic_t vbl_received;
40124+ atomic_unchecked_t vbl_received;
40125
40126 u32 color_fmt;
40127 unsigned int front_offset;
40128diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40129index a954c54..9cc595c 100644
40130--- a/drivers/gpu/drm/r128/r128_ioc32.c
40131+++ b/drivers/gpu/drm/r128/r128_ioc32.c
40132@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40133 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40134 }
40135
40136-drm_ioctl_compat_t *r128_compat_ioctls[] = {
40137+drm_ioctl_compat_t r128_compat_ioctls[] = {
40138 [DRM_R128_INIT] = compat_r128_init,
40139 [DRM_R128_DEPTH] = compat_r128_depth,
40140 [DRM_R128_STIPPLE] = compat_r128_stipple,
40141@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40142 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40143 {
40144 unsigned int nr = DRM_IOCTL_NR(cmd);
40145- drm_ioctl_compat_t *fn = NULL;
40146 int ret;
40147
40148 if (nr < DRM_COMMAND_BASE)
40149 return drm_compat_ioctl(filp, cmd, arg);
40150
40151- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40152- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40153-
40154- if (fn != NULL)
40155+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40156+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40157 ret = (*fn) (filp, cmd, arg);
40158- else
40159+ } else
40160 ret = drm_ioctl(filp, cmd, arg);
40161
40162 return ret;
40163diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40164index 2ea4f09..d391371 100644
40165--- a/drivers/gpu/drm/r128/r128_irq.c
40166+++ b/drivers/gpu/drm/r128/r128_irq.c
40167@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40168 if (crtc != 0)
40169 return 0;
40170
40171- return atomic_read(&dev_priv->vbl_received);
40172+ return atomic_read_unchecked(&dev_priv->vbl_received);
40173 }
40174
40175 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40176@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40177 /* VBLANK interrupt */
40178 if (status & R128_CRTC_VBLANK_INT) {
40179 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40180- atomic_inc(&dev_priv->vbl_received);
40181+ atomic_inc_unchecked(&dev_priv->vbl_received);
40182 drm_handle_vblank(dev, 0);
40183 return IRQ_HANDLED;
40184 }
40185diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40186index 01dd9ae..6352f04 100644
40187--- a/drivers/gpu/drm/r128/r128_state.c
40188+++ b/drivers/gpu/drm/r128/r128_state.c
40189@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40190
40191 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40192 {
40193- if (atomic_read(&dev_priv->idle_count) == 0)
40194+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40195 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40196 else
40197- atomic_set(&dev_priv->idle_count, 0);
40198+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40199 }
40200
40201 #endif
40202diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40203index af85299..ed9ac8d 100644
40204--- a/drivers/gpu/drm/radeon/mkregtable.c
40205+++ b/drivers/gpu/drm/radeon/mkregtable.c
40206@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40207 regex_t mask_rex;
40208 regmatch_t match[4];
40209 char buf[1024];
40210- size_t end;
40211+ long end;
40212 int len;
40213 int done = 0;
40214 int r;
40215 unsigned o;
40216 struct offset *offset;
40217 char last_reg_s[10];
40218- int last_reg;
40219+ unsigned long last_reg;
40220
40221 if (regcomp
40222 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40223diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40224index 39b033b..6efc056 100644
40225--- a/drivers/gpu/drm/radeon/radeon_device.c
40226+++ b/drivers/gpu/drm/radeon/radeon_device.c
40227@@ -1120,7 +1120,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40228 bool can_switch;
40229
40230 spin_lock(&dev->count_lock);
40231- can_switch = (dev->open_count == 0);
40232+ can_switch = (local_read(&dev->open_count) == 0);
40233 spin_unlock(&dev->count_lock);
40234 return can_switch;
40235 }
40236diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40237index 00e0d44..08381a4 100644
40238--- a/drivers/gpu/drm/radeon/radeon_drv.h
40239+++ b/drivers/gpu/drm/radeon/radeon_drv.h
40240@@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40241
40242 /* SW interrupt */
40243 wait_queue_head_t swi_queue;
40244- atomic_t swi_emitted;
40245+ atomic_unchecked_t swi_emitted;
40246 int vblank_crtc;
40247 uint32_t irq_enable_reg;
40248 uint32_t r500_disp_irq_reg;
40249diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40250index bdb0f93..5ff558f 100644
40251--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40252+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40253@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40254 request = compat_alloc_user_space(sizeof(*request));
40255 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
40256 || __put_user(req32.param, &request->param)
40257- || __put_user((void __user *)(unsigned long)req32.value,
40258+ || __put_user((unsigned long)req32.value,
40259 &request->value))
40260 return -EFAULT;
40261
40262@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40263 #define compat_radeon_cp_setparam NULL
40264 #endif /* X86_64 || IA64 */
40265
40266-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40267+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
40268 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
40269 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
40270 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
40271@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40272 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40273 {
40274 unsigned int nr = DRM_IOCTL_NR(cmd);
40275- drm_ioctl_compat_t *fn = NULL;
40276 int ret;
40277
40278 if (nr < DRM_COMMAND_BASE)
40279 return drm_compat_ioctl(filp, cmd, arg);
40280
40281- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
40282- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40283-
40284- if (fn != NULL)
40285+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
40286+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40287 ret = (*fn) (filp, cmd, arg);
40288- else
40289+ } else
40290 ret = drm_ioctl(filp, cmd, arg);
40291
40292 return ret;
40293diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
40294index 8d68e97..9dcfed8 100644
40295--- a/drivers/gpu/drm/radeon/radeon_irq.c
40296+++ b/drivers/gpu/drm/radeon/radeon_irq.c
40297@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
40298 unsigned int ret;
40299 RING_LOCALS;
40300
40301- atomic_inc(&dev_priv->swi_emitted);
40302- ret = atomic_read(&dev_priv->swi_emitted);
40303+ atomic_inc_unchecked(&dev_priv->swi_emitted);
40304+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
40305
40306 BEGIN_RING(4);
40307 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
40308@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
40309 drm_radeon_private_t *dev_priv =
40310 (drm_radeon_private_t *) dev->dev_private;
40311
40312- atomic_set(&dev_priv->swi_emitted, 0);
40313+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
40314 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
40315
40316 dev->max_vblank_count = 0x001fffff;
40317diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
40318index 4d20910..6726b6d 100644
40319--- a/drivers/gpu/drm/radeon/radeon_state.c
40320+++ b/drivers/gpu/drm/radeon/radeon_state.c
40321@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
40322 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
40323 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
40324
40325- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40326+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40327 sarea_priv->nbox * sizeof(depth_boxes[0])))
40328 return -EFAULT;
40329
40330@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
40331 {
40332 drm_radeon_private_t *dev_priv = dev->dev_private;
40333 drm_radeon_getparam_t *param = data;
40334- int value;
40335+ int value = 0;
40336
40337 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
40338
40339diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
40340index 71245d6..94c556d 100644
40341--- a/drivers/gpu/drm/radeon/radeon_ttm.c
40342+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
40343@@ -784,7 +784,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
40344 man->size = size >> PAGE_SHIFT;
40345 }
40346
40347-static struct vm_operations_struct radeon_ttm_vm_ops;
40348+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
40349 static const struct vm_operations_struct *ttm_vm_ops = NULL;
40350
40351 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40352@@ -825,8 +825,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
40353 }
40354 if (unlikely(ttm_vm_ops == NULL)) {
40355 ttm_vm_ops = vma->vm_ops;
40356+ pax_open_kernel();
40357 radeon_ttm_vm_ops = *ttm_vm_ops;
40358 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
40359+ pax_close_kernel();
40360 }
40361 vma->vm_ops = &radeon_ttm_vm_ops;
40362 return 0;
40363@@ -855,38 +857,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
40364 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
40365 {
40366 #if defined(CONFIG_DEBUG_FS)
40367- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
40368- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
40369- unsigned i;
40370+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
40371+ {
40372+ .name = "radeon_vram_mm",
40373+ .show = &radeon_mm_dump_table,
40374+ },
40375+ {
40376+ .name = "radeon_gtt_mm",
40377+ .show = &radeon_mm_dump_table,
40378+ },
40379+ {
40380+ .name = "ttm_page_pool",
40381+ .show = &ttm_page_alloc_debugfs,
40382+ },
40383+ {
40384+ .name = "ttm_dma_page_pool",
40385+ .show = &ttm_dma_page_alloc_debugfs,
40386+ },
40387+ };
40388+ unsigned i = RADEON_DEBUGFS_MEM_TYPES + 1;
40389
40390- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
40391- if (i == 0)
40392- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
40393- else
40394- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
40395- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40396- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
40397- radeon_mem_types_list[i].driver_features = 0;
40398- if (i == 0)
40399- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
40400- else
40401- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
40402-
40403- }
40404- /* Add ttm page pool to debugfs */
40405- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
40406- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40407- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
40408- radeon_mem_types_list[i].driver_features = 0;
40409- radeon_mem_types_list[i++].data = NULL;
40410+ pax_open_kernel();
40411+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
40412+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
40413+ pax_close_kernel();
40414 #ifdef CONFIG_SWIOTLB
40415- if (swiotlb_nr_tbl()) {
40416- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
40417- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40418- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
40419- radeon_mem_types_list[i].driver_features = 0;
40420- radeon_mem_types_list[i++].data = NULL;
40421- }
40422+ if (swiotlb_nr_tbl())
40423+ i++;
40424 #endif
40425 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
40426
40427diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
40428index ae1cb31..5b5b6b7c 100644
40429--- a/drivers/gpu/drm/tegra/dc.c
40430+++ b/drivers/gpu/drm/tegra/dc.c
40431@@ -1064,7 +1064,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
40432 }
40433
40434 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
40435- dc->debugfs_files[i].data = dc;
40436+ *(void **)&dc->debugfs_files[i].data = dc;
40437
40438 err = drm_debugfs_create_files(dc->debugfs_files,
40439 ARRAY_SIZE(debugfs_files),
40440diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
40441index 0cd9bc2..9759be4 100644
40442--- a/drivers/gpu/drm/tegra/hdmi.c
40443+++ b/drivers/gpu/drm/tegra/hdmi.c
40444@@ -57,7 +57,7 @@ struct tegra_hdmi {
40445 bool stereo;
40446 bool dvi;
40447
40448- struct drm_info_list *debugfs_files;
40449+ drm_info_list_no_const *debugfs_files;
40450 struct drm_minor *minor;
40451 struct dentry *debugfs;
40452 };
40453diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
40454index c58eba33..83c2728 100644
40455--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
40456+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
40457@@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
40458 }
40459
40460 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
40461- ttm_bo_man_init,
40462- ttm_bo_man_takedown,
40463- ttm_bo_man_get_node,
40464- ttm_bo_man_put_node,
40465- ttm_bo_man_debug
40466+ .init = ttm_bo_man_init,
40467+ .takedown = ttm_bo_man_takedown,
40468+ .get_node = ttm_bo_man_get_node,
40469+ .put_node = ttm_bo_man_put_node,
40470+ .debug = ttm_bo_man_debug
40471 };
40472 EXPORT_SYMBOL(ttm_bo_manager_func);
40473diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
40474index dbc2def..0a9f710 100644
40475--- a/drivers/gpu/drm/ttm/ttm_memory.c
40476+++ b/drivers/gpu/drm/ttm/ttm_memory.c
40477@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
40478 zone->glob = glob;
40479 glob->zone_kernel = zone;
40480 ret = kobject_init_and_add(
40481- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
40482+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
40483 if (unlikely(ret != 0)) {
40484 kobject_put(&zone->kobj);
40485 return ret;
40486@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
40487 zone->glob = glob;
40488 glob->zone_dma32 = zone;
40489 ret = kobject_init_and_add(
40490- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
40491+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
40492 if (unlikely(ret != 0)) {
40493 kobject_put(&zone->kobj);
40494 return ret;
40495diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
40496index 863bef9..cba15cf 100644
40497--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
40498+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
40499@@ -391,9 +391,9 @@ out:
40500 static unsigned long
40501 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
40502 {
40503- static atomic_t start_pool = ATOMIC_INIT(0);
40504+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
40505 unsigned i;
40506- unsigned pool_offset = atomic_add_return(1, &start_pool);
40507+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
40508 struct ttm_page_pool *pool;
40509 int shrink_pages = sc->nr_to_scan;
40510 unsigned long freed = 0;
40511diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
40512index 97e9d61..bf23c461 100644
40513--- a/drivers/gpu/drm/udl/udl_fb.c
40514+++ b/drivers/gpu/drm/udl/udl_fb.c
40515@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
40516 fb_deferred_io_cleanup(info);
40517 kfree(info->fbdefio);
40518 info->fbdefio = NULL;
40519- info->fbops->fb_mmap = udl_fb_mmap;
40520 }
40521
40522 pr_warn("released /dev/fb%d user=%d count=%d\n",
40523diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
40524index a811ef2..ff99b05 100644
40525--- a/drivers/gpu/drm/via/via_drv.h
40526+++ b/drivers/gpu/drm/via/via_drv.h
40527@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
40528 typedef uint32_t maskarray_t[5];
40529
40530 typedef struct drm_via_irq {
40531- atomic_t irq_received;
40532+ atomic_unchecked_t irq_received;
40533 uint32_t pending_mask;
40534 uint32_t enable_mask;
40535 wait_queue_head_t irq_queue;
40536@@ -75,7 +75,7 @@ typedef struct drm_via_private {
40537 struct timeval last_vblank;
40538 int last_vblank_valid;
40539 unsigned usec_per_vblank;
40540- atomic_t vbl_received;
40541+ atomic_unchecked_t vbl_received;
40542 drm_via_state_t hc_state;
40543 char pci_buf[VIA_PCI_BUF_SIZE];
40544 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
40545diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
40546index ac98964..5dbf512 100644
40547--- a/drivers/gpu/drm/via/via_irq.c
40548+++ b/drivers/gpu/drm/via/via_irq.c
40549@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
40550 if (crtc != 0)
40551 return 0;
40552
40553- return atomic_read(&dev_priv->vbl_received);
40554+ return atomic_read_unchecked(&dev_priv->vbl_received);
40555 }
40556
40557 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40558@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40559
40560 status = VIA_READ(VIA_REG_INTERRUPT);
40561 if (status & VIA_IRQ_VBLANK_PENDING) {
40562- atomic_inc(&dev_priv->vbl_received);
40563- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
40564+ atomic_inc_unchecked(&dev_priv->vbl_received);
40565+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
40566 do_gettimeofday(&cur_vblank);
40567 if (dev_priv->last_vblank_valid) {
40568 dev_priv->usec_per_vblank =
40569@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40570 dev_priv->last_vblank = cur_vblank;
40571 dev_priv->last_vblank_valid = 1;
40572 }
40573- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
40574+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
40575 DRM_DEBUG("US per vblank is: %u\n",
40576 dev_priv->usec_per_vblank);
40577 }
40578@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40579
40580 for (i = 0; i < dev_priv->num_irqs; ++i) {
40581 if (status & cur_irq->pending_mask) {
40582- atomic_inc(&cur_irq->irq_received);
40583+ atomic_inc_unchecked(&cur_irq->irq_received);
40584 DRM_WAKEUP(&cur_irq->irq_queue);
40585 handled = 1;
40586 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
40587@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
40588 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
40589 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
40590 masks[irq][4]));
40591- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
40592+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
40593 } else {
40594 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
40595 (((cur_irq_sequence =
40596- atomic_read(&cur_irq->irq_received)) -
40597+ atomic_read_unchecked(&cur_irq->irq_received)) -
40598 *sequence) <= (1 << 23)));
40599 }
40600 *sequence = cur_irq_sequence;
40601@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
40602 }
40603
40604 for (i = 0; i < dev_priv->num_irqs; ++i) {
40605- atomic_set(&cur_irq->irq_received, 0);
40606+ atomic_set_unchecked(&cur_irq->irq_received, 0);
40607 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
40608 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
40609 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
40610@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
40611 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
40612 case VIA_IRQ_RELATIVE:
40613 irqwait->request.sequence +=
40614- atomic_read(&cur_irq->irq_received);
40615+ atomic_read_unchecked(&cur_irq->irq_received);
40616 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
40617 case VIA_IRQ_ABSOLUTE:
40618 break;
40619diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
40620index 20890ad..699e4f2 100644
40621--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
40622+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
40623@@ -342,7 +342,7 @@ struct vmw_private {
40624 * Fencing and IRQs.
40625 */
40626
40627- atomic_t marker_seq;
40628+ atomic_unchecked_t marker_seq;
40629 wait_queue_head_t fence_queue;
40630 wait_queue_head_t fifo_queue;
40631 int fence_queue_waiters; /* Protected by hw_mutex */
40632diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
40633index 3eb1486..0a47ee9 100644
40634--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
40635+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
40636@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
40637 (unsigned int) min,
40638 (unsigned int) fifo->capabilities);
40639
40640- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
40641+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
40642 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
40643 vmw_marker_queue_init(&fifo->marker_queue);
40644 return vmw_fifo_send_fence(dev_priv, &dummy);
40645@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
40646 if (reserveable)
40647 iowrite32(bytes, fifo_mem +
40648 SVGA_FIFO_RESERVED);
40649- return fifo_mem + (next_cmd >> 2);
40650+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
40651 } else {
40652 need_bounce = true;
40653 }
40654@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
40655
40656 fm = vmw_fifo_reserve(dev_priv, bytes);
40657 if (unlikely(fm == NULL)) {
40658- *seqno = atomic_read(&dev_priv->marker_seq);
40659+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
40660 ret = -ENOMEM;
40661 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
40662 false, 3*HZ);
40663@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
40664 }
40665
40666 do {
40667- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
40668+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
40669 } while (*seqno == 0);
40670
40671 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
40672diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
40673index c5c054a..46f0548 100644
40674--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
40675+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
40676@@ -153,9 +153,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
40677 }
40678
40679 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
40680- vmw_gmrid_man_init,
40681- vmw_gmrid_man_takedown,
40682- vmw_gmrid_man_get_node,
40683- vmw_gmrid_man_put_node,
40684- vmw_gmrid_man_debug
40685+ .init = vmw_gmrid_man_init,
40686+ .takedown = vmw_gmrid_man_takedown,
40687+ .get_node = vmw_gmrid_man_get_node,
40688+ .put_node = vmw_gmrid_man_put_node,
40689+ .debug = vmw_gmrid_man_debug
40690 };
40691diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40692index 45d5b5a..f3f5e4e 100644
40693--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40694+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40695@@ -141,7 +141,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
40696 int ret;
40697
40698 num_clips = arg->num_clips;
40699- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
40700+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
40701
40702 if (unlikely(num_clips == 0))
40703 return 0;
40704@@ -225,7 +225,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
40705 int ret;
40706
40707 num_clips = arg->num_clips;
40708- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
40709+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
40710
40711 if (unlikely(num_clips == 0))
40712 return 0;
40713diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40714index 4640adb..e1384ed 100644
40715--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40716+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40717@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
40718 * emitted. Then the fence is stale and signaled.
40719 */
40720
40721- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
40722+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
40723 > VMW_FENCE_WRAP);
40724
40725 return ret;
40726@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
40727
40728 if (fifo_idle)
40729 down_read(&fifo_state->rwsem);
40730- signal_seq = atomic_read(&dev_priv->marker_seq);
40731+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
40732 ret = 0;
40733
40734 for (;;) {
40735diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40736index 8a8725c2..afed796 100644
40737--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40738+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40739@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
40740 while (!vmw_lag_lt(queue, us)) {
40741 spin_lock(&queue->lock);
40742 if (list_empty(&queue->head))
40743- seqno = atomic_read(&dev_priv->marker_seq);
40744+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
40745 else {
40746 marker = list_first_entry(&queue->head,
40747 struct vmw_marker, head);
40748diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
40749index ec0ae2d..dc0780b 100644
40750--- a/drivers/gpu/vga/vga_switcheroo.c
40751+++ b/drivers/gpu/vga/vga_switcheroo.c
40752@@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
40753
40754 /* this version is for the case where the power switch is separate
40755 to the device being powered down. */
40756-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
40757+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
40758 {
40759 /* copy over all the bus versions */
40760 if (dev->bus && dev->bus->pm) {
40761@@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
40762 return ret;
40763 }
40764
40765-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
40766+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
40767 {
40768 /* copy over all the bus versions */
40769 if (dev->bus && dev->bus->pm) {
40770diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
40771index 253fe23..0dfec5f 100644
40772--- a/drivers/hid/hid-core.c
40773+++ b/drivers/hid/hid-core.c
40774@@ -2416,7 +2416,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
40775
40776 int hid_add_device(struct hid_device *hdev)
40777 {
40778- static atomic_t id = ATOMIC_INIT(0);
40779+ static atomic_unchecked_t id = ATOMIC_INIT(0);
40780 int ret;
40781
40782 if (WARN_ON(hdev->status & HID_STAT_ADDED))
40783@@ -2450,7 +2450,7 @@ int hid_add_device(struct hid_device *hdev)
40784 /* XXX hack, any other cleaner solution after the driver core
40785 * is converted to allow more than 20 bytes as the device name? */
40786 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
40787- hdev->vendor, hdev->product, atomic_inc_return(&id));
40788+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
40789
40790 hid_debug_register(hdev, dev_name(&hdev->dev));
40791 ret = device_add(&hdev->dev);
40792diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
40793index c13fb5b..55a3802 100644
40794--- a/drivers/hid/hid-wiimote-debug.c
40795+++ b/drivers/hid/hid-wiimote-debug.c
40796@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
40797 else if (size == 0)
40798 return -EIO;
40799
40800- if (copy_to_user(u, buf, size))
40801+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
40802 return -EFAULT;
40803
40804 *off += size;
40805diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
40806index cedc6da..2c3da2a 100644
40807--- a/drivers/hid/uhid.c
40808+++ b/drivers/hid/uhid.c
40809@@ -47,7 +47,7 @@ struct uhid_device {
40810 struct mutex report_lock;
40811 wait_queue_head_t report_wait;
40812 atomic_t report_done;
40813- atomic_t report_id;
40814+ atomic_unchecked_t report_id;
40815 struct uhid_event report_buf;
40816 };
40817
40818@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
40819
40820 spin_lock_irqsave(&uhid->qlock, flags);
40821 ev->type = UHID_FEATURE;
40822- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
40823+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
40824 ev->u.feature.rnum = rnum;
40825 ev->u.feature.rtype = report_type;
40826
40827@@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
40828 spin_lock_irqsave(&uhid->qlock, flags);
40829
40830 /* id for old report; drop it silently */
40831- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
40832+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
40833 goto unlock;
40834 if (atomic_read(&uhid->report_done))
40835 goto unlock;
40836diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
40837index cea623c..73011b0 100644
40838--- a/drivers/hv/channel.c
40839+++ b/drivers/hv/channel.c
40840@@ -362,8 +362,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
40841 int ret = 0;
40842 int t;
40843
40844- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
40845- atomic_inc(&vmbus_connection.next_gpadl_handle);
40846+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
40847+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
40848
40849 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
40850 if (ret)
40851diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
40852index f0c5e07..399256e 100644
40853--- a/drivers/hv/hv.c
40854+++ b/drivers/hv/hv.c
40855@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
40856 u64 output_address = (output) ? virt_to_phys(output) : 0;
40857 u32 output_address_hi = output_address >> 32;
40858 u32 output_address_lo = output_address & 0xFFFFFFFF;
40859- void *hypercall_page = hv_context.hypercall_page;
40860+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
40861
40862 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
40863 "=a"(hv_status_lo) : "d" (control_hi),
40864diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
40865index 7e17a54..a50a33d 100644
40866--- a/drivers/hv/hv_balloon.c
40867+++ b/drivers/hv/hv_balloon.c
40868@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
40869
40870 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
40871 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
40872-static atomic_t trans_id = ATOMIC_INIT(0);
40873+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
40874
40875 static int dm_ring_size = (5 * PAGE_SIZE);
40876
40877@@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
40878 pr_info("Memory hot add failed\n");
40879
40880 dm->state = DM_INITIALIZED;
40881- resp.hdr.trans_id = atomic_inc_return(&trans_id);
40882+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40883 vmbus_sendpacket(dm->dev->channel, &resp,
40884 sizeof(struct dm_hot_add_response),
40885 (unsigned long)NULL,
40886@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
40887 memset(&status, 0, sizeof(struct dm_status));
40888 status.hdr.type = DM_STATUS_REPORT;
40889 status.hdr.size = sizeof(struct dm_status);
40890- status.hdr.trans_id = atomic_inc_return(&trans_id);
40891+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40892
40893 /*
40894 * The host expects the guest to report free memory.
40895@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
40896 * send the status. This can happen if we were interrupted
40897 * after we picked our transaction ID.
40898 */
40899- if (status.hdr.trans_id != atomic_read(&trans_id))
40900+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
40901 return;
40902
40903 vmbus_sendpacket(dm->dev->channel, &status,
40904@@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
40905 */
40906
40907 do {
40908- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
40909+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40910 ret = vmbus_sendpacket(dm_device.dev->channel,
40911 bl_resp,
40912 bl_resp->hdr.size,
40913@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
40914
40915 memset(&resp, 0, sizeof(struct dm_unballoon_response));
40916 resp.hdr.type = DM_UNBALLOON_RESPONSE;
40917- resp.hdr.trans_id = atomic_inc_return(&trans_id);
40918+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40919 resp.hdr.size = sizeof(struct dm_unballoon_response);
40920
40921 vmbus_sendpacket(dm_device.dev->channel, &resp,
40922@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
40923 memset(&version_req, 0, sizeof(struct dm_version_request));
40924 version_req.hdr.type = DM_VERSION_REQUEST;
40925 version_req.hdr.size = sizeof(struct dm_version_request);
40926- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
40927+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40928 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
40929 version_req.is_last_attempt = 1;
40930
40931@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
40932 memset(&version_req, 0, sizeof(struct dm_version_request));
40933 version_req.hdr.type = DM_VERSION_REQUEST;
40934 version_req.hdr.size = sizeof(struct dm_version_request);
40935- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
40936+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40937 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
40938 version_req.is_last_attempt = 0;
40939
40940@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
40941 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
40942 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
40943 cap_msg.hdr.size = sizeof(struct dm_capabilities);
40944- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
40945+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40946
40947 cap_msg.caps.cap_bits.balloon = 1;
40948 cap_msg.caps.cap_bits.hot_add = 1;
40949diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
40950index e055176..c22ff1f 100644
40951--- a/drivers/hv/hyperv_vmbus.h
40952+++ b/drivers/hv/hyperv_vmbus.h
40953@@ -602,7 +602,7 @@ enum vmbus_connect_state {
40954 struct vmbus_connection {
40955 enum vmbus_connect_state conn_state;
40956
40957- atomic_t next_gpadl_handle;
40958+ atomic_unchecked_t next_gpadl_handle;
40959
40960 /*
40961 * Represents channel interrupts. Each bit position represents a
40962diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
40963index 48aad4f..c768fb2 100644
40964--- a/drivers/hv/vmbus_drv.c
40965+++ b/drivers/hv/vmbus_drv.c
40966@@ -846,10 +846,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
40967 {
40968 int ret = 0;
40969
40970- static atomic_t device_num = ATOMIC_INIT(0);
40971+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
40972
40973 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
40974- atomic_inc_return(&device_num));
40975+ atomic_inc_return_unchecked(&device_num));
40976
40977 child_device_obj->device.bus = &hv_bus;
40978 child_device_obj->device.parent = &hv_acpi_dev->dev;
40979diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
40980index 6a34f7f..aa4c3a6 100644
40981--- a/drivers/hwmon/acpi_power_meter.c
40982+++ b/drivers/hwmon/acpi_power_meter.c
40983@@ -117,7 +117,7 @@ struct sensor_template {
40984 struct device_attribute *devattr,
40985 const char *buf, size_t count);
40986 int index;
40987-};
40988+} __do_const;
40989
40990 /* Averaging interval */
40991 static int update_avg_interval(struct acpi_power_meter_resource *resource)
40992@@ -632,7 +632,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
40993 struct sensor_template *attrs)
40994 {
40995 struct device *dev = &resource->acpi_dev->dev;
40996- struct sensor_device_attribute *sensors =
40997+ sensor_device_attribute_no_const *sensors =
40998 &resource->sensors[resource->num_sensors];
40999 int res = 0;
41000
41001diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41002index 3288f13..71cfb4e 100644
41003--- a/drivers/hwmon/applesmc.c
41004+++ b/drivers/hwmon/applesmc.c
41005@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41006 {
41007 struct applesmc_node_group *grp;
41008 struct applesmc_dev_attr *node;
41009- struct attribute *attr;
41010+ attribute_no_const *attr;
41011 int ret, i;
41012
41013 for (grp = groups; grp->format; grp++) {
41014diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41015index dafc63c..4abb96c 100644
41016--- a/drivers/hwmon/asus_atk0110.c
41017+++ b/drivers/hwmon/asus_atk0110.c
41018@@ -151,10 +151,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41019 struct atk_sensor_data {
41020 struct list_head list;
41021 struct atk_data *data;
41022- struct device_attribute label_attr;
41023- struct device_attribute input_attr;
41024- struct device_attribute limit1_attr;
41025- struct device_attribute limit2_attr;
41026+ device_attribute_no_const label_attr;
41027+ device_attribute_no_const input_attr;
41028+ device_attribute_no_const limit1_attr;
41029+ device_attribute_no_const limit2_attr;
41030 char label_attr_name[ATTR_NAME_SIZE];
41031 char input_attr_name[ATTR_NAME_SIZE];
41032 char limit1_attr_name[ATTR_NAME_SIZE];
41033@@ -274,7 +274,7 @@ static ssize_t atk_name_show(struct device *dev,
41034 static struct device_attribute atk_name_attr =
41035 __ATTR(name, 0444, atk_name_show, NULL);
41036
41037-static void atk_init_attribute(struct device_attribute *attr, char *name,
41038+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41039 sysfs_show_func show)
41040 {
41041 sysfs_attr_init(&attr->attr);
41042diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41043index 9425098..7646cc5 100644
41044--- a/drivers/hwmon/coretemp.c
41045+++ b/drivers/hwmon/coretemp.c
41046@@ -797,7 +797,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41047 return NOTIFY_OK;
41048 }
41049
41050-static struct notifier_block coretemp_cpu_notifier __refdata = {
41051+static struct notifier_block coretemp_cpu_notifier = {
41052 .notifier_call = coretemp_cpu_callback,
41053 };
41054
41055diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41056index 632f1dc..57e6a58 100644
41057--- a/drivers/hwmon/ibmaem.c
41058+++ b/drivers/hwmon/ibmaem.c
41059@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41060 struct aem_rw_sensor_template *rw)
41061 {
41062 struct device *dev = &data->pdev->dev;
41063- struct sensor_device_attribute *sensors = data->sensors;
41064+ sensor_device_attribute_no_const *sensors = data->sensors;
41065 int err;
41066
41067 /* Set up read-only sensors */
41068diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41069index 708081b..fe2d4ab 100644
41070--- a/drivers/hwmon/iio_hwmon.c
41071+++ b/drivers/hwmon/iio_hwmon.c
41072@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41073 {
41074 struct device *dev = &pdev->dev;
41075 struct iio_hwmon_state *st;
41076- struct sensor_device_attribute *a;
41077+ sensor_device_attribute_no_const *a;
41078 int ret, i;
41079 int in_i = 1, temp_i = 1, curr_i = 1;
41080 enum iio_chan_type type;
41081diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41082index cf811c1..4c17110 100644
41083--- a/drivers/hwmon/nct6775.c
41084+++ b/drivers/hwmon/nct6775.c
41085@@ -944,10 +944,10 @@ static struct attribute_group *
41086 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41087 int repeat)
41088 {
41089- struct attribute_group *group;
41090+ attribute_group_no_const *group;
41091 struct sensor_device_attr_u *su;
41092- struct sensor_device_attribute *a;
41093- struct sensor_device_attribute_2 *a2;
41094+ sensor_device_attribute_no_const *a;
41095+ sensor_device_attribute_2_no_const *a2;
41096 struct attribute **attrs;
41097 struct sensor_device_template **t;
41098 int i, count;
41099diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41100index 3cbf66e..8c5cc2a 100644
41101--- a/drivers/hwmon/pmbus/pmbus_core.c
41102+++ b/drivers/hwmon/pmbus/pmbus_core.c
41103@@ -782,7 +782,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41104 return 0;
41105 }
41106
41107-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41108+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41109 const char *name,
41110 umode_t mode,
41111 ssize_t (*show)(struct device *dev,
41112@@ -799,7 +799,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41113 dev_attr->store = store;
41114 }
41115
41116-static void pmbus_attr_init(struct sensor_device_attribute *a,
41117+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41118 const char *name,
41119 umode_t mode,
41120 ssize_t (*show)(struct device *dev,
41121@@ -821,7 +821,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41122 u16 reg, u8 mask)
41123 {
41124 struct pmbus_boolean *boolean;
41125- struct sensor_device_attribute *a;
41126+ sensor_device_attribute_no_const *a;
41127
41128 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41129 if (!boolean)
41130@@ -846,7 +846,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41131 bool update, bool readonly)
41132 {
41133 struct pmbus_sensor *sensor;
41134- struct device_attribute *a;
41135+ device_attribute_no_const *a;
41136
41137 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41138 if (!sensor)
41139@@ -877,7 +877,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41140 const char *lstring, int index)
41141 {
41142 struct pmbus_label *label;
41143- struct device_attribute *a;
41144+ device_attribute_no_const *a;
41145
41146 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41147 if (!label)
41148diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41149index 97cd45a..ac54d8b 100644
41150--- a/drivers/hwmon/sht15.c
41151+++ b/drivers/hwmon/sht15.c
41152@@ -169,7 +169,7 @@ struct sht15_data {
41153 int supply_uv;
41154 bool supply_uv_valid;
41155 struct work_struct update_supply_work;
41156- atomic_t interrupt_handled;
41157+ atomic_unchecked_t interrupt_handled;
41158 };
41159
41160 /**
41161@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41162 ret = gpio_direction_input(data->pdata->gpio_data);
41163 if (ret)
41164 return ret;
41165- atomic_set(&data->interrupt_handled, 0);
41166+ atomic_set_unchecked(&data->interrupt_handled, 0);
41167
41168 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41169 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41170 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41171 /* Only relevant if the interrupt hasn't occurred. */
41172- if (!atomic_read(&data->interrupt_handled))
41173+ if (!atomic_read_unchecked(&data->interrupt_handled))
41174 schedule_work(&data->read_work);
41175 }
41176 ret = wait_event_timeout(data->wait_queue,
41177@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41178
41179 /* First disable the interrupt */
41180 disable_irq_nosync(irq);
41181- atomic_inc(&data->interrupt_handled);
41182+ atomic_inc_unchecked(&data->interrupt_handled);
41183 /* Then schedule a reading work struct */
41184 if (data->state != SHT15_READING_NOTHING)
41185 schedule_work(&data->read_work);
41186@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41187 * If not, then start the interrupt again - care here as could
41188 * have gone low in meantime so verify it hasn't!
41189 */
41190- atomic_set(&data->interrupt_handled, 0);
41191+ atomic_set_unchecked(&data->interrupt_handled, 0);
41192 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41193 /* If still not occurred or another handler was scheduled */
41194 if (gpio_get_value(data->pdata->gpio_data)
41195- || atomic_read(&data->interrupt_handled))
41196+ || atomic_read_unchecked(&data->interrupt_handled))
41197 return;
41198 }
41199
41200diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41201index 38944e9..ae9e5ed 100644
41202--- a/drivers/hwmon/via-cputemp.c
41203+++ b/drivers/hwmon/via-cputemp.c
41204@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41205 return NOTIFY_OK;
41206 }
41207
41208-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41209+static struct notifier_block via_cputemp_cpu_notifier = {
41210 .notifier_call = via_cputemp_cpu_callback,
41211 };
41212
41213diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41214index 07f01ac..d79ad3d 100644
41215--- a/drivers/i2c/busses/i2c-amd756-s4882.c
41216+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41217@@ -43,7 +43,7 @@
41218 extern struct i2c_adapter amd756_smbus;
41219
41220 static struct i2c_adapter *s4882_adapter;
41221-static struct i2c_algorithm *s4882_algo;
41222+static i2c_algorithm_no_const *s4882_algo;
41223
41224 /* Wrapper access functions for multiplexed SMBus */
41225 static DEFINE_MUTEX(amd756_lock);
41226diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41227index 721f7eb..0fd2a09 100644
41228--- a/drivers/i2c/busses/i2c-diolan-u2c.c
41229+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41230@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41231 /* usb layer */
41232
41233 /* Send command to device, and get response. */
41234-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41235+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41236 {
41237 int ret = 0;
41238 int actual;
41239diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41240index 2ca268d..c6acbdf 100644
41241--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41242+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41243@@ -41,7 +41,7 @@
41244 extern struct i2c_adapter *nforce2_smbus;
41245
41246 static struct i2c_adapter *s4985_adapter;
41247-static struct i2c_algorithm *s4985_algo;
41248+static i2c_algorithm_no_const *s4985_algo;
41249
41250 /* Wrapper access functions for multiplexed SMBus */
41251 static DEFINE_MUTEX(nforce2_lock);
41252diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41253index 80b47e8..1a6040d9 100644
41254--- a/drivers/i2c/i2c-dev.c
41255+++ b/drivers/i2c/i2c-dev.c
41256@@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41257 break;
41258 }
41259
41260- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41261+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41262 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41263 if (IS_ERR(rdwr_pa[i].buf)) {
41264 res = PTR_ERR(rdwr_pa[i].buf);
41265diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41266index 0b510ba..4fbb5085 100644
41267--- a/drivers/ide/ide-cd.c
41268+++ b/drivers/ide/ide-cd.c
41269@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41270 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41271 if ((unsigned long)buf & alignment
41272 || blk_rq_bytes(rq) & q->dma_pad_mask
41273- || object_is_on_stack(buf))
41274+ || object_starts_on_stack(buf))
41275 drive->dma = 0;
41276 }
41277 }
41278diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41279index 18f72e3..3722327 100644
41280--- a/drivers/iio/industrialio-core.c
41281+++ b/drivers/iio/industrialio-core.c
41282@@ -521,7 +521,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41283 }
41284
41285 static
41286-int __iio_device_attr_init(struct device_attribute *dev_attr,
41287+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41288 const char *postfix,
41289 struct iio_chan_spec const *chan,
41290 ssize_t (*readfunc)(struct device *dev,
41291diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41292index f2ef7ef..743d02f 100644
41293--- a/drivers/infiniband/core/cm.c
41294+++ b/drivers/infiniband/core/cm.c
41295@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41296
41297 struct cm_counter_group {
41298 struct kobject obj;
41299- atomic_long_t counter[CM_ATTR_COUNT];
41300+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
41301 };
41302
41303 struct cm_counter_attribute {
41304@@ -1392,7 +1392,7 @@ static void cm_dup_req_handler(struct cm_work *work,
41305 struct ib_mad_send_buf *msg = NULL;
41306 int ret;
41307
41308- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41309+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41310 counter[CM_REQ_COUNTER]);
41311
41312 /* Quick state check to discard duplicate REQs. */
41313@@ -1776,7 +1776,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
41314 if (!cm_id_priv)
41315 return;
41316
41317- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41318+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41319 counter[CM_REP_COUNTER]);
41320 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
41321 if (ret)
41322@@ -1943,7 +1943,7 @@ static int cm_rtu_handler(struct cm_work *work)
41323 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
41324 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
41325 spin_unlock_irq(&cm_id_priv->lock);
41326- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41327+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41328 counter[CM_RTU_COUNTER]);
41329 goto out;
41330 }
41331@@ -2126,7 +2126,7 @@ static int cm_dreq_handler(struct cm_work *work)
41332 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
41333 dreq_msg->local_comm_id);
41334 if (!cm_id_priv) {
41335- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41336+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41337 counter[CM_DREQ_COUNTER]);
41338 cm_issue_drep(work->port, work->mad_recv_wc);
41339 return -EINVAL;
41340@@ -2151,7 +2151,7 @@ static int cm_dreq_handler(struct cm_work *work)
41341 case IB_CM_MRA_REP_RCVD:
41342 break;
41343 case IB_CM_TIMEWAIT:
41344- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41345+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41346 counter[CM_DREQ_COUNTER]);
41347 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41348 goto unlock;
41349@@ -2165,7 +2165,7 @@ static int cm_dreq_handler(struct cm_work *work)
41350 cm_free_msg(msg);
41351 goto deref;
41352 case IB_CM_DREQ_RCVD:
41353- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41354+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41355 counter[CM_DREQ_COUNTER]);
41356 goto unlock;
41357 default:
41358@@ -2532,7 +2532,7 @@ static int cm_mra_handler(struct cm_work *work)
41359 ib_modify_mad(cm_id_priv->av.port->mad_agent,
41360 cm_id_priv->msg, timeout)) {
41361 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
41362- atomic_long_inc(&work->port->
41363+ atomic_long_inc_unchecked(&work->port->
41364 counter_group[CM_RECV_DUPLICATES].
41365 counter[CM_MRA_COUNTER]);
41366 goto out;
41367@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
41368 break;
41369 case IB_CM_MRA_REQ_RCVD:
41370 case IB_CM_MRA_REP_RCVD:
41371- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41372+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41373 counter[CM_MRA_COUNTER]);
41374 /* fall through */
41375 default:
41376@@ -2703,7 +2703,7 @@ static int cm_lap_handler(struct cm_work *work)
41377 case IB_CM_LAP_IDLE:
41378 break;
41379 case IB_CM_MRA_LAP_SENT:
41380- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41381+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41382 counter[CM_LAP_COUNTER]);
41383 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41384 goto unlock;
41385@@ -2719,7 +2719,7 @@ static int cm_lap_handler(struct cm_work *work)
41386 cm_free_msg(msg);
41387 goto deref;
41388 case IB_CM_LAP_RCVD:
41389- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41390+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41391 counter[CM_LAP_COUNTER]);
41392 goto unlock;
41393 default:
41394@@ -3003,7 +3003,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
41395 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
41396 if (cur_cm_id_priv) {
41397 spin_unlock_irq(&cm.lock);
41398- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41399+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41400 counter[CM_SIDR_REQ_COUNTER]);
41401 goto out; /* Duplicate message. */
41402 }
41403@@ -3215,10 +3215,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
41404 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
41405 msg->retries = 1;
41406
41407- atomic_long_add(1 + msg->retries,
41408+ atomic_long_add_unchecked(1 + msg->retries,
41409 &port->counter_group[CM_XMIT].counter[attr_index]);
41410 if (msg->retries)
41411- atomic_long_add(msg->retries,
41412+ atomic_long_add_unchecked(msg->retries,
41413 &port->counter_group[CM_XMIT_RETRIES].
41414 counter[attr_index]);
41415
41416@@ -3428,7 +3428,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
41417 }
41418
41419 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
41420- atomic_long_inc(&port->counter_group[CM_RECV].
41421+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
41422 counter[attr_id - CM_ATTR_ID_OFFSET]);
41423
41424 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
41425@@ -3633,7 +3633,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
41426 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
41427
41428 return sprintf(buf, "%ld\n",
41429- atomic_long_read(&group->counter[cm_attr->index]));
41430+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
41431 }
41432
41433 static const struct sysfs_ops cm_counter_ops = {
41434diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
41435index 9f5ad7c..588cd84 100644
41436--- a/drivers/infiniband/core/fmr_pool.c
41437+++ b/drivers/infiniband/core/fmr_pool.c
41438@@ -98,8 +98,8 @@ struct ib_fmr_pool {
41439
41440 struct task_struct *thread;
41441
41442- atomic_t req_ser;
41443- atomic_t flush_ser;
41444+ atomic_unchecked_t req_ser;
41445+ atomic_unchecked_t flush_ser;
41446
41447 wait_queue_head_t force_wait;
41448 };
41449@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
41450 struct ib_fmr_pool *pool = pool_ptr;
41451
41452 do {
41453- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
41454+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
41455 ib_fmr_batch_release(pool);
41456
41457- atomic_inc(&pool->flush_ser);
41458+ atomic_inc_unchecked(&pool->flush_ser);
41459 wake_up_interruptible(&pool->force_wait);
41460
41461 if (pool->flush_function)
41462@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
41463 }
41464
41465 set_current_state(TASK_INTERRUPTIBLE);
41466- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
41467+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
41468 !kthread_should_stop())
41469 schedule();
41470 __set_current_state(TASK_RUNNING);
41471@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
41472 pool->dirty_watermark = params->dirty_watermark;
41473 pool->dirty_len = 0;
41474 spin_lock_init(&pool->pool_lock);
41475- atomic_set(&pool->req_ser, 0);
41476- atomic_set(&pool->flush_ser, 0);
41477+ atomic_set_unchecked(&pool->req_ser, 0);
41478+ atomic_set_unchecked(&pool->flush_ser, 0);
41479 init_waitqueue_head(&pool->force_wait);
41480
41481 pool->thread = kthread_run(ib_fmr_cleanup_thread,
41482@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
41483 }
41484 spin_unlock_irq(&pool->pool_lock);
41485
41486- serial = atomic_inc_return(&pool->req_ser);
41487+ serial = atomic_inc_return_unchecked(&pool->req_ser);
41488 wake_up_process(pool->thread);
41489
41490 if (wait_event_interruptible(pool->force_wait,
41491- atomic_read(&pool->flush_ser) - serial >= 0))
41492+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
41493 return -EINTR;
41494
41495 return 0;
41496@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
41497 } else {
41498 list_add_tail(&fmr->list, &pool->dirty_list);
41499 if (++pool->dirty_len >= pool->dirty_watermark) {
41500- atomic_inc(&pool->req_ser);
41501+ atomic_inc_unchecked(&pool->req_ser);
41502 wake_up_process(pool->thread);
41503 }
41504 }
41505diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
41506index 84e4500..2c9beeb 100644
41507--- a/drivers/infiniband/hw/cxgb4/mem.c
41508+++ b/drivers/infiniband/hw/cxgb4/mem.c
41509@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
41510 int err;
41511 struct fw_ri_tpte tpt;
41512 u32 stag_idx;
41513- static atomic_t key;
41514+ static atomic_unchecked_t key;
41515
41516 if (c4iw_fatal_error(rdev))
41517 return -EIO;
41518@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
41519 if (rdev->stats.stag.cur > rdev->stats.stag.max)
41520 rdev->stats.stag.max = rdev->stats.stag.cur;
41521 mutex_unlock(&rdev->stats.lock);
41522- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
41523+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
41524 }
41525 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
41526 __func__, stag_state, type, pdid, stag_idx);
41527diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
41528index 644c2c7..ecf0879 100644
41529--- a/drivers/infiniband/hw/ipath/ipath_dma.c
41530+++ b/drivers/infiniband/hw/ipath/ipath_dma.c
41531@@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
41532 }
41533
41534 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
41535- ipath_mapping_error,
41536- ipath_dma_map_single,
41537- ipath_dma_unmap_single,
41538- ipath_dma_map_page,
41539- ipath_dma_unmap_page,
41540- ipath_map_sg,
41541- ipath_unmap_sg,
41542- ipath_sg_dma_address,
41543- ipath_sg_dma_len,
41544- ipath_sync_single_for_cpu,
41545- ipath_sync_single_for_device,
41546- ipath_dma_alloc_coherent,
41547- ipath_dma_free_coherent
41548+ .mapping_error = ipath_mapping_error,
41549+ .map_single = ipath_dma_map_single,
41550+ .unmap_single = ipath_dma_unmap_single,
41551+ .map_page = ipath_dma_map_page,
41552+ .unmap_page = ipath_dma_unmap_page,
41553+ .map_sg = ipath_map_sg,
41554+ .unmap_sg = ipath_unmap_sg,
41555+ .dma_address = ipath_sg_dma_address,
41556+ .dma_len = ipath_sg_dma_len,
41557+ .sync_single_for_cpu = ipath_sync_single_for_cpu,
41558+ .sync_single_for_device = ipath_sync_single_for_device,
41559+ .alloc_coherent = ipath_dma_alloc_coherent,
41560+ .free_coherent = ipath_dma_free_coherent
41561 };
41562diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
41563index 79b3dbc..96e5fcc 100644
41564--- a/drivers/infiniband/hw/ipath/ipath_rc.c
41565+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
41566@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
41567 struct ib_atomic_eth *ateth;
41568 struct ipath_ack_entry *e;
41569 u64 vaddr;
41570- atomic64_t *maddr;
41571+ atomic64_unchecked_t *maddr;
41572 u64 sdata;
41573 u32 rkey;
41574 u8 next;
41575@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
41576 IB_ACCESS_REMOTE_ATOMIC)))
41577 goto nack_acc_unlck;
41578 /* Perform atomic OP and save result. */
41579- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
41580+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
41581 sdata = be64_to_cpu(ateth->swap_data);
41582 e = &qp->s_ack_queue[qp->r_head_ack_queue];
41583 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
41584- (u64) atomic64_add_return(sdata, maddr) - sdata :
41585+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
41586 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
41587 be64_to_cpu(ateth->compare_data),
41588 sdata);
41589diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
41590index 1f95bba..9530f87 100644
41591--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
41592+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
41593@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
41594 unsigned long flags;
41595 struct ib_wc wc;
41596 u64 sdata;
41597- atomic64_t *maddr;
41598+ atomic64_unchecked_t *maddr;
41599 enum ib_wc_status send_status;
41600
41601 /*
41602@@ -382,11 +382,11 @@ again:
41603 IB_ACCESS_REMOTE_ATOMIC)))
41604 goto acc_err;
41605 /* Perform atomic OP and save result. */
41606- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
41607+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
41608 sdata = wqe->wr.wr.atomic.compare_add;
41609 *(u64 *) sqp->s_sge.sge.vaddr =
41610 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
41611- (u64) atomic64_add_return(sdata, maddr) - sdata :
41612+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
41613 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
41614 sdata, wqe->wr.wr.atomic.swap);
41615 goto send_comp;
41616diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
41617index f2a3f48..673ec79 100644
41618--- a/drivers/infiniband/hw/mlx4/mad.c
41619+++ b/drivers/infiniband/hw/mlx4/mad.c
41620@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
41621
41622 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
41623 {
41624- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
41625+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
41626 cpu_to_be64(0xff00000000000000LL);
41627 }
41628
41629diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
41630index 25b2cdf..099ff97 100644
41631--- a/drivers/infiniband/hw/mlx4/mcg.c
41632+++ b/drivers/infiniband/hw/mlx4/mcg.c
41633@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
41634 {
41635 char name[20];
41636
41637- atomic_set(&ctx->tid, 0);
41638+ atomic_set_unchecked(&ctx->tid, 0);
41639 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
41640 ctx->mcg_wq = create_singlethread_workqueue(name);
41641 if (!ctx->mcg_wq)
41642diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
41643index 036b663..c9a8c73 100644
41644--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
41645+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
41646@@ -404,7 +404,7 @@ struct mlx4_ib_demux_ctx {
41647 struct list_head mcg_mgid0_list;
41648 struct workqueue_struct *mcg_wq;
41649 struct mlx4_ib_demux_pv_ctx **tun;
41650- atomic_t tid;
41651+ atomic_unchecked_t tid;
41652 int flushing; /* flushing the work queue */
41653 };
41654
41655diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
41656index 9d3e5c1..6f166df 100644
41657--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
41658+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
41659@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
41660 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
41661 }
41662
41663-int mthca_QUERY_FW(struct mthca_dev *dev)
41664+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
41665 {
41666 struct mthca_mailbox *mailbox;
41667 u32 *outbox;
41668@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41669 CMD_TIME_CLASS_B);
41670 }
41671
41672-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41673+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41674 int num_mtt)
41675 {
41676 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
41677@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
41678 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
41679 }
41680
41681-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41682+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41683 int eq_num)
41684 {
41685 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
41686@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
41687 CMD_TIME_CLASS_B);
41688 }
41689
41690-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
41691+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
41692 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
41693 void *in_mad, void *response_mad)
41694 {
41695diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
41696index 87897b9..7e79542 100644
41697--- a/drivers/infiniband/hw/mthca/mthca_main.c
41698+++ b/drivers/infiniband/hw/mthca/mthca_main.c
41699@@ -692,7 +692,7 @@ err_close:
41700 return err;
41701 }
41702
41703-static int mthca_setup_hca(struct mthca_dev *dev)
41704+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
41705 {
41706 int err;
41707
41708diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
41709index ed9a989..6aa5dc2 100644
41710--- a/drivers/infiniband/hw/mthca/mthca_mr.c
41711+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
41712@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
41713 * through the bitmaps)
41714 */
41715
41716-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
41717+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
41718 {
41719 int o;
41720 int m;
41721@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
41722 return key;
41723 }
41724
41725-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
41726+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
41727 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
41728 {
41729 struct mthca_mailbox *mailbox;
41730@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
41731 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
41732 }
41733
41734-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
41735+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
41736 u64 *buffer_list, int buffer_size_shift,
41737 int list_len, u64 iova, u64 total_size,
41738 u32 access, struct mthca_mr *mr)
41739diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
41740index 5b71d43..35a9e14 100644
41741--- a/drivers/infiniband/hw/mthca/mthca_provider.c
41742+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
41743@@ -763,7 +763,7 @@ unlock:
41744 return 0;
41745 }
41746
41747-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
41748+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
41749 {
41750 struct mthca_dev *dev = to_mdev(ibcq->device);
41751 struct mthca_cq *cq = to_mcq(ibcq);
41752diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
41753index 4291410..d2ab1fb 100644
41754--- a/drivers/infiniband/hw/nes/nes.c
41755+++ b/drivers/infiniband/hw/nes/nes.c
41756@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
41757 LIST_HEAD(nes_adapter_list);
41758 static LIST_HEAD(nes_dev_list);
41759
41760-atomic_t qps_destroyed;
41761+atomic_unchecked_t qps_destroyed;
41762
41763 static unsigned int ee_flsh_adapter;
41764 static unsigned int sysfs_nonidx_addr;
41765@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
41766 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
41767 struct nes_adapter *nesadapter = nesdev->nesadapter;
41768
41769- atomic_inc(&qps_destroyed);
41770+ atomic_inc_unchecked(&qps_destroyed);
41771
41772 /* Free the control structures */
41773
41774diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
41775index 33cc589..3bd6538 100644
41776--- a/drivers/infiniband/hw/nes/nes.h
41777+++ b/drivers/infiniband/hw/nes/nes.h
41778@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
41779 extern unsigned int wqm_quanta;
41780 extern struct list_head nes_adapter_list;
41781
41782-extern atomic_t cm_connects;
41783-extern atomic_t cm_accepts;
41784-extern atomic_t cm_disconnects;
41785-extern atomic_t cm_closes;
41786-extern atomic_t cm_connecteds;
41787-extern atomic_t cm_connect_reqs;
41788-extern atomic_t cm_rejects;
41789-extern atomic_t mod_qp_timouts;
41790-extern atomic_t qps_created;
41791-extern atomic_t qps_destroyed;
41792-extern atomic_t sw_qps_destroyed;
41793+extern atomic_unchecked_t cm_connects;
41794+extern atomic_unchecked_t cm_accepts;
41795+extern atomic_unchecked_t cm_disconnects;
41796+extern atomic_unchecked_t cm_closes;
41797+extern atomic_unchecked_t cm_connecteds;
41798+extern atomic_unchecked_t cm_connect_reqs;
41799+extern atomic_unchecked_t cm_rejects;
41800+extern atomic_unchecked_t mod_qp_timouts;
41801+extern atomic_unchecked_t qps_created;
41802+extern atomic_unchecked_t qps_destroyed;
41803+extern atomic_unchecked_t sw_qps_destroyed;
41804 extern u32 mh_detected;
41805 extern u32 mh_pauses_sent;
41806 extern u32 cm_packets_sent;
41807@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
41808 extern u32 cm_packets_received;
41809 extern u32 cm_packets_dropped;
41810 extern u32 cm_packets_retrans;
41811-extern atomic_t cm_listens_created;
41812-extern atomic_t cm_listens_destroyed;
41813+extern atomic_unchecked_t cm_listens_created;
41814+extern atomic_unchecked_t cm_listens_destroyed;
41815 extern u32 cm_backlog_drops;
41816-extern atomic_t cm_loopbacks;
41817-extern atomic_t cm_nodes_created;
41818-extern atomic_t cm_nodes_destroyed;
41819-extern atomic_t cm_accel_dropped_pkts;
41820-extern atomic_t cm_resets_recvd;
41821-extern atomic_t pau_qps_created;
41822-extern atomic_t pau_qps_destroyed;
41823+extern atomic_unchecked_t cm_loopbacks;
41824+extern atomic_unchecked_t cm_nodes_created;
41825+extern atomic_unchecked_t cm_nodes_destroyed;
41826+extern atomic_unchecked_t cm_accel_dropped_pkts;
41827+extern atomic_unchecked_t cm_resets_recvd;
41828+extern atomic_unchecked_t pau_qps_created;
41829+extern atomic_unchecked_t pau_qps_destroyed;
41830
41831 extern u32 int_mod_timer_init;
41832 extern u32 int_mod_cq_depth_256;
41833diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
41834index 6b29249..461d143 100644
41835--- a/drivers/infiniband/hw/nes/nes_cm.c
41836+++ b/drivers/infiniband/hw/nes/nes_cm.c
41837@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
41838 u32 cm_packets_retrans;
41839 u32 cm_packets_created;
41840 u32 cm_packets_received;
41841-atomic_t cm_listens_created;
41842-atomic_t cm_listens_destroyed;
41843+atomic_unchecked_t cm_listens_created;
41844+atomic_unchecked_t cm_listens_destroyed;
41845 u32 cm_backlog_drops;
41846-atomic_t cm_loopbacks;
41847-atomic_t cm_nodes_created;
41848-atomic_t cm_nodes_destroyed;
41849-atomic_t cm_accel_dropped_pkts;
41850-atomic_t cm_resets_recvd;
41851+atomic_unchecked_t cm_loopbacks;
41852+atomic_unchecked_t cm_nodes_created;
41853+atomic_unchecked_t cm_nodes_destroyed;
41854+atomic_unchecked_t cm_accel_dropped_pkts;
41855+atomic_unchecked_t cm_resets_recvd;
41856
41857 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
41858 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
41859@@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
41860 /* instance of function pointers for client API */
41861 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
41862 static struct nes_cm_ops nes_cm_api = {
41863- mini_cm_accelerated,
41864- mini_cm_listen,
41865- mini_cm_del_listen,
41866- mini_cm_connect,
41867- mini_cm_close,
41868- mini_cm_accept,
41869- mini_cm_reject,
41870- mini_cm_recv_pkt,
41871- mini_cm_dealloc_core,
41872- mini_cm_get,
41873- mini_cm_set
41874+ .accelerated = mini_cm_accelerated,
41875+ .listen = mini_cm_listen,
41876+ .stop_listener = mini_cm_del_listen,
41877+ .connect = mini_cm_connect,
41878+ .close = mini_cm_close,
41879+ .accept = mini_cm_accept,
41880+ .reject = mini_cm_reject,
41881+ .recv_pkt = mini_cm_recv_pkt,
41882+ .destroy_cm_core = mini_cm_dealloc_core,
41883+ .get = mini_cm_get,
41884+ .set = mini_cm_set
41885 };
41886
41887 static struct nes_cm_core *g_cm_core;
41888
41889-atomic_t cm_connects;
41890-atomic_t cm_accepts;
41891-atomic_t cm_disconnects;
41892-atomic_t cm_closes;
41893-atomic_t cm_connecteds;
41894-atomic_t cm_connect_reqs;
41895-atomic_t cm_rejects;
41896+atomic_unchecked_t cm_connects;
41897+atomic_unchecked_t cm_accepts;
41898+atomic_unchecked_t cm_disconnects;
41899+atomic_unchecked_t cm_closes;
41900+atomic_unchecked_t cm_connecteds;
41901+atomic_unchecked_t cm_connect_reqs;
41902+atomic_unchecked_t cm_rejects;
41903
41904 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
41905 {
41906@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
41907 kfree(listener);
41908 listener = NULL;
41909 ret = 0;
41910- atomic_inc(&cm_listens_destroyed);
41911+ atomic_inc_unchecked(&cm_listens_destroyed);
41912 } else {
41913 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
41914 }
41915@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
41916 cm_node->rem_mac);
41917
41918 add_hte_node(cm_core, cm_node);
41919- atomic_inc(&cm_nodes_created);
41920+ atomic_inc_unchecked(&cm_nodes_created);
41921
41922 return cm_node;
41923 }
41924@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
41925 }
41926
41927 atomic_dec(&cm_core->node_cnt);
41928- atomic_inc(&cm_nodes_destroyed);
41929+ atomic_inc_unchecked(&cm_nodes_destroyed);
41930 nesqp = cm_node->nesqp;
41931 if (nesqp) {
41932 nesqp->cm_node = NULL;
41933@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
41934
41935 static void drop_packet(struct sk_buff *skb)
41936 {
41937- atomic_inc(&cm_accel_dropped_pkts);
41938+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
41939 dev_kfree_skb_any(skb);
41940 }
41941
41942@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
41943 {
41944
41945 int reset = 0; /* whether to send reset in case of err.. */
41946- atomic_inc(&cm_resets_recvd);
41947+ atomic_inc_unchecked(&cm_resets_recvd);
41948 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
41949 " refcnt=%d\n", cm_node, cm_node->state,
41950 atomic_read(&cm_node->ref_count));
41951@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
41952 rem_ref_cm_node(cm_node->cm_core, cm_node);
41953 return NULL;
41954 }
41955- atomic_inc(&cm_loopbacks);
41956+ atomic_inc_unchecked(&cm_loopbacks);
41957 loopbackremotenode->loopbackpartner = cm_node;
41958 loopbackremotenode->tcp_cntxt.rcv_wscale =
41959 NES_CM_DEFAULT_RCV_WND_SCALE;
41960@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
41961 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
41962 else {
41963 rem_ref_cm_node(cm_core, cm_node);
41964- atomic_inc(&cm_accel_dropped_pkts);
41965+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
41966 dev_kfree_skb_any(skb);
41967 }
41968 break;
41969@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
41970
41971 if ((cm_id) && (cm_id->event_handler)) {
41972 if (issue_disconn) {
41973- atomic_inc(&cm_disconnects);
41974+ atomic_inc_unchecked(&cm_disconnects);
41975 cm_event.event = IW_CM_EVENT_DISCONNECT;
41976 cm_event.status = disconn_status;
41977 cm_event.local_addr = cm_id->local_addr;
41978@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
41979 }
41980
41981 if (issue_close) {
41982- atomic_inc(&cm_closes);
41983+ atomic_inc_unchecked(&cm_closes);
41984 nes_disconnect(nesqp, 1);
41985
41986 cm_id->provider_data = nesqp;
41987@@ -3035,7 +3035,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
41988
41989 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
41990 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
41991- atomic_inc(&cm_accepts);
41992+ atomic_inc_unchecked(&cm_accepts);
41993
41994 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
41995 netdev_refcnt_read(nesvnic->netdev));
41996@@ -3224,7 +3224,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
41997 struct nes_cm_core *cm_core;
41998 u8 *start_buff;
41999
42000- atomic_inc(&cm_rejects);
42001+ atomic_inc_unchecked(&cm_rejects);
42002 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42003 loopback = cm_node->loopbackpartner;
42004 cm_core = cm_node->cm_core;
42005@@ -3286,7 +3286,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42006 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42007 ntohs(laddr->sin_port));
42008
42009- atomic_inc(&cm_connects);
42010+ atomic_inc_unchecked(&cm_connects);
42011 nesqp->active_conn = 1;
42012
42013 /* cache the cm_id in the qp */
42014@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42015 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42016 return err;
42017 }
42018- atomic_inc(&cm_listens_created);
42019+ atomic_inc_unchecked(&cm_listens_created);
42020 }
42021
42022 cm_id->add_ref(cm_id);
42023@@ -3505,7 +3505,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42024
42025 if (nesqp->destroyed)
42026 return;
42027- atomic_inc(&cm_connecteds);
42028+ atomic_inc_unchecked(&cm_connecteds);
42029 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42030 " local port 0x%04X. jiffies = %lu.\n",
42031 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42032@@ -3686,7 +3686,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42033
42034 cm_id->add_ref(cm_id);
42035 ret = cm_id->event_handler(cm_id, &cm_event);
42036- atomic_inc(&cm_closes);
42037+ atomic_inc_unchecked(&cm_closes);
42038 cm_event.event = IW_CM_EVENT_CLOSE;
42039 cm_event.status = 0;
42040 cm_event.provider_data = cm_id->provider_data;
42041@@ -3726,7 +3726,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42042 return;
42043 cm_id = cm_node->cm_id;
42044
42045- atomic_inc(&cm_connect_reqs);
42046+ atomic_inc_unchecked(&cm_connect_reqs);
42047 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42048 cm_node, cm_id, jiffies);
42049
42050@@ -3770,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42051 return;
42052 cm_id = cm_node->cm_id;
42053
42054- atomic_inc(&cm_connect_reqs);
42055+ atomic_inc_unchecked(&cm_connect_reqs);
42056 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42057 cm_node, cm_id, jiffies);
42058
42059diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42060index 4166452..fc952c3 100644
42061--- a/drivers/infiniband/hw/nes/nes_mgt.c
42062+++ b/drivers/infiniband/hw/nes/nes_mgt.c
42063@@ -40,8 +40,8 @@
42064 #include "nes.h"
42065 #include "nes_mgt.h"
42066
42067-atomic_t pau_qps_created;
42068-atomic_t pau_qps_destroyed;
42069+atomic_unchecked_t pau_qps_created;
42070+atomic_unchecked_t pau_qps_destroyed;
42071
42072 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42073 {
42074@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42075 {
42076 struct sk_buff *skb;
42077 unsigned long flags;
42078- atomic_inc(&pau_qps_destroyed);
42079+ atomic_inc_unchecked(&pau_qps_destroyed);
42080
42081 /* Free packets that have not yet been forwarded */
42082 /* Lock is acquired by skb_dequeue when removing the skb */
42083@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42084 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42085 skb_queue_head_init(&nesqp->pau_list);
42086 spin_lock_init(&nesqp->pau_lock);
42087- atomic_inc(&pau_qps_created);
42088+ atomic_inc_unchecked(&pau_qps_created);
42089 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42090 }
42091
42092diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42093index 49eb511..a774366 100644
42094--- a/drivers/infiniband/hw/nes/nes_nic.c
42095+++ b/drivers/infiniband/hw/nes/nes_nic.c
42096@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42097 target_stat_values[++index] = mh_detected;
42098 target_stat_values[++index] = mh_pauses_sent;
42099 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42100- target_stat_values[++index] = atomic_read(&cm_connects);
42101- target_stat_values[++index] = atomic_read(&cm_accepts);
42102- target_stat_values[++index] = atomic_read(&cm_disconnects);
42103- target_stat_values[++index] = atomic_read(&cm_connecteds);
42104- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42105- target_stat_values[++index] = atomic_read(&cm_rejects);
42106- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42107- target_stat_values[++index] = atomic_read(&qps_created);
42108- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42109- target_stat_values[++index] = atomic_read(&qps_destroyed);
42110- target_stat_values[++index] = atomic_read(&cm_closes);
42111+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42112+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42113+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42114+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42115+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42116+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42117+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42118+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42119+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42120+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42121+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42122 target_stat_values[++index] = cm_packets_sent;
42123 target_stat_values[++index] = cm_packets_bounced;
42124 target_stat_values[++index] = cm_packets_created;
42125 target_stat_values[++index] = cm_packets_received;
42126 target_stat_values[++index] = cm_packets_dropped;
42127 target_stat_values[++index] = cm_packets_retrans;
42128- target_stat_values[++index] = atomic_read(&cm_listens_created);
42129- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42130+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42131+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42132 target_stat_values[++index] = cm_backlog_drops;
42133- target_stat_values[++index] = atomic_read(&cm_loopbacks);
42134- target_stat_values[++index] = atomic_read(&cm_nodes_created);
42135- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42136- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42137- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42138+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42139+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42140+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42141+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42142+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42143 target_stat_values[++index] = nesadapter->free_4kpbl;
42144 target_stat_values[++index] = nesadapter->free_256pbl;
42145 target_stat_values[++index] = int_mod_timer_init;
42146 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42147 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42148 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42149- target_stat_values[++index] = atomic_read(&pau_qps_created);
42150- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42151+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42152+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42153 }
42154
42155 /**
42156diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42157index 8308e36..ae0d3b5 100644
42158--- a/drivers/infiniband/hw/nes/nes_verbs.c
42159+++ b/drivers/infiniband/hw/nes/nes_verbs.c
42160@@ -46,9 +46,9 @@
42161
42162 #include <rdma/ib_umem.h>
42163
42164-atomic_t mod_qp_timouts;
42165-atomic_t qps_created;
42166-atomic_t sw_qps_destroyed;
42167+atomic_unchecked_t mod_qp_timouts;
42168+atomic_unchecked_t qps_created;
42169+atomic_unchecked_t sw_qps_destroyed;
42170
42171 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42172
42173@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42174 if (init_attr->create_flags)
42175 return ERR_PTR(-EINVAL);
42176
42177- atomic_inc(&qps_created);
42178+ atomic_inc_unchecked(&qps_created);
42179 switch (init_attr->qp_type) {
42180 case IB_QPT_RC:
42181 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42182@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42183 struct iw_cm_event cm_event;
42184 int ret = 0;
42185
42186- atomic_inc(&sw_qps_destroyed);
42187+ atomic_inc_unchecked(&sw_qps_destroyed);
42188 nesqp->destroyed = 1;
42189
42190 /* Blow away the connection if it exists. */
42191diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42192index 1946101..09766d2 100644
42193--- a/drivers/infiniband/hw/qib/qib.h
42194+++ b/drivers/infiniband/hw/qib/qib.h
42195@@ -52,6 +52,7 @@
42196 #include <linux/kref.h>
42197 #include <linux/sched.h>
42198 #include <linux/kthread.h>
42199+#include <linux/slab.h>
42200
42201 #include "qib_common.h"
42202 #include "qib_verbs.h"
42203diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42204index 24c41ba..102d71f 100644
42205--- a/drivers/input/gameport/gameport.c
42206+++ b/drivers/input/gameport/gameport.c
42207@@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42208 */
42209 static void gameport_init_port(struct gameport *gameport)
42210 {
42211- static atomic_t gameport_no = ATOMIC_INIT(0);
42212+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42213
42214 __module_get(THIS_MODULE);
42215
42216 mutex_init(&gameport->drv_mutex);
42217 device_initialize(&gameport->dev);
42218 dev_set_name(&gameport->dev, "gameport%lu",
42219- (unsigned long)atomic_inc_return(&gameport_no) - 1);
42220+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42221 gameport->dev.bus = &gameport_bus;
42222 gameport->dev.release = gameport_release_port;
42223 if (gameport->parent)
42224diff --git a/drivers/input/input.c b/drivers/input/input.c
42225index d2965e4..f52b7d7 100644
42226--- a/drivers/input/input.c
42227+++ b/drivers/input/input.c
42228@@ -1734,7 +1734,7 @@ EXPORT_SYMBOL_GPL(input_class);
42229 */
42230 struct input_dev *input_allocate_device(void)
42231 {
42232- static atomic_t input_no = ATOMIC_INIT(0);
42233+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42234 struct input_dev *dev;
42235
42236 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42237@@ -1749,7 +1749,7 @@ struct input_dev *input_allocate_device(void)
42238 INIT_LIST_HEAD(&dev->node);
42239
42240 dev_set_name(&dev->dev, "input%ld",
42241- (unsigned long) atomic_inc_return(&input_no) - 1);
42242+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42243
42244 __module_get(THIS_MODULE);
42245 }
42246diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42247index 04c69af..5f92d00 100644
42248--- a/drivers/input/joystick/sidewinder.c
42249+++ b/drivers/input/joystick/sidewinder.c
42250@@ -30,6 +30,7 @@
42251 #include <linux/kernel.h>
42252 #include <linux/module.h>
42253 #include <linux/slab.h>
42254+#include <linux/sched.h>
42255 #include <linux/init.h>
42256 #include <linux/input.h>
42257 #include <linux/gameport.h>
42258diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42259index 75e3b10..fb390fd 100644
42260--- a/drivers/input/joystick/xpad.c
42261+++ b/drivers/input/joystick/xpad.c
42262@@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42263
42264 static int xpad_led_probe(struct usb_xpad *xpad)
42265 {
42266- static atomic_t led_seq = ATOMIC_INIT(0);
42267+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42268 long led_no;
42269 struct xpad_led *led;
42270 struct led_classdev *led_cdev;
42271@@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42272 if (!led)
42273 return -ENOMEM;
42274
42275- led_no = (long)atomic_inc_return(&led_seq) - 1;
42276+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42277
42278 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42279 led->xpad = xpad;
42280diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42281index e204f26..8459f15 100644
42282--- a/drivers/input/misc/ims-pcu.c
42283+++ b/drivers/input/misc/ims-pcu.c
42284@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42285
42286 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42287 {
42288- static atomic_t device_no = ATOMIC_INIT(0);
42289+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42290
42291 const struct ims_pcu_device_info *info;
42292 u8 device_id;
42293@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42294 }
42295
42296 /* Device appears to be operable, complete initialization */
42297- pcu->device_no = atomic_inc_return(&device_no) - 1;
42298+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42299
42300 error = ims_pcu_setup_backlight(pcu);
42301 if (error)
42302diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42303index 2f0b39d..7370f13 100644
42304--- a/drivers/input/mouse/psmouse.h
42305+++ b/drivers/input/mouse/psmouse.h
42306@@ -116,7 +116,7 @@ struct psmouse_attribute {
42307 ssize_t (*set)(struct psmouse *psmouse, void *data,
42308 const char *buf, size_t count);
42309 bool protect;
42310-};
42311+} __do_const;
42312 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
42313
42314 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
42315diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
42316index 4c842c3..590b0bf 100644
42317--- a/drivers/input/mousedev.c
42318+++ b/drivers/input/mousedev.c
42319@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
42320
42321 spin_unlock_irq(&client->packet_lock);
42322
42323- if (copy_to_user(buffer, data, count))
42324+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
42325 return -EFAULT;
42326
42327 return count;
42328diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
42329index 8f4c4ab..5fc8a45 100644
42330--- a/drivers/input/serio/serio.c
42331+++ b/drivers/input/serio/serio.c
42332@@ -505,7 +505,7 @@ static void serio_release_port(struct device *dev)
42333 */
42334 static void serio_init_port(struct serio *serio)
42335 {
42336- static atomic_t serio_no = ATOMIC_INIT(0);
42337+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
42338
42339 __module_get(THIS_MODULE);
42340
42341@@ -516,7 +516,7 @@ static void serio_init_port(struct serio *serio)
42342 mutex_init(&serio->drv_mutex);
42343 device_initialize(&serio->dev);
42344 dev_set_name(&serio->dev, "serio%ld",
42345- (long)atomic_inc_return(&serio_no) - 1);
42346+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
42347 serio->dev.bus = &serio_bus;
42348 serio->dev.release = serio_release_port;
42349 serio->dev.groups = serio_device_attr_groups;
42350diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
42351index 59df2e7..8f1cafb 100644
42352--- a/drivers/input/serio/serio_raw.c
42353+++ b/drivers/input/serio/serio_raw.c
42354@@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
42355
42356 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42357 {
42358- static atomic_t serio_raw_no = ATOMIC_INIT(0);
42359+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
42360 struct serio_raw *serio_raw;
42361 int err;
42362
42363@@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42364 }
42365
42366 snprintf(serio_raw->name, sizeof(serio_raw->name),
42367- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
42368+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
42369 kref_init(&serio_raw->kref);
42370 INIT_LIST_HEAD(&serio_raw->client_list);
42371 init_waitqueue_head(&serio_raw->wait);
42372diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
42373index e5555fc..937986d 100644
42374--- a/drivers/iommu/iommu.c
42375+++ b/drivers/iommu/iommu.c
42376@@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
42377 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
42378 {
42379 bus_register_notifier(bus, &iommu_bus_nb);
42380- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
42381+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
42382 }
42383
42384 /**
42385diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
42386index 39f81ae..2660096 100644
42387--- a/drivers/iommu/irq_remapping.c
42388+++ b/drivers/iommu/irq_remapping.c
42389@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
42390 void panic_if_irq_remap(const char *msg)
42391 {
42392 if (irq_remapping_enabled)
42393- panic(msg);
42394+ panic("%s", msg);
42395 }
42396
42397 static void ir_ack_apic_edge(struct irq_data *data)
42398@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
42399
42400 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
42401 {
42402- chip->irq_print_chip = ir_print_prefix;
42403- chip->irq_ack = ir_ack_apic_edge;
42404- chip->irq_eoi = ir_ack_apic_level;
42405- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42406+ pax_open_kernel();
42407+ *(void **)&chip->irq_print_chip = ir_print_prefix;
42408+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
42409+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
42410+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42411+ pax_close_kernel();
42412 }
42413
42414 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
42415diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
42416index 341c601..e5f407e 100644
42417--- a/drivers/irqchip/irq-gic.c
42418+++ b/drivers/irqchip/irq-gic.c
42419@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
42420 * Supported arch specific GIC irq extension.
42421 * Default make them NULL.
42422 */
42423-struct irq_chip gic_arch_extn = {
42424+irq_chip_no_const gic_arch_extn = {
42425 .irq_eoi = NULL,
42426 .irq_mask = NULL,
42427 .irq_unmask = NULL,
42428@@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
42429 chained_irq_exit(chip, desc);
42430 }
42431
42432-static struct irq_chip gic_chip = {
42433+static irq_chip_no_const gic_chip __read_only = {
42434 .name = "GIC",
42435 .irq_mask = gic_mask_irq,
42436 .irq_unmask = gic_unmask_irq,
42437diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
42438index ac6f72b..81150f2 100644
42439--- a/drivers/isdn/capi/capi.c
42440+++ b/drivers/isdn/capi/capi.c
42441@@ -81,8 +81,8 @@ struct capiminor {
42442
42443 struct capi20_appl *ap;
42444 u32 ncci;
42445- atomic_t datahandle;
42446- atomic_t msgid;
42447+ atomic_unchecked_t datahandle;
42448+ atomic_unchecked_t msgid;
42449
42450 struct tty_port port;
42451 int ttyinstop;
42452@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
42453 capimsg_setu16(s, 2, mp->ap->applid);
42454 capimsg_setu8 (s, 4, CAPI_DATA_B3);
42455 capimsg_setu8 (s, 5, CAPI_RESP);
42456- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
42457+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
42458 capimsg_setu32(s, 8, mp->ncci);
42459 capimsg_setu16(s, 12, datahandle);
42460 }
42461@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
42462 mp->outbytes -= len;
42463 spin_unlock_bh(&mp->outlock);
42464
42465- datahandle = atomic_inc_return(&mp->datahandle);
42466+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
42467 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
42468 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
42469 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
42470 capimsg_setu16(skb->data, 2, mp->ap->applid);
42471 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
42472 capimsg_setu8 (skb->data, 5, CAPI_REQ);
42473- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
42474+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
42475 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
42476 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
42477 capimsg_setu16(skb->data, 16, len); /* Data length */
42478diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
42479index c44950d..10ac276 100644
42480--- a/drivers/isdn/gigaset/bas-gigaset.c
42481+++ b/drivers/isdn/gigaset/bas-gigaset.c
42482@@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
42483
42484
42485 static const struct gigaset_ops gigops = {
42486- gigaset_write_cmd,
42487- gigaset_write_room,
42488- gigaset_chars_in_buffer,
42489- gigaset_brkchars,
42490- gigaset_init_bchannel,
42491- gigaset_close_bchannel,
42492- gigaset_initbcshw,
42493- gigaset_freebcshw,
42494- gigaset_reinitbcshw,
42495- gigaset_initcshw,
42496- gigaset_freecshw,
42497- gigaset_set_modem_ctrl,
42498- gigaset_baud_rate,
42499- gigaset_set_line_ctrl,
42500- gigaset_isoc_send_skb,
42501- gigaset_isoc_input,
42502+ .write_cmd = gigaset_write_cmd,
42503+ .write_room = gigaset_write_room,
42504+ .chars_in_buffer = gigaset_chars_in_buffer,
42505+ .brkchars = gigaset_brkchars,
42506+ .init_bchannel = gigaset_init_bchannel,
42507+ .close_bchannel = gigaset_close_bchannel,
42508+ .initbcshw = gigaset_initbcshw,
42509+ .freebcshw = gigaset_freebcshw,
42510+ .reinitbcshw = gigaset_reinitbcshw,
42511+ .initcshw = gigaset_initcshw,
42512+ .freecshw = gigaset_freecshw,
42513+ .set_modem_ctrl = gigaset_set_modem_ctrl,
42514+ .baud_rate = gigaset_baud_rate,
42515+ .set_line_ctrl = gigaset_set_line_ctrl,
42516+ .send_skb = gigaset_isoc_send_skb,
42517+ .handle_input = gigaset_isoc_input,
42518 };
42519
42520 /* bas_gigaset_init
42521diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
42522index 600c79b..3752bab 100644
42523--- a/drivers/isdn/gigaset/interface.c
42524+++ b/drivers/isdn/gigaset/interface.c
42525@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
42526 }
42527 tty->driver_data = cs;
42528
42529- ++cs->port.count;
42530+ atomic_inc(&cs->port.count);
42531
42532- if (cs->port.count == 1) {
42533+ if (atomic_read(&cs->port.count) == 1) {
42534 tty_port_tty_set(&cs->port, tty);
42535 cs->port.low_latency = 1;
42536 }
42537@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
42538
42539 if (!cs->connected)
42540 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
42541- else if (!cs->port.count)
42542+ else if (!atomic_read(&cs->port.count))
42543 dev_warn(cs->dev, "%s: device not opened\n", __func__);
42544- else if (!--cs->port.count)
42545+ else if (!atomic_dec_return(&cs->port.count))
42546 tty_port_tty_set(&cs->port, NULL);
42547
42548 mutex_unlock(&cs->mutex);
42549diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
42550index 8c91fd5..14f13ce 100644
42551--- a/drivers/isdn/gigaset/ser-gigaset.c
42552+++ b/drivers/isdn/gigaset/ser-gigaset.c
42553@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
42554 }
42555
42556 static const struct gigaset_ops ops = {
42557- gigaset_write_cmd,
42558- gigaset_write_room,
42559- gigaset_chars_in_buffer,
42560- gigaset_brkchars,
42561- gigaset_init_bchannel,
42562- gigaset_close_bchannel,
42563- gigaset_initbcshw,
42564- gigaset_freebcshw,
42565- gigaset_reinitbcshw,
42566- gigaset_initcshw,
42567- gigaset_freecshw,
42568- gigaset_set_modem_ctrl,
42569- gigaset_baud_rate,
42570- gigaset_set_line_ctrl,
42571- gigaset_m10x_send_skb, /* asyncdata.c */
42572- gigaset_m10x_input, /* asyncdata.c */
42573+ .write_cmd = gigaset_write_cmd,
42574+ .write_room = gigaset_write_room,
42575+ .chars_in_buffer = gigaset_chars_in_buffer,
42576+ .brkchars = gigaset_brkchars,
42577+ .init_bchannel = gigaset_init_bchannel,
42578+ .close_bchannel = gigaset_close_bchannel,
42579+ .initbcshw = gigaset_initbcshw,
42580+ .freebcshw = gigaset_freebcshw,
42581+ .reinitbcshw = gigaset_reinitbcshw,
42582+ .initcshw = gigaset_initcshw,
42583+ .freecshw = gigaset_freecshw,
42584+ .set_modem_ctrl = gigaset_set_modem_ctrl,
42585+ .baud_rate = gigaset_baud_rate,
42586+ .set_line_ctrl = gigaset_set_line_ctrl,
42587+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
42588+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
42589 };
42590
42591
42592diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
42593index d0a41cb..b953e50 100644
42594--- a/drivers/isdn/gigaset/usb-gigaset.c
42595+++ b/drivers/isdn/gigaset/usb-gigaset.c
42596@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
42597 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
42598 memcpy(cs->hw.usb->bchars, buf, 6);
42599 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
42600- 0, 0, &buf, 6, 2000);
42601+ 0, 0, buf, 6, 2000);
42602 }
42603
42604 static void gigaset_freebcshw(struct bc_state *bcs)
42605@@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
42606 }
42607
42608 static const struct gigaset_ops ops = {
42609- gigaset_write_cmd,
42610- gigaset_write_room,
42611- gigaset_chars_in_buffer,
42612- gigaset_brkchars,
42613- gigaset_init_bchannel,
42614- gigaset_close_bchannel,
42615- gigaset_initbcshw,
42616- gigaset_freebcshw,
42617- gigaset_reinitbcshw,
42618- gigaset_initcshw,
42619- gigaset_freecshw,
42620- gigaset_set_modem_ctrl,
42621- gigaset_baud_rate,
42622- gigaset_set_line_ctrl,
42623- gigaset_m10x_send_skb,
42624- gigaset_m10x_input,
42625+ .write_cmd = gigaset_write_cmd,
42626+ .write_room = gigaset_write_room,
42627+ .chars_in_buffer = gigaset_chars_in_buffer,
42628+ .brkchars = gigaset_brkchars,
42629+ .init_bchannel = gigaset_init_bchannel,
42630+ .close_bchannel = gigaset_close_bchannel,
42631+ .initbcshw = gigaset_initbcshw,
42632+ .freebcshw = gigaset_freebcshw,
42633+ .reinitbcshw = gigaset_reinitbcshw,
42634+ .initcshw = gigaset_initcshw,
42635+ .freecshw = gigaset_freecshw,
42636+ .set_modem_ctrl = gigaset_set_modem_ctrl,
42637+ .baud_rate = gigaset_baud_rate,
42638+ .set_line_ctrl = gigaset_set_line_ctrl,
42639+ .send_skb = gigaset_m10x_send_skb,
42640+ .handle_input = gigaset_m10x_input,
42641 };
42642
42643 /*
42644diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
42645index 4d9b195..455075c 100644
42646--- a/drivers/isdn/hardware/avm/b1.c
42647+++ b/drivers/isdn/hardware/avm/b1.c
42648@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
42649 }
42650 if (left) {
42651 if (t4file->user) {
42652- if (copy_from_user(buf, dp, left))
42653+ if (left > sizeof buf || copy_from_user(buf, dp, left))
42654 return -EFAULT;
42655 } else {
42656 memcpy(buf, dp, left);
42657@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
42658 }
42659 if (left) {
42660 if (config->user) {
42661- if (copy_from_user(buf, dp, left))
42662+ if (left > sizeof buf || copy_from_user(buf, dp, left))
42663 return -EFAULT;
42664 } else {
42665 memcpy(buf, dp, left);
42666diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
42667index 9bb12ba..d4262f7 100644
42668--- a/drivers/isdn/i4l/isdn_common.c
42669+++ b/drivers/isdn/i4l/isdn_common.c
42670@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
42671 } else
42672 return -EINVAL;
42673 case IIOCDBGVAR:
42674+ if (!capable(CAP_SYS_RAWIO))
42675+ return -EPERM;
42676 if (arg) {
42677 if (copy_to_user(argp, &dev, sizeof(ulong)))
42678 return -EFAULT;
42679diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
42680index 91d5730..336523e 100644
42681--- a/drivers/isdn/i4l/isdn_concap.c
42682+++ b/drivers/isdn/i4l/isdn_concap.c
42683@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
42684 }
42685
42686 struct concap_device_ops isdn_concap_reliable_dl_dops = {
42687- &isdn_concap_dl_data_req,
42688- &isdn_concap_dl_connect_req,
42689- &isdn_concap_dl_disconn_req
42690+ .data_req = &isdn_concap_dl_data_req,
42691+ .connect_req = &isdn_concap_dl_connect_req,
42692+ .disconn_req = &isdn_concap_dl_disconn_req
42693 };
42694
42695 /* The following should better go into a dedicated source file such that
42696diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
42697index 3c5f249..5fac4d0 100644
42698--- a/drivers/isdn/i4l/isdn_tty.c
42699+++ b/drivers/isdn/i4l/isdn_tty.c
42700@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
42701
42702 #ifdef ISDN_DEBUG_MODEM_OPEN
42703 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
42704- port->count);
42705+ atomic_read(&port->count));
42706 #endif
42707- port->count++;
42708+ atomic_inc(&port->count);
42709 port->tty = tty;
42710 /*
42711 * Start up serial port
42712@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42713 #endif
42714 return;
42715 }
42716- if ((tty->count == 1) && (port->count != 1)) {
42717+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
42718 /*
42719 * Uh, oh. tty->count is 1, which means that the tty
42720 * structure will be freed. Info->count should always
42721@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42722 * serial port won't be shutdown.
42723 */
42724 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
42725- "info->count is %d\n", port->count);
42726- port->count = 1;
42727+ "info->count is %d\n", atomic_read(&port->count));
42728+ atomic_set(&port->count, 1);
42729 }
42730- if (--port->count < 0) {
42731+ if (atomic_dec_return(&port->count) < 0) {
42732 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
42733- info->line, port->count);
42734- port->count = 0;
42735+ info->line, atomic_read(&port->count));
42736+ atomic_set(&port->count, 0);
42737 }
42738- if (port->count) {
42739+ if (atomic_read(&port->count)) {
42740 #ifdef ISDN_DEBUG_MODEM_OPEN
42741 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
42742 #endif
42743@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
42744 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
42745 return;
42746 isdn_tty_shutdown(info);
42747- port->count = 0;
42748+ atomic_set(&port->count, 0);
42749 port->flags &= ~ASYNC_NORMAL_ACTIVE;
42750 port->tty = NULL;
42751 wake_up_interruptible(&port->open_wait);
42752@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
42753 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
42754 modem_info *info = &dev->mdm.info[i];
42755
42756- if (info->port.count == 0)
42757+ if (atomic_read(&info->port.count) == 0)
42758 continue;
42759 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
42760 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
42761diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
42762index e2d4e58..40cd045 100644
42763--- a/drivers/isdn/i4l/isdn_x25iface.c
42764+++ b/drivers/isdn/i4l/isdn_x25iface.c
42765@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
42766
42767
42768 static struct concap_proto_ops ix25_pops = {
42769- &isdn_x25iface_proto_new,
42770- &isdn_x25iface_proto_del,
42771- &isdn_x25iface_proto_restart,
42772- &isdn_x25iface_proto_close,
42773- &isdn_x25iface_xmit,
42774- &isdn_x25iface_receive,
42775- &isdn_x25iface_connect_ind,
42776- &isdn_x25iface_disconn_ind
42777+ .proto_new = &isdn_x25iface_proto_new,
42778+ .proto_del = &isdn_x25iface_proto_del,
42779+ .restart = &isdn_x25iface_proto_restart,
42780+ .close = &isdn_x25iface_proto_close,
42781+ .encap_and_xmit = &isdn_x25iface_xmit,
42782+ .data_ind = &isdn_x25iface_receive,
42783+ .connect_ind = &isdn_x25iface_connect_ind,
42784+ .disconn_ind = &isdn_x25iface_disconn_ind
42785 };
42786
42787 /* error message helper function */
42788diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
42789index 53d487f..f020f41 100644
42790--- a/drivers/isdn/icn/icn.c
42791+++ b/drivers/isdn/icn/icn.c
42792@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
42793 if (count > len)
42794 count = len;
42795 if (user) {
42796- if (copy_from_user(msg, buf, count))
42797+ if (count > sizeof msg || copy_from_user(msg, buf, count))
42798 return -EFAULT;
42799 } else
42800 memcpy(msg, buf, count);
42801diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
42802index a4f05c5..1433bc5 100644
42803--- a/drivers/isdn/mISDN/dsp_cmx.c
42804+++ b/drivers/isdn/mISDN/dsp_cmx.c
42805@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
42806 static u16 dsp_count; /* last sample count */
42807 static int dsp_count_valid; /* if we have last sample count */
42808
42809-void
42810+void __intentional_overflow(-1)
42811 dsp_cmx_send(void *arg)
42812 {
42813 struct dsp_conf *conf;
42814diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
42815index d93e245..e7ece6b 100644
42816--- a/drivers/leds/leds-clevo-mail.c
42817+++ b/drivers/leds/leds-clevo-mail.c
42818@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
42819 * detected as working, but in reality it is not) as low as
42820 * possible.
42821 */
42822-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
42823+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
42824 {
42825 .callback = clevo_mail_led_dmi_callback,
42826 .ident = "Clevo D410J",
42827diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
42828index 5b8f938..b73d657 100644
42829--- a/drivers/leds/leds-ss4200.c
42830+++ b/drivers/leds/leds-ss4200.c
42831@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
42832 * detected as working, but in reality it is not) as low as
42833 * possible.
42834 */
42835-static struct dmi_system_id nas_led_whitelist[] __initdata = {
42836+static struct dmi_system_id nas_led_whitelist[] __initconst = {
42837 {
42838 .callback = ss4200_led_dmi_callback,
42839 .ident = "Intel SS4200-E",
42840diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
42841index 0bf1e4e..b4bf44e 100644
42842--- a/drivers/lguest/core.c
42843+++ b/drivers/lguest/core.c
42844@@ -97,9 +97,17 @@ static __init int map_switcher(void)
42845 * The end address needs +1 because __get_vm_area allocates an
42846 * extra guard page, so we need space for that.
42847 */
42848+
42849+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
42850+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42851+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
42852+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42853+#else
42854 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42855 VM_ALLOC, switcher_addr, switcher_addr
42856 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42857+#endif
42858+
42859 if (!switcher_vma) {
42860 err = -ENOMEM;
42861 printk("lguest: could not map switcher pages high\n");
42862@@ -124,7 +132,7 @@ static __init int map_switcher(void)
42863 * Now the Switcher is mapped at the right address, we can't fail!
42864 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
42865 */
42866- memcpy(switcher_vma->addr, start_switcher_text,
42867+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
42868 end_switcher_text - start_switcher_text);
42869
42870 printk(KERN_INFO "lguest: mapped switcher at %p\n",
42871diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
42872index bfb39bb..08a603b 100644
42873--- a/drivers/lguest/page_tables.c
42874+++ b/drivers/lguest/page_tables.c
42875@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
42876 /*:*/
42877
42878 #ifdef CONFIG_X86_PAE
42879-static void release_pmd(pmd_t *spmd)
42880+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
42881 {
42882 /* If the entry's not present, there's nothing to release. */
42883 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
42884diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
42885index 922a1ac..9dd0c2a 100644
42886--- a/drivers/lguest/x86/core.c
42887+++ b/drivers/lguest/x86/core.c
42888@@ -59,7 +59,7 @@ static struct {
42889 /* Offset from where switcher.S was compiled to where we've copied it */
42890 static unsigned long switcher_offset(void)
42891 {
42892- return switcher_addr - (unsigned long)start_switcher_text;
42893+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
42894 }
42895
42896 /* This cpu's struct lguest_pages (after the Switcher text page) */
42897@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
42898 * These copies are pretty cheap, so we do them unconditionally: */
42899 /* Save the current Host top-level page directory.
42900 */
42901+
42902+#ifdef CONFIG_PAX_PER_CPU_PGD
42903+ pages->state.host_cr3 = read_cr3();
42904+#else
42905 pages->state.host_cr3 = __pa(current->mm->pgd);
42906+#endif
42907+
42908 /*
42909 * Set up the Guest's page tables to see this CPU's pages (and no
42910 * other CPU's pages).
42911@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
42912 * compiled-in switcher code and the high-mapped copy we just made.
42913 */
42914 for (i = 0; i < IDT_ENTRIES; i++)
42915- default_idt_entries[i] += switcher_offset();
42916+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
42917
42918 /*
42919 * Set up the Switcher's per-cpu areas.
42920@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
42921 * it will be undisturbed when we switch. To change %cs and jump we
42922 * need this structure to feed to Intel's "lcall" instruction.
42923 */
42924- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
42925+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
42926 lguest_entry.segment = LGUEST_CS;
42927
42928 /*
42929diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
42930index 40634b0..4f5855e 100644
42931--- a/drivers/lguest/x86/switcher_32.S
42932+++ b/drivers/lguest/x86/switcher_32.S
42933@@ -87,6 +87,7 @@
42934 #include <asm/page.h>
42935 #include <asm/segment.h>
42936 #include <asm/lguest.h>
42937+#include <asm/processor-flags.h>
42938
42939 // We mark the start of the code to copy
42940 // It's placed in .text tho it's never run here
42941@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
42942 // Changes type when we load it: damn Intel!
42943 // For after we switch over our page tables
42944 // That entry will be read-only: we'd crash.
42945+
42946+#ifdef CONFIG_PAX_KERNEXEC
42947+ mov %cr0, %edx
42948+ xor $X86_CR0_WP, %edx
42949+ mov %edx, %cr0
42950+#endif
42951+
42952 movl $(GDT_ENTRY_TSS*8), %edx
42953 ltr %dx
42954
42955@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
42956 // Let's clear it again for our return.
42957 // The GDT descriptor of the Host
42958 // Points to the table after two "size" bytes
42959- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
42960+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
42961 // Clear "used" from type field (byte 5, bit 2)
42962- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
42963+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
42964+
42965+#ifdef CONFIG_PAX_KERNEXEC
42966+ mov %cr0, %eax
42967+ xor $X86_CR0_WP, %eax
42968+ mov %eax, %cr0
42969+#endif
42970
42971 // Once our page table's switched, the Guest is live!
42972 // The Host fades as we run this final step.
42973@@ -295,13 +309,12 @@ deliver_to_host:
42974 // I consulted gcc, and it gave
42975 // These instructions, which I gladly credit:
42976 leal (%edx,%ebx,8), %eax
42977- movzwl (%eax),%edx
42978- movl 4(%eax), %eax
42979- xorw %ax, %ax
42980- orl %eax, %edx
42981+ movl 4(%eax), %edx
42982+ movw (%eax), %dx
42983 // Now the address of the handler's in %edx
42984 // We call it now: its "iret" drops us home.
42985- jmp *%edx
42986+ ljmp $__KERNEL_CS, $1f
42987+1: jmp *%edx
42988
42989 // Every interrupt can come to us here
42990 // But we must truly tell each apart.
42991diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
42992index 9762f1b..3e79734 100644
42993--- a/drivers/md/bcache/closure.h
42994+++ b/drivers/md/bcache/closure.h
42995@@ -483,7 +483,7 @@ static inline void closure_queue(struct closure *cl)
42996 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
42997 struct workqueue_struct *wq)
42998 {
42999- BUG_ON(object_is_on_stack(cl));
43000+ BUG_ON(object_starts_on_stack(cl));
43001 closure_set_ip(cl);
43002 cl->fn = fn;
43003 cl->wq = wq;
43004diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43005index 12dc29b..1596277 100644
43006--- a/drivers/md/bitmap.c
43007+++ b/drivers/md/bitmap.c
43008@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43009 chunk_kb ? "KB" : "B");
43010 if (bitmap->storage.file) {
43011 seq_printf(seq, ", file: ");
43012- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43013+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43014 }
43015
43016 seq_printf(seq, "\n");
43017diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43018index 5152142..623d141 100644
43019--- a/drivers/md/dm-ioctl.c
43020+++ b/drivers/md/dm-ioctl.c
43021@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43022 cmd == DM_LIST_VERSIONS_CMD)
43023 return 0;
43024
43025- if ((cmd == DM_DEV_CREATE_CMD)) {
43026+ if (cmd == DM_DEV_CREATE_CMD) {
43027 if (!*param->name) {
43028 DMWARN("name not supplied when creating device");
43029 return -EINVAL;
43030diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43031index 9584443..9fc9ac9 100644
43032--- a/drivers/md/dm-raid1.c
43033+++ b/drivers/md/dm-raid1.c
43034@@ -40,7 +40,7 @@ enum dm_raid1_error {
43035
43036 struct mirror {
43037 struct mirror_set *ms;
43038- atomic_t error_count;
43039+ atomic_unchecked_t error_count;
43040 unsigned long error_type;
43041 struct dm_dev *dev;
43042 sector_t offset;
43043@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43044 struct mirror *m;
43045
43046 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43047- if (!atomic_read(&m->error_count))
43048+ if (!atomic_read_unchecked(&m->error_count))
43049 return m;
43050
43051 return NULL;
43052@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43053 * simple way to tell if a device has encountered
43054 * errors.
43055 */
43056- atomic_inc(&m->error_count);
43057+ atomic_inc_unchecked(&m->error_count);
43058
43059 if (test_and_set_bit(error_type, &m->error_type))
43060 return;
43061@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43062 struct mirror *m = get_default_mirror(ms);
43063
43064 do {
43065- if (likely(!atomic_read(&m->error_count)))
43066+ if (likely(!atomic_read_unchecked(&m->error_count)))
43067 return m;
43068
43069 if (m-- == ms->mirror)
43070@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43071 {
43072 struct mirror *default_mirror = get_default_mirror(m->ms);
43073
43074- return !atomic_read(&default_mirror->error_count);
43075+ return !atomic_read_unchecked(&default_mirror->error_count);
43076 }
43077
43078 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43079@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43080 */
43081 if (likely(region_in_sync(ms, region, 1)))
43082 m = choose_mirror(ms, bio->bi_sector);
43083- else if (m && atomic_read(&m->error_count))
43084+ else if (m && atomic_read_unchecked(&m->error_count))
43085 m = NULL;
43086
43087 if (likely(m))
43088@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43089 }
43090
43091 ms->mirror[mirror].ms = ms;
43092- atomic_set(&(ms->mirror[mirror].error_count), 0);
43093+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43094 ms->mirror[mirror].error_type = 0;
43095 ms->mirror[mirror].offset = offset;
43096
43097@@ -1339,7 +1339,7 @@ static void mirror_resume(struct dm_target *ti)
43098 */
43099 static char device_status_char(struct mirror *m)
43100 {
43101- if (!atomic_read(&(m->error_count)))
43102+ if (!atomic_read_unchecked(&(m->error_count)))
43103 return 'A';
43104
43105 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43106diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43107index 28a9012..9c0f6a5 100644
43108--- a/drivers/md/dm-stats.c
43109+++ b/drivers/md/dm-stats.c
43110@@ -382,7 +382,7 @@ do_sync_free:
43111 synchronize_rcu_expedited();
43112 dm_stat_free(&s->rcu_head);
43113 } else {
43114- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43115+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43116 call_rcu(&s->rcu_head, dm_stat_free);
43117 }
43118 return 0;
43119@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43120 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43121 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43122 ));
43123- ACCESS_ONCE(last->last_sector) = end_sector;
43124- ACCESS_ONCE(last->last_rw) = bi_rw;
43125+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
43126+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43127 }
43128
43129 rcu_read_lock();
43130diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43131index 73c1712..7347292 100644
43132--- a/drivers/md/dm-stripe.c
43133+++ b/drivers/md/dm-stripe.c
43134@@ -21,7 +21,7 @@ struct stripe {
43135 struct dm_dev *dev;
43136 sector_t physical_start;
43137
43138- atomic_t error_count;
43139+ atomic_unchecked_t error_count;
43140 };
43141
43142 struct stripe_c {
43143@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43144 kfree(sc);
43145 return r;
43146 }
43147- atomic_set(&(sc->stripe[i].error_count), 0);
43148+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43149 }
43150
43151 ti->private = sc;
43152@@ -327,7 +327,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43153 DMEMIT("%d ", sc->stripes);
43154 for (i = 0; i < sc->stripes; i++) {
43155 DMEMIT("%s ", sc->stripe[i].dev->name);
43156- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43157+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43158 'D' : 'A';
43159 }
43160 buffer[i] = '\0';
43161@@ -372,8 +372,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43162 */
43163 for (i = 0; i < sc->stripes; i++)
43164 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43165- atomic_inc(&(sc->stripe[i].error_count));
43166- if (atomic_read(&(sc->stripe[i].error_count)) <
43167+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
43168+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43169 DM_IO_ERROR_THRESHOLD)
43170 schedule_work(&sc->trigger_event);
43171 }
43172diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43173index 3ba6a38..b0fa9b0 100644
43174--- a/drivers/md/dm-table.c
43175+++ b/drivers/md/dm-table.c
43176@@ -291,7 +291,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43177 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43178 struct mapped_device *md)
43179 {
43180- static char *_claim_ptr = "I belong to device-mapper";
43181+ static char _claim_ptr[] = "I belong to device-mapper";
43182 struct block_device *bdev;
43183
43184 int r;
43185@@ -359,7 +359,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43186 if (!dev_size)
43187 return 0;
43188
43189- if ((start >= dev_size) || (start + len > dev_size)) {
43190+ if ((start >= dev_size) || (len > dev_size - start)) {
43191 DMWARN("%s: %s too small for target: "
43192 "start=%llu, len=%llu, dev_size=%llu",
43193 dm_device_name(ti->table->md), bdevname(bdev, b),
43194diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43195index 8a30ad5..72792d3 100644
43196--- a/drivers/md/dm-thin-metadata.c
43197+++ b/drivers/md/dm-thin-metadata.c
43198@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43199 {
43200 pmd->info.tm = pmd->tm;
43201 pmd->info.levels = 2;
43202- pmd->info.value_type.context = pmd->data_sm;
43203+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43204 pmd->info.value_type.size = sizeof(__le64);
43205 pmd->info.value_type.inc = data_block_inc;
43206 pmd->info.value_type.dec = data_block_dec;
43207@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43208
43209 pmd->bl_info.tm = pmd->tm;
43210 pmd->bl_info.levels = 1;
43211- pmd->bl_info.value_type.context = pmd->data_sm;
43212+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43213 pmd->bl_info.value_type.size = sizeof(__le64);
43214 pmd->bl_info.value_type.inc = data_block_inc;
43215 pmd->bl_info.value_type.dec = data_block_dec;
43216diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43217index 0704c52..0a33d61 100644
43218--- a/drivers/md/dm.c
43219+++ b/drivers/md/dm.c
43220@@ -185,9 +185,9 @@ struct mapped_device {
43221 /*
43222 * Event handling.
43223 */
43224- atomic_t event_nr;
43225+ atomic_unchecked_t event_nr;
43226 wait_queue_head_t eventq;
43227- atomic_t uevent_seq;
43228+ atomic_unchecked_t uevent_seq;
43229 struct list_head uevent_list;
43230 spinlock_t uevent_lock; /* Protect access to uevent_list */
43231
43232@@ -2021,8 +2021,8 @@ static struct mapped_device *alloc_dev(int minor)
43233 spin_lock_init(&md->deferred_lock);
43234 atomic_set(&md->holders, 1);
43235 atomic_set(&md->open_count, 0);
43236- atomic_set(&md->event_nr, 0);
43237- atomic_set(&md->uevent_seq, 0);
43238+ atomic_set_unchecked(&md->event_nr, 0);
43239+ atomic_set_unchecked(&md->uevent_seq, 0);
43240 INIT_LIST_HEAD(&md->uevent_list);
43241 spin_lock_init(&md->uevent_lock);
43242
43243@@ -2175,7 +2175,7 @@ static void event_callback(void *context)
43244
43245 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43246
43247- atomic_inc(&md->event_nr);
43248+ atomic_inc_unchecked(&md->event_nr);
43249 wake_up(&md->eventq);
43250 }
43251
43252@@ -2868,18 +2868,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43253
43254 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43255 {
43256- return atomic_add_return(1, &md->uevent_seq);
43257+ return atomic_add_return_unchecked(1, &md->uevent_seq);
43258 }
43259
43260 uint32_t dm_get_event_nr(struct mapped_device *md)
43261 {
43262- return atomic_read(&md->event_nr);
43263+ return atomic_read_unchecked(&md->event_nr);
43264 }
43265
43266 int dm_wait_event(struct mapped_device *md, int event_nr)
43267 {
43268 return wait_event_interruptible(md->eventq,
43269- (event_nr != atomic_read(&md->event_nr)));
43270+ (event_nr != atomic_read_unchecked(&md->event_nr)));
43271 }
43272
43273 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43274diff --git a/drivers/md/md.c b/drivers/md/md.c
43275index 369d919..ba7049c 100644
43276--- a/drivers/md/md.c
43277+++ b/drivers/md/md.c
43278@@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
43279 * start build, activate spare
43280 */
43281 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
43282-static atomic_t md_event_count;
43283+static atomic_unchecked_t md_event_count;
43284 void md_new_event(struct mddev *mddev)
43285 {
43286- atomic_inc(&md_event_count);
43287+ atomic_inc_unchecked(&md_event_count);
43288 wake_up(&md_event_waiters);
43289 }
43290 EXPORT_SYMBOL_GPL(md_new_event);
43291@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
43292 */
43293 static void md_new_event_inintr(struct mddev *mddev)
43294 {
43295- atomic_inc(&md_event_count);
43296+ atomic_inc_unchecked(&md_event_count);
43297 wake_up(&md_event_waiters);
43298 }
43299
43300@@ -1463,7 +1463,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
43301 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
43302 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
43303 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
43304- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43305+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43306
43307 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
43308 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
43309@@ -1710,7 +1710,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
43310 else
43311 sb->resync_offset = cpu_to_le64(0);
43312
43313- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
43314+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
43315
43316 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
43317 sb->size = cpu_to_le64(mddev->dev_sectors);
43318@@ -2715,7 +2715,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
43319 static ssize_t
43320 errors_show(struct md_rdev *rdev, char *page)
43321 {
43322- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
43323+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
43324 }
43325
43326 static ssize_t
43327@@ -2724,7 +2724,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
43328 char *e;
43329 unsigned long n = simple_strtoul(buf, &e, 10);
43330 if (*buf && (*e == 0 || *e == '\n')) {
43331- atomic_set(&rdev->corrected_errors, n);
43332+ atomic_set_unchecked(&rdev->corrected_errors, n);
43333 return len;
43334 }
43335 return -EINVAL;
43336@@ -3173,8 +3173,8 @@ int md_rdev_init(struct md_rdev *rdev)
43337 rdev->sb_loaded = 0;
43338 rdev->bb_page = NULL;
43339 atomic_set(&rdev->nr_pending, 0);
43340- atomic_set(&rdev->read_errors, 0);
43341- atomic_set(&rdev->corrected_errors, 0);
43342+ atomic_set_unchecked(&rdev->read_errors, 0);
43343+ atomic_set_unchecked(&rdev->corrected_errors, 0);
43344
43345 INIT_LIST_HEAD(&rdev->same_set);
43346 init_waitqueue_head(&rdev->blocked_wait);
43347@@ -7038,7 +7038,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
43348
43349 spin_unlock(&pers_lock);
43350 seq_printf(seq, "\n");
43351- seq->poll_event = atomic_read(&md_event_count);
43352+ seq->poll_event = atomic_read_unchecked(&md_event_count);
43353 return 0;
43354 }
43355 if (v == (void*)2) {
43356@@ -7141,7 +7141,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
43357 return error;
43358
43359 seq = file->private_data;
43360- seq->poll_event = atomic_read(&md_event_count);
43361+ seq->poll_event = atomic_read_unchecked(&md_event_count);
43362 return error;
43363 }
43364
43365@@ -7155,7 +7155,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
43366 /* always allow read */
43367 mask = POLLIN | POLLRDNORM;
43368
43369- if (seq->poll_event != atomic_read(&md_event_count))
43370+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
43371 mask |= POLLERR | POLLPRI;
43372 return mask;
43373 }
43374@@ -7199,7 +7199,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
43375 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
43376 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
43377 (int)part_stat_read(&disk->part0, sectors[1]) -
43378- atomic_read(&disk->sync_io);
43379+ atomic_read_unchecked(&disk->sync_io);
43380 /* sync IO will cause sync_io to increase before the disk_stats
43381 * as sync_io is counted when a request starts, and
43382 * disk_stats is counted when it completes.
43383diff --git a/drivers/md/md.h b/drivers/md/md.h
43384index 0095ec8..c89277a 100644
43385--- a/drivers/md/md.h
43386+++ b/drivers/md/md.h
43387@@ -94,13 +94,13 @@ struct md_rdev {
43388 * only maintained for arrays that
43389 * support hot removal
43390 */
43391- atomic_t read_errors; /* number of consecutive read errors that
43392+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
43393 * we have tried to ignore.
43394 */
43395 struct timespec last_read_error; /* monotonic time since our
43396 * last read error
43397 */
43398- atomic_t corrected_errors; /* number of corrected read errors,
43399+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
43400 * for reporting to userspace and storing
43401 * in superblock.
43402 */
43403@@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
43404
43405 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
43406 {
43407- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
43408+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
43409 }
43410
43411 struct md_personality
43412diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
43413index 3e6d115..ffecdeb 100644
43414--- a/drivers/md/persistent-data/dm-space-map.h
43415+++ b/drivers/md/persistent-data/dm-space-map.h
43416@@ -71,6 +71,7 @@ struct dm_space_map {
43417 dm_sm_threshold_fn fn,
43418 void *context);
43419 };
43420+typedef struct dm_space_map __no_const dm_space_map_no_const;
43421
43422 /*----------------------------------------------------------------*/
43423
43424diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
43425index a49cfcc..20b9a65 100644
43426--- a/drivers/md/raid1.c
43427+++ b/drivers/md/raid1.c
43428@@ -1921,7 +1921,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
43429 if (r1_sync_page_io(rdev, sect, s,
43430 bio->bi_io_vec[idx].bv_page,
43431 READ) != 0)
43432- atomic_add(s, &rdev->corrected_errors);
43433+ atomic_add_unchecked(s, &rdev->corrected_errors);
43434 }
43435 sectors -= s;
43436 sect += s;
43437@@ -2148,7 +2148,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
43438 test_bit(In_sync, &rdev->flags)) {
43439 if (r1_sync_page_io(rdev, sect, s,
43440 conf->tmppage, READ)) {
43441- atomic_add(s, &rdev->corrected_errors);
43442+ atomic_add_unchecked(s, &rdev->corrected_errors);
43443 printk(KERN_INFO
43444 "md/raid1:%s: read error corrected "
43445 "(%d sectors at %llu on %s)\n",
43446diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
43447index 06eeb99..770613e 100644
43448--- a/drivers/md/raid10.c
43449+++ b/drivers/md/raid10.c
43450@@ -1963,7 +1963,7 @@ static void end_sync_read(struct bio *bio, int error)
43451 /* The write handler will notice the lack of
43452 * R10BIO_Uptodate and record any errors etc
43453 */
43454- atomic_add(r10_bio->sectors,
43455+ atomic_add_unchecked(r10_bio->sectors,
43456 &conf->mirrors[d].rdev->corrected_errors);
43457
43458 /* for reconstruct, we always reschedule after a read.
43459@@ -2321,7 +2321,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
43460 {
43461 struct timespec cur_time_mon;
43462 unsigned long hours_since_last;
43463- unsigned int read_errors = atomic_read(&rdev->read_errors);
43464+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
43465
43466 ktime_get_ts(&cur_time_mon);
43467
43468@@ -2343,9 +2343,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
43469 * overflowing the shift of read_errors by hours_since_last.
43470 */
43471 if (hours_since_last >= 8 * sizeof(read_errors))
43472- atomic_set(&rdev->read_errors, 0);
43473+ atomic_set_unchecked(&rdev->read_errors, 0);
43474 else
43475- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
43476+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
43477 }
43478
43479 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
43480@@ -2399,8 +2399,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
43481 return;
43482
43483 check_decay_read_errors(mddev, rdev);
43484- atomic_inc(&rdev->read_errors);
43485- if (atomic_read(&rdev->read_errors) > max_read_errors) {
43486+ atomic_inc_unchecked(&rdev->read_errors);
43487+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
43488 char b[BDEVNAME_SIZE];
43489 bdevname(rdev->bdev, b);
43490
43491@@ -2408,7 +2408,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
43492 "md/raid10:%s: %s: Raid device exceeded "
43493 "read_error threshold [cur %d:max %d]\n",
43494 mdname(mddev), b,
43495- atomic_read(&rdev->read_errors), max_read_errors);
43496+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
43497 printk(KERN_NOTICE
43498 "md/raid10:%s: %s: Failing raid device\n",
43499 mdname(mddev), b);
43500@@ -2563,7 +2563,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
43501 sect +
43502 choose_data_offset(r10_bio, rdev)),
43503 bdevname(rdev->bdev, b));
43504- atomic_add(s, &rdev->corrected_errors);
43505+ atomic_add_unchecked(s, &rdev->corrected_errors);
43506 }
43507
43508 rdev_dec_pending(rdev, mddev);
43509diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
43510index 03f82ab..374bb38 100644
43511--- a/drivers/md/raid5.c
43512+++ b/drivers/md/raid5.c
43513@@ -1991,21 +1991,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
43514 mdname(conf->mddev), STRIPE_SECTORS,
43515 (unsigned long long)s,
43516 bdevname(rdev->bdev, b));
43517- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
43518+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
43519 clear_bit(R5_ReadError, &sh->dev[i].flags);
43520 clear_bit(R5_ReWrite, &sh->dev[i].flags);
43521 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
43522 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
43523
43524- if (atomic_read(&rdev->read_errors))
43525- atomic_set(&rdev->read_errors, 0);
43526+ if (atomic_read_unchecked(&rdev->read_errors))
43527+ atomic_set_unchecked(&rdev->read_errors, 0);
43528 } else {
43529 const char *bdn = bdevname(rdev->bdev, b);
43530 int retry = 0;
43531 int set_bad = 0;
43532
43533 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
43534- atomic_inc(&rdev->read_errors);
43535+ atomic_inc_unchecked(&rdev->read_errors);
43536 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
43537 printk_ratelimited(
43538 KERN_WARNING
43539@@ -2033,7 +2033,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
43540 mdname(conf->mddev),
43541 (unsigned long long)s,
43542 bdn);
43543- } else if (atomic_read(&rdev->read_errors)
43544+ } else if (atomic_read_unchecked(&rdev->read_errors)
43545 > conf->max_nr_stripes)
43546 printk(KERN_WARNING
43547 "md/raid:%s: Too many read errors, failing device %s.\n",
43548diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
43549index 983db75..ef9248c 100644
43550--- a/drivers/media/dvb-core/dvbdev.c
43551+++ b/drivers/media/dvb-core/dvbdev.c
43552@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
43553 const struct dvb_device *template, void *priv, int type)
43554 {
43555 struct dvb_device *dvbdev;
43556- struct file_operations *dvbdevfops;
43557+ file_operations_no_const *dvbdevfops;
43558 struct device *clsdev;
43559 int minor;
43560 int id;
43561diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
43562index 9b6c3bb..baeb5c7 100644
43563--- a/drivers/media/dvb-frontends/dib3000.h
43564+++ b/drivers/media/dvb-frontends/dib3000.h
43565@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
43566 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
43567 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
43568 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
43569-};
43570+} __no_const;
43571
43572 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
43573 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
43574diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
43575index ed8cb90..5ef7f79 100644
43576--- a/drivers/media/pci/cx88/cx88-video.c
43577+++ b/drivers/media/pci/cx88/cx88-video.c
43578@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
43579
43580 /* ------------------------------------------------------------------ */
43581
43582-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43583-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43584-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43585+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43586+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43587+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43588
43589 module_param_array(video_nr, int, NULL, 0444);
43590 module_param_array(vbi_nr, int, NULL, 0444);
43591diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
43592index 802642d..5534900 100644
43593--- a/drivers/media/pci/ivtv/ivtv-driver.c
43594+++ b/drivers/media/pci/ivtv/ivtv-driver.c
43595@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
43596 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
43597
43598 /* ivtv instance counter */
43599-static atomic_t ivtv_instance = ATOMIC_INIT(0);
43600+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
43601
43602 /* Parameter declarations */
43603 static int cardtype[IVTV_MAX_CARDS];
43604diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
43605index dfd0a21..6bbb465 100644
43606--- a/drivers/media/platform/omap/omap_vout.c
43607+++ b/drivers/media/platform/omap/omap_vout.c
43608@@ -63,7 +63,6 @@ enum omap_vout_channels {
43609 OMAP_VIDEO2,
43610 };
43611
43612-static struct videobuf_queue_ops video_vbq_ops;
43613 /* Variables configurable through module params*/
43614 static u32 video1_numbuffers = 3;
43615 static u32 video2_numbuffers = 3;
43616@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
43617 {
43618 struct videobuf_queue *q;
43619 struct omap_vout_device *vout = NULL;
43620+ static struct videobuf_queue_ops video_vbq_ops = {
43621+ .buf_setup = omap_vout_buffer_setup,
43622+ .buf_prepare = omap_vout_buffer_prepare,
43623+ .buf_release = omap_vout_buffer_release,
43624+ .buf_queue = omap_vout_buffer_queue,
43625+ };
43626
43627 vout = video_drvdata(file);
43628 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
43629@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
43630 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
43631
43632 q = &vout->vbq;
43633- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
43634- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
43635- video_vbq_ops.buf_release = omap_vout_buffer_release;
43636- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
43637 spin_lock_init(&vout->vbq_lock);
43638
43639 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
43640diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
43641index fb2acc5..a2fcbdc4 100644
43642--- a/drivers/media/platform/s5p-tv/mixer.h
43643+++ b/drivers/media/platform/s5p-tv/mixer.h
43644@@ -156,7 +156,7 @@ struct mxr_layer {
43645 /** layer index (unique identifier) */
43646 int idx;
43647 /** callbacks for layer methods */
43648- struct mxr_layer_ops ops;
43649+ struct mxr_layer_ops *ops;
43650 /** format array */
43651 const struct mxr_format **fmt_array;
43652 /** size of format array */
43653diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43654index 74344c7..a39e70e 100644
43655--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43656+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43657@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
43658 {
43659 struct mxr_layer *layer;
43660 int ret;
43661- struct mxr_layer_ops ops = {
43662+ static struct mxr_layer_ops ops = {
43663 .release = mxr_graph_layer_release,
43664 .buffer_set = mxr_graph_buffer_set,
43665 .stream_set = mxr_graph_stream_set,
43666diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
43667index b713403..53cb5ad 100644
43668--- a/drivers/media/platform/s5p-tv/mixer_reg.c
43669+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
43670@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
43671 layer->update_buf = next;
43672 }
43673
43674- layer->ops.buffer_set(layer, layer->update_buf);
43675+ layer->ops->buffer_set(layer, layer->update_buf);
43676
43677 if (done && done != layer->shadow_buf)
43678 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
43679diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
43680index 81b97db..b089ccd 100644
43681--- a/drivers/media/platform/s5p-tv/mixer_video.c
43682+++ b/drivers/media/platform/s5p-tv/mixer_video.c
43683@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
43684 layer->geo.src.height = layer->geo.src.full_height;
43685
43686 mxr_geometry_dump(mdev, &layer->geo);
43687- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43688+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43689 mxr_geometry_dump(mdev, &layer->geo);
43690 }
43691
43692@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
43693 layer->geo.dst.full_width = mbus_fmt.width;
43694 layer->geo.dst.full_height = mbus_fmt.height;
43695 layer->geo.dst.field = mbus_fmt.field;
43696- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43697+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43698
43699 mxr_geometry_dump(mdev, &layer->geo);
43700 }
43701@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
43702 /* set source size to highest accepted value */
43703 geo->src.full_width = max(geo->dst.full_width, pix->width);
43704 geo->src.full_height = max(geo->dst.full_height, pix->height);
43705- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43706+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43707 mxr_geometry_dump(mdev, &layer->geo);
43708 /* set cropping to total visible screen */
43709 geo->src.width = pix->width;
43710@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
43711 geo->src.x_offset = 0;
43712 geo->src.y_offset = 0;
43713 /* assure consistency of geometry */
43714- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
43715+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
43716 mxr_geometry_dump(mdev, &layer->geo);
43717 /* set full size to lowest possible value */
43718 geo->src.full_width = 0;
43719 geo->src.full_height = 0;
43720- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43721+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43722 mxr_geometry_dump(mdev, &layer->geo);
43723
43724 /* returning results */
43725@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
43726 target->width = s->r.width;
43727 target->height = s->r.height;
43728
43729- layer->ops.fix_geometry(layer, stage, s->flags);
43730+ layer->ops->fix_geometry(layer, stage, s->flags);
43731
43732 /* retrieve update selection rectangle */
43733 res.left = target->x_offset;
43734@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
43735 mxr_output_get(mdev);
43736
43737 mxr_layer_update_output(layer);
43738- layer->ops.format_set(layer);
43739+ layer->ops->format_set(layer);
43740 /* enabling layer in hardware */
43741 spin_lock_irqsave(&layer->enq_slock, flags);
43742 layer->state = MXR_LAYER_STREAMING;
43743 spin_unlock_irqrestore(&layer->enq_slock, flags);
43744
43745- layer->ops.stream_set(layer, MXR_ENABLE);
43746+ layer->ops->stream_set(layer, MXR_ENABLE);
43747 mxr_streamer_get(mdev);
43748
43749 return 0;
43750@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
43751 spin_unlock_irqrestore(&layer->enq_slock, flags);
43752
43753 /* disabling layer in hardware */
43754- layer->ops.stream_set(layer, MXR_DISABLE);
43755+ layer->ops->stream_set(layer, MXR_DISABLE);
43756 /* remove one streamer */
43757 mxr_streamer_put(mdev);
43758 /* allow changes in output configuration */
43759@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
43760
43761 void mxr_layer_release(struct mxr_layer *layer)
43762 {
43763- if (layer->ops.release)
43764- layer->ops.release(layer);
43765+ if (layer->ops->release)
43766+ layer->ops->release(layer);
43767 }
43768
43769 void mxr_base_layer_release(struct mxr_layer *layer)
43770@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
43771
43772 layer->mdev = mdev;
43773 layer->idx = idx;
43774- layer->ops = *ops;
43775+ layer->ops = ops;
43776
43777 spin_lock_init(&layer->enq_slock);
43778 INIT_LIST_HEAD(&layer->enq_list);
43779diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43780index c9388c4..ce71ece 100644
43781--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43782+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43783@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
43784 {
43785 struct mxr_layer *layer;
43786 int ret;
43787- struct mxr_layer_ops ops = {
43788+ static struct mxr_layer_ops ops = {
43789 .release = mxr_vp_layer_release,
43790 .buffer_set = mxr_vp_buffer_set,
43791 .stream_set = mxr_vp_stream_set,
43792diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
43793index 2d4e73b..8b4d5b6 100644
43794--- a/drivers/media/platform/vivi.c
43795+++ b/drivers/media/platform/vivi.c
43796@@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
43797 MODULE_LICENSE("Dual BSD/GPL");
43798 MODULE_VERSION(VIVI_VERSION);
43799
43800-static unsigned video_nr = -1;
43801-module_param(video_nr, uint, 0644);
43802+static int video_nr = -1;
43803+module_param(video_nr, int, 0644);
43804 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
43805
43806 static unsigned n_devs = 1;
43807diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
43808index 545c04c..a14bded 100644
43809--- a/drivers/media/radio/radio-cadet.c
43810+++ b/drivers/media/radio/radio-cadet.c
43811@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43812 unsigned char readbuf[RDS_BUFFER];
43813 int i = 0;
43814
43815+ if (count > RDS_BUFFER)
43816+ return -EFAULT;
43817 mutex_lock(&dev->lock);
43818 if (dev->rdsstat == 0)
43819 cadet_start_rds(dev);
43820@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43821 while (i < count && dev->rdsin != dev->rdsout)
43822 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
43823
43824- if (i && copy_to_user(data, readbuf, i))
43825+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
43826 i = -EFAULT;
43827 unlock:
43828 mutex_unlock(&dev->lock);
43829diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
43830index 5236035..c622c74 100644
43831--- a/drivers/media/radio/radio-maxiradio.c
43832+++ b/drivers/media/radio/radio-maxiradio.c
43833@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
43834 /* TEA5757 pin mappings */
43835 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
43836
43837-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
43838+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
43839
43840 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
43841 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
43842diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
43843index 050b3bb..79f62b9 100644
43844--- a/drivers/media/radio/radio-shark.c
43845+++ b/drivers/media/radio/radio-shark.c
43846@@ -79,7 +79,7 @@ struct shark_device {
43847 u32 last_val;
43848 };
43849
43850-static atomic_t shark_instance = ATOMIC_INIT(0);
43851+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43852
43853 static void shark_write_val(struct snd_tea575x *tea, u32 val)
43854 {
43855diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
43856index 8654e0d..0608a64 100644
43857--- a/drivers/media/radio/radio-shark2.c
43858+++ b/drivers/media/radio/radio-shark2.c
43859@@ -74,7 +74,7 @@ struct shark_device {
43860 u8 *transfer_buffer;
43861 };
43862
43863-static atomic_t shark_instance = ATOMIC_INIT(0);
43864+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43865
43866 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
43867 {
43868diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
43869index 2fd9009..278cc1e 100644
43870--- a/drivers/media/radio/radio-si476x.c
43871+++ b/drivers/media/radio/radio-si476x.c
43872@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
43873 struct si476x_radio *radio;
43874 struct v4l2_ctrl *ctrl;
43875
43876- static atomic_t instance = ATOMIC_INIT(0);
43877+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
43878
43879 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
43880 if (!radio)
43881diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
43882index 46da365..3ba4206 100644
43883--- a/drivers/media/rc/rc-main.c
43884+++ b/drivers/media/rc/rc-main.c
43885@@ -1065,7 +1065,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
43886 int rc_register_device(struct rc_dev *dev)
43887 {
43888 static bool raw_init = false; /* raw decoders loaded? */
43889- static atomic_t devno = ATOMIC_INIT(0);
43890+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
43891 struct rc_map *rc_map;
43892 const char *path;
43893 int rc;
43894@@ -1096,7 +1096,7 @@ int rc_register_device(struct rc_dev *dev)
43895 */
43896 mutex_lock(&dev->lock);
43897
43898- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
43899+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
43900 dev_set_name(&dev->dev, "rc%ld", dev->devno);
43901 dev_set_drvdata(&dev->dev, dev);
43902 rc = device_add(&dev->dev);
43903diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
43904index 20e345d..da56fe4 100644
43905--- a/drivers/media/usb/dvb-usb/cxusb.c
43906+++ b/drivers/media/usb/dvb-usb/cxusb.c
43907@@ -1101,7 +1101,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
43908
43909 struct dib0700_adapter_state {
43910 int (*set_param_save) (struct dvb_frontend *);
43911-};
43912+} __no_const;
43913
43914 static int dib7070_set_param_override(struct dvb_frontend *fe)
43915 {
43916diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
43917index c1a63b2..dbcbfb6 100644
43918--- a/drivers/media/usb/dvb-usb/dw2102.c
43919+++ b/drivers/media/usb/dvb-usb/dw2102.c
43920@@ -121,7 +121,7 @@ struct su3000_state {
43921
43922 struct s6x0_state {
43923 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
43924-};
43925+} __no_const;
43926
43927 /* debug */
43928 static int dvb_usb_dw2102_debug;
43929diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43930index 8f7a6a4..eb0e1d4 100644
43931--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43932+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43933@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
43934 __u32 reserved;
43935 };
43936
43937-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43938+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43939 enum v4l2_memory memory)
43940 {
43941 void __user *up_pln;
43942@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43943 return 0;
43944 }
43945
43946-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43947+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43948 enum v4l2_memory memory)
43949 {
43950 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
43951@@ -425,7 +425,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
43952 * by passing a very big num_planes value */
43953 uplane = compat_alloc_user_space(num_planes *
43954 sizeof(struct v4l2_plane));
43955- kp->m.planes = uplane;
43956+ kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
43957
43958 while (--num_planes >= 0) {
43959 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
43960@@ -496,7 +496,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
43961 if (num_planes == 0)
43962 return 0;
43963
43964- uplane = kp->m.planes;
43965+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
43966 if (get_user(p, &up->m.planes))
43967 return -EFAULT;
43968 uplane32 = compat_ptr(p);
43969@@ -550,7 +550,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
43970 get_user(kp->capability, &up->capability) ||
43971 get_user(kp->flags, &up->flags))
43972 return -EFAULT;
43973- kp->base = compat_ptr(tmp);
43974+ kp->base = (void __force_kernel *)compat_ptr(tmp);
43975 get_v4l2_pix_format(&kp->fmt, &up->fmt);
43976 return 0;
43977 }
43978@@ -656,7 +656,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
43979 n * sizeof(struct v4l2_ext_control32)))
43980 return -EFAULT;
43981 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
43982- kp->controls = kcontrols;
43983+ kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
43984 while (--n >= 0) {
43985 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
43986 return -EFAULT;
43987@@ -678,7 +678,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
43988 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
43989 {
43990 struct v4l2_ext_control32 __user *ucontrols;
43991- struct v4l2_ext_control __user *kcontrols = kp->controls;
43992+ struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
43993 int n = kp->count;
43994 compat_caddr_t p;
43995
43996@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
43997 put_user(kp->start_block, &up->start_block) ||
43998 put_user(kp->blocks, &up->blocks) ||
43999 put_user(tmp, &up->edid) ||
44000- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
44001+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
44002 return -EFAULT;
44003 return 0;
44004 }
44005diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
44006index fb46790..ae1f8fa 100644
44007--- a/drivers/media/v4l2-core/v4l2-ctrls.c
44008+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
44009@@ -1396,8 +1396,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
44010 return 0;
44011
44012 case V4L2_CTRL_TYPE_STRING:
44013- len = strlen(c->string);
44014- if (len < ctrl->minimum)
44015+ len = strlen_user(c->string);
44016+ if (!len || len < ctrl->minimum)
44017 return -ERANGE;
44018 if ((len - ctrl->minimum) % ctrl->step)
44019 return -ERANGE;
44020diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
44021index 02d1b63..5fd6b16 100644
44022--- a/drivers/media/v4l2-core/v4l2-device.c
44023+++ b/drivers/media/v4l2-core/v4l2-device.c
44024@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
44025 EXPORT_SYMBOL_GPL(v4l2_device_put);
44026
44027 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
44028- atomic_t *instance)
44029+ atomic_unchecked_t *instance)
44030 {
44031- int num = atomic_inc_return(instance) - 1;
44032+ int num = atomic_inc_return_unchecked(instance) - 1;
44033 int len = strlen(basename);
44034
44035 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
44036diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
44037index 68e6b5e..8eb2aec 100644
44038--- a/drivers/media/v4l2-core/v4l2-ioctl.c
44039+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
44040@@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
44041 struct file *file, void *fh, void *p);
44042 } u;
44043 void (*debug)(const void *arg, bool write_only);
44044-};
44045+} __do_const;
44046+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
44047
44048 /* This control needs a priority check */
44049 #define INFO_FL_PRIO (1 << 0)
44050@@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
44051 struct video_device *vfd = video_devdata(file);
44052 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
44053 bool write_only = false;
44054- struct v4l2_ioctl_info default_info;
44055+ v4l2_ioctl_info_no_const default_info;
44056 const struct v4l2_ioctl_info *info;
44057 void *fh = file->private_data;
44058 struct v4l2_fh *vfh = NULL;
44059@@ -2194,7 +2195,7 @@ done:
44060 }
44061
44062 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44063- void * __user *user_ptr, void ***kernel_ptr)
44064+ void __user **user_ptr, void ***kernel_ptr)
44065 {
44066 int ret = 0;
44067
44068@@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44069 ret = -EINVAL;
44070 break;
44071 }
44072- *user_ptr = (void __user *)buf->m.planes;
44073+ *user_ptr = (void __force_user *)buf->m.planes;
44074 *kernel_ptr = (void *)&buf->m.planes;
44075 *array_size = sizeof(struct v4l2_plane) * buf->length;
44076 ret = 1;
44077@@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44078 ret = -EINVAL;
44079 break;
44080 }
44081- *user_ptr = (void __user *)ctrls->controls;
44082+ *user_ptr = (void __force_user *)ctrls->controls;
44083 *kernel_ptr = (void *)&ctrls->controls;
44084 *array_size = sizeof(struct v4l2_ext_control)
44085 * ctrls->count;
44086@@ -2340,7 +2341,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
44087 err = -ENOTTY;
44088
44089 if (has_array_args) {
44090- *kernel_ptr = user_ptr;
44091+ *kernel_ptr = (void __force_kernel *)user_ptr;
44092 if (copy_to_user(user_ptr, mbuf, array_size))
44093 err = -EFAULT;
44094 goto out_array_args;
44095diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
44096index 767ff4d..c69d259 100644
44097--- a/drivers/message/fusion/mptbase.c
44098+++ b/drivers/message/fusion/mptbase.c
44099@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44100 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
44101 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
44102
44103+#ifdef CONFIG_GRKERNSEC_HIDESYM
44104+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
44105+#else
44106 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
44107 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
44108+#endif
44109+
44110 /*
44111 * Rounding UP to nearest 4-kB boundary here...
44112 */
44113@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44114 ioc->facts.GlobalCredits);
44115
44116 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
44117+#ifdef CONFIG_GRKERNSEC_HIDESYM
44118+ NULL, NULL);
44119+#else
44120 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
44121+#endif
44122 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
44123 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
44124 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
44125diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
44126index dd239bd..689c4f7 100644
44127--- a/drivers/message/fusion/mptsas.c
44128+++ b/drivers/message/fusion/mptsas.c
44129@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
44130 return 0;
44131 }
44132
44133+static inline void
44134+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44135+{
44136+ if (phy_info->port_details) {
44137+ phy_info->port_details->rphy = rphy;
44138+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44139+ ioc->name, rphy));
44140+ }
44141+
44142+ if (rphy) {
44143+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44144+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44145+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44146+ ioc->name, rphy, rphy->dev.release));
44147+ }
44148+}
44149+
44150 /* no mutex */
44151 static void
44152 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
44153@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
44154 return NULL;
44155 }
44156
44157-static inline void
44158-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44159-{
44160- if (phy_info->port_details) {
44161- phy_info->port_details->rphy = rphy;
44162- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44163- ioc->name, rphy));
44164- }
44165-
44166- if (rphy) {
44167- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44168- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44169- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44170- ioc->name, rphy, rphy->dev.release));
44171- }
44172-}
44173-
44174 static inline struct sas_port *
44175 mptsas_get_port(struct mptsas_phyinfo *phy_info)
44176 {
44177diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
44178index 727819c..ad74694 100644
44179--- a/drivers/message/fusion/mptscsih.c
44180+++ b/drivers/message/fusion/mptscsih.c
44181@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
44182
44183 h = shost_priv(SChost);
44184
44185- if (h) {
44186- if (h->info_kbuf == NULL)
44187- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44188- return h->info_kbuf;
44189- h->info_kbuf[0] = '\0';
44190+ if (!h)
44191+ return NULL;
44192
44193- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44194- h->info_kbuf[size-1] = '\0';
44195- }
44196+ if (h->info_kbuf == NULL)
44197+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44198+ return h->info_kbuf;
44199+ h->info_kbuf[0] = '\0';
44200+
44201+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44202+ h->info_kbuf[size-1] = '\0';
44203
44204 return h->info_kbuf;
44205 }
44206diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
44207index b7d87cd..3fb36da 100644
44208--- a/drivers/message/i2o/i2o_proc.c
44209+++ b/drivers/message/i2o/i2o_proc.c
44210@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
44211 "Array Controller Device"
44212 };
44213
44214-static char *chtostr(char *tmp, u8 *chars, int n)
44215-{
44216- tmp[0] = 0;
44217- return strncat(tmp, (char *)chars, n);
44218-}
44219-
44220 static int i2o_report_query_status(struct seq_file *seq, int block_status,
44221 char *group)
44222 {
44223@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
44224 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
44225 {
44226 struct i2o_controller *c = (struct i2o_controller *)seq->private;
44227- static u32 work32[5];
44228- static u8 *work8 = (u8 *) work32;
44229- static u16 *work16 = (u16 *) work32;
44230+ u32 work32[5];
44231+ u8 *work8 = (u8 *) work32;
44232+ u16 *work16 = (u16 *) work32;
44233 int token;
44234 u32 hwcap;
44235
44236@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44237 } *result;
44238
44239 i2o_exec_execute_ddm_table ddm_table;
44240- char tmp[28 + 1];
44241
44242 result = kmalloc(sizeof(*result), GFP_KERNEL);
44243 if (!result)
44244@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44245
44246 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
44247 seq_printf(seq, "%-#8x", ddm_table.module_id);
44248- seq_printf(seq, "%-29s",
44249- chtostr(tmp, ddm_table.module_name_version, 28));
44250+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
44251 seq_printf(seq, "%9d ", ddm_table.data_size);
44252 seq_printf(seq, "%8d", ddm_table.code_size);
44253
44254@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44255
44256 i2o_driver_result_table *result;
44257 i2o_driver_store_table *dst;
44258- char tmp[28 + 1];
44259
44260 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
44261 if (result == NULL)
44262@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44263
44264 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
44265 seq_printf(seq, "%-#8x", dst->module_id);
44266- seq_printf(seq, "%-29s",
44267- chtostr(tmp, dst->module_name_version, 28));
44268- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
44269+ seq_printf(seq, "%-.28s", dst->module_name_version);
44270+ seq_printf(seq, "%-.8s", dst->date);
44271 seq_printf(seq, "%8d ", dst->module_size);
44272 seq_printf(seq, "%8d ", dst->mpb_size);
44273 seq_printf(seq, "0x%04x", dst->module_flags);
44274@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
44275 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44276 {
44277 struct i2o_device *d = (struct i2o_device *)seq->private;
44278- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44279+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44280 // == (allow) 512d bytes (max)
44281- static u16 *work16 = (u16 *) work32;
44282+ u16 *work16 = (u16 *) work32;
44283 int token;
44284- char tmp[16 + 1];
44285
44286 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
44287
44288@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44289 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
44290 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
44291 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
44292- seq_printf(seq, "Vendor info : %s\n",
44293- chtostr(tmp, (u8 *) (work32 + 2), 16));
44294- seq_printf(seq, "Product info : %s\n",
44295- chtostr(tmp, (u8 *) (work32 + 6), 16));
44296- seq_printf(seq, "Description : %s\n",
44297- chtostr(tmp, (u8 *) (work32 + 10), 16));
44298- seq_printf(seq, "Product rev. : %s\n",
44299- chtostr(tmp, (u8 *) (work32 + 14), 8));
44300+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
44301+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
44302+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
44303+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
44304
44305 seq_printf(seq, "Serial number : ");
44306 print_serial_number(seq, (u8 *) (work32 + 16),
44307@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44308 u8 pad[256]; // allow up to 256 byte (max) serial number
44309 } result;
44310
44311- char tmp[24 + 1];
44312-
44313 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
44314
44315 if (token < 0) {
44316@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44317 }
44318
44319 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
44320- seq_printf(seq, "Module name : %s\n",
44321- chtostr(tmp, result.module_name, 24));
44322- seq_printf(seq, "Module revision : %s\n",
44323- chtostr(tmp, result.module_rev, 8));
44324+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
44325+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
44326
44327 seq_printf(seq, "Serial number : ");
44328 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
44329@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44330 u8 instance_number[4];
44331 } result;
44332
44333- char tmp[64 + 1];
44334-
44335 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
44336
44337 if (token < 0) {
44338@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44339 return 0;
44340 }
44341
44342- seq_printf(seq, "Device name : %s\n",
44343- chtostr(tmp, result.device_name, 64));
44344- seq_printf(seq, "Service name : %s\n",
44345- chtostr(tmp, result.service_name, 64));
44346- seq_printf(seq, "Physical name : %s\n",
44347- chtostr(tmp, result.physical_location, 64));
44348- seq_printf(seq, "Instance number : %s\n",
44349- chtostr(tmp, result.instance_number, 4));
44350+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
44351+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
44352+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
44353+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
44354
44355 return 0;
44356 }
44357@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44358 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
44359 {
44360 struct i2o_device *d = (struct i2o_device *)seq->private;
44361- static u32 work32[12];
44362- static u16 *work16 = (u16 *) work32;
44363- static u8 *work8 = (u8 *) work32;
44364+ u32 work32[12];
44365+ u16 *work16 = (u16 *) work32;
44366+ u8 *work8 = (u8 *) work32;
44367 int token;
44368
44369 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
44370diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
44371index a8c08f3..155fe3d 100644
44372--- a/drivers/message/i2o/iop.c
44373+++ b/drivers/message/i2o/iop.c
44374@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
44375
44376 spin_lock_irqsave(&c->context_list_lock, flags);
44377
44378- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
44379- atomic_inc(&c->context_list_counter);
44380+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
44381+ atomic_inc_unchecked(&c->context_list_counter);
44382
44383- entry->context = atomic_read(&c->context_list_counter);
44384+ entry->context = atomic_read_unchecked(&c->context_list_counter);
44385
44386 list_add(&entry->list, &c->context_list);
44387
44388@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
44389
44390 #if BITS_PER_LONG == 64
44391 spin_lock_init(&c->context_list_lock);
44392- atomic_set(&c->context_list_counter, 0);
44393+ atomic_set_unchecked(&c->context_list_counter, 0);
44394 INIT_LIST_HEAD(&c->context_list);
44395 #endif
44396
44397diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
44398index fcbb2e9..2635e11 100644
44399--- a/drivers/mfd/janz-cmodio.c
44400+++ b/drivers/mfd/janz-cmodio.c
44401@@ -13,6 +13,7 @@
44402
44403 #include <linux/kernel.h>
44404 #include <linux/module.h>
44405+#include <linux/slab.h>
44406 #include <linux/init.h>
44407 #include <linux/pci.h>
44408 #include <linux/interrupt.h>
44409diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
44410index 176aa26..27811b2 100644
44411--- a/drivers/mfd/max8925-i2c.c
44412+++ b/drivers/mfd/max8925-i2c.c
44413@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
44414 const struct i2c_device_id *id)
44415 {
44416 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
44417- static struct max8925_chip *chip;
44418+ struct max8925_chip *chip;
44419 struct device_node *node = client->dev.of_node;
44420
44421 if (node && !pdata) {
44422diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
44423index c0f608e..286f8ec 100644
44424--- a/drivers/mfd/tps65910.c
44425+++ b/drivers/mfd/tps65910.c
44426@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
44427 struct tps65910_platform_data *pdata)
44428 {
44429 int ret = 0;
44430- static struct regmap_irq_chip *tps6591x_irqs_chip;
44431+ struct regmap_irq_chip *tps6591x_irqs_chip;
44432
44433 if (!irq) {
44434 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
44435diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
44436index 9aa6d1e..1631bfc 100644
44437--- a/drivers/mfd/twl4030-irq.c
44438+++ b/drivers/mfd/twl4030-irq.c
44439@@ -35,6 +35,7 @@
44440 #include <linux/of.h>
44441 #include <linux/irqdomain.h>
44442 #include <linux/i2c/twl.h>
44443+#include <asm/pgtable.h>
44444
44445 #include "twl-core.h"
44446
44447@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
44448 * Install an irq handler for each of the SIH modules;
44449 * clone dummy irq_chip since PIH can't *do* anything
44450 */
44451- twl4030_irq_chip = dummy_irq_chip;
44452- twl4030_irq_chip.name = "twl4030";
44453+ pax_open_kernel();
44454+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
44455+ *(const char **)&twl4030_irq_chip.name = "twl4030";
44456
44457- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
44458+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
44459+ pax_close_kernel();
44460
44461 for (i = irq_base; i < irq_end; i++) {
44462 irq_set_chip_and_handler(i, &twl4030_irq_chip,
44463diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
44464index 464419b..64bae8d 100644
44465--- a/drivers/misc/c2port/core.c
44466+++ b/drivers/misc/c2port/core.c
44467@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
44468 goto error_idr_alloc;
44469 c2dev->id = ret;
44470
44471- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
44472+ pax_open_kernel();
44473+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
44474+ pax_close_kernel();
44475
44476 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
44477 "c2port%d", c2dev->id);
44478diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
44479index 9c34e57..b981cda 100644
44480--- a/drivers/misc/eeprom/sunxi_sid.c
44481+++ b/drivers/misc/eeprom/sunxi_sid.c
44482@@ -127,7 +127,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
44483
44484 platform_set_drvdata(pdev, sid_data);
44485
44486- sid_bin_attr.size = sid_data->keysize;
44487+ pax_open_kernel();
44488+ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
44489+ pax_close_kernel();
44490 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
44491 return -ENODEV;
44492
44493diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
44494index 36f5d52..32311c3 100644
44495--- a/drivers/misc/kgdbts.c
44496+++ b/drivers/misc/kgdbts.c
44497@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
44498 char before[BREAK_INSTR_SIZE];
44499 char after[BREAK_INSTR_SIZE];
44500
44501- probe_kernel_read(before, (char *)kgdbts_break_test,
44502+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
44503 BREAK_INSTR_SIZE);
44504 init_simple_test();
44505 ts.tst = plant_and_detach_test;
44506@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
44507 /* Activate test with initial breakpoint */
44508 if (!is_early)
44509 kgdb_breakpoint();
44510- probe_kernel_read(after, (char *)kgdbts_break_test,
44511+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
44512 BREAK_INSTR_SIZE);
44513 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
44514 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
44515diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
44516index 036effe..b3a6336 100644
44517--- a/drivers/misc/lis3lv02d/lis3lv02d.c
44518+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
44519@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
44520 * the lid is closed. This leads to interrupts as soon as a little move
44521 * is done.
44522 */
44523- atomic_inc(&lis3->count);
44524+ atomic_inc_unchecked(&lis3->count);
44525
44526 wake_up_interruptible(&lis3->misc_wait);
44527 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
44528@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
44529 if (lis3->pm_dev)
44530 pm_runtime_get_sync(lis3->pm_dev);
44531
44532- atomic_set(&lis3->count, 0);
44533+ atomic_set_unchecked(&lis3->count, 0);
44534 return 0;
44535 }
44536
44537@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
44538 add_wait_queue(&lis3->misc_wait, &wait);
44539 while (true) {
44540 set_current_state(TASK_INTERRUPTIBLE);
44541- data = atomic_xchg(&lis3->count, 0);
44542+ data = atomic_xchg_unchecked(&lis3->count, 0);
44543 if (data)
44544 break;
44545
44546@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
44547 struct lis3lv02d, miscdev);
44548
44549 poll_wait(file, &lis3->misc_wait, wait);
44550- if (atomic_read(&lis3->count))
44551+ if (atomic_read_unchecked(&lis3->count))
44552 return POLLIN | POLLRDNORM;
44553 return 0;
44554 }
44555diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
44556index c439c82..1f20f57 100644
44557--- a/drivers/misc/lis3lv02d/lis3lv02d.h
44558+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
44559@@ -297,7 +297,7 @@ struct lis3lv02d {
44560 struct input_polled_dev *idev; /* input device */
44561 struct platform_device *pdev; /* platform device */
44562 struct regulator_bulk_data regulators[2];
44563- atomic_t count; /* interrupt count after last read */
44564+ atomic_unchecked_t count; /* interrupt count after last read */
44565 union axis_conversion ac; /* hw -> logical axis */
44566 int mapped_btns[3];
44567
44568diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
44569index 2f30bad..c4c13d0 100644
44570--- a/drivers/misc/sgi-gru/gruhandles.c
44571+++ b/drivers/misc/sgi-gru/gruhandles.c
44572@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
44573 unsigned long nsec;
44574
44575 nsec = CLKS2NSEC(clks);
44576- atomic_long_inc(&mcs_op_statistics[op].count);
44577- atomic_long_add(nsec, &mcs_op_statistics[op].total);
44578+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
44579+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
44580 if (mcs_op_statistics[op].max < nsec)
44581 mcs_op_statistics[op].max = nsec;
44582 }
44583diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
44584index 4f76359..cdfcb2e 100644
44585--- a/drivers/misc/sgi-gru/gruprocfs.c
44586+++ b/drivers/misc/sgi-gru/gruprocfs.c
44587@@ -32,9 +32,9 @@
44588
44589 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
44590
44591-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
44592+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
44593 {
44594- unsigned long val = atomic_long_read(v);
44595+ unsigned long val = atomic_long_read_unchecked(v);
44596
44597 seq_printf(s, "%16lu %s\n", val, id);
44598 }
44599@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
44600
44601 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
44602 for (op = 0; op < mcsop_last; op++) {
44603- count = atomic_long_read(&mcs_op_statistics[op].count);
44604- total = atomic_long_read(&mcs_op_statistics[op].total);
44605+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
44606+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
44607 max = mcs_op_statistics[op].max;
44608 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
44609 count ? total / count : 0, max);
44610diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
44611index 5c3ce24..4915ccb 100644
44612--- a/drivers/misc/sgi-gru/grutables.h
44613+++ b/drivers/misc/sgi-gru/grutables.h
44614@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
44615 * GRU statistics.
44616 */
44617 struct gru_stats_s {
44618- atomic_long_t vdata_alloc;
44619- atomic_long_t vdata_free;
44620- atomic_long_t gts_alloc;
44621- atomic_long_t gts_free;
44622- atomic_long_t gms_alloc;
44623- atomic_long_t gms_free;
44624- atomic_long_t gts_double_allocate;
44625- atomic_long_t assign_context;
44626- atomic_long_t assign_context_failed;
44627- atomic_long_t free_context;
44628- atomic_long_t load_user_context;
44629- atomic_long_t load_kernel_context;
44630- atomic_long_t lock_kernel_context;
44631- atomic_long_t unlock_kernel_context;
44632- atomic_long_t steal_user_context;
44633- atomic_long_t steal_kernel_context;
44634- atomic_long_t steal_context_failed;
44635- atomic_long_t nopfn;
44636- atomic_long_t asid_new;
44637- atomic_long_t asid_next;
44638- atomic_long_t asid_wrap;
44639- atomic_long_t asid_reuse;
44640- atomic_long_t intr;
44641- atomic_long_t intr_cbr;
44642- atomic_long_t intr_tfh;
44643- atomic_long_t intr_spurious;
44644- atomic_long_t intr_mm_lock_failed;
44645- atomic_long_t call_os;
44646- atomic_long_t call_os_wait_queue;
44647- atomic_long_t user_flush_tlb;
44648- atomic_long_t user_unload_context;
44649- atomic_long_t user_exception;
44650- atomic_long_t set_context_option;
44651- atomic_long_t check_context_retarget_intr;
44652- atomic_long_t check_context_unload;
44653- atomic_long_t tlb_dropin;
44654- atomic_long_t tlb_preload_page;
44655- atomic_long_t tlb_dropin_fail_no_asid;
44656- atomic_long_t tlb_dropin_fail_upm;
44657- atomic_long_t tlb_dropin_fail_invalid;
44658- atomic_long_t tlb_dropin_fail_range_active;
44659- atomic_long_t tlb_dropin_fail_idle;
44660- atomic_long_t tlb_dropin_fail_fmm;
44661- atomic_long_t tlb_dropin_fail_no_exception;
44662- atomic_long_t tfh_stale_on_fault;
44663- atomic_long_t mmu_invalidate_range;
44664- atomic_long_t mmu_invalidate_page;
44665- atomic_long_t flush_tlb;
44666- atomic_long_t flush_tlb_gru;
44667- atomic_long_t flush_tlb_gru_tgh;
44668- atomic_long_t flush_tlb_gru_zero_asid;
44669+ atomic_long_unchecked_t vdata_alloc;
44670+ atomic_long_unchecked_t vdata_free;
44671+ atomic_long_unchecked_t gts_alloc;
44672+ atomic_long_unchecked_t gts_free;
44673+ atomic_long_unchecked_t gms_alloc;
44674+ atomic_long_unchecked_t gms_free;
44675+ atomic_long_unchecked_t gts_double_allocate;
44676+ atomic_long_unchecked_t assign_context;
44677+ atomic_long_unchecked_t assign_context_failed;
44678+ atomic_long_unchecked_t free_context;
44679+ atomic_long_unchecked_t load_user_context;
44680+ atomic_long_unchecked_t load_kernel_context;
44681+ atomic_long_unchecked_t lock_kernel_context;
44682+ atomic_long_unchecked_t unlock_kernel_context;
44683+ atomic_long_unchecked_t steal_user_context;
44684+ atomic_long_unchecked_t steal_kernel_context;
44685+ atomic_long_unchecked_t steal_context_failed;
44686+ atomic_long_unchecked_t nopfn;
44687+ atomic_long_unchecked_t asid_new;
44688+ atomic_long_unchecked_t asid_next;
44689+ atomic_long_unchecked_t asid_wrap;
44690+ atomic_long_unchecked_t asid_reuse;
44691+ atomic_long_unchecked_t intr;
44692+ atomic_long_unchecked_t intr_cbr;
44693+ atomic_long_unchecked_t intr_tfh;
44694+ atomic_long_unchecked_t intr_spurious;
44695+ atomic_long_unchecked_t intr_mm_lock_failed;
44696+ atomic_long_unchecked_t call_os;
44697+ atomic_long_unchecked_t call_os_wait_queue;
44698+ atomic_long_unchecked_t user_flush_tlb;
44699+ atomic_long_unchecked_t user_unload_context;
44700+ atomic_long_unchecked_t user_exception;
44701+ atomic_long_unchecked_t set_context_option;
44702+ atomic_long_unchecked_t check_context_retarget_intr;
44703+ atomic_long_unchecked_t check_context_unload;
44704+ atomic_long_unchecked_t tlb_dropin;
44705+ atomic_long_unchecked_t tlb_preload_page;
44706+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
44707+ atomic_long_unchecked_t tlb_dropin_fail_upm;
44708+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
44709+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
44710+ atomic_long_unchecked_t tlb_dropin_fail_idle;
44711+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
44712+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
44713+ atomic_long_unchecked_t tfh_stale_on_fault;
44714+ atomic_long_unchecked_t mmu_invalidate_range;
44715+ atomic_long_unchecked_t mmu_invalidate_page;
44716+ atomic_long_unchecked_t flush_tlb;
44717+ atomic_long_unchecked_t flush_tlb_gru;
44718+ atomic_long_unchecked_t flush_tlb_gru_tgh;
44719+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
44720
44721- atomic_long_t copy_gpa;
44722- atomic_long_t read_gpa;
44723+ atomic_long_unchecked_t copy_gpa;
44724+ atomic_long_unchecked_t read_gpa;
44725
44726- atomic_long_t mesq_receive;
44727- atomic_long_t mesq_receive_none;
44728- atomic_long_t mesq_send;
44729- atomic_long_t mesq_send_failed;
44730- atomic_long_t mesq_noop;
44731- atomic_long_t mesq_send_unexpected_error;
44732- atomic_long_t mesq_send_lb_overflow;
44733- atomic_long_t mesq_send_qlimit_reached;
44734- atomic_long_t mesq_send_amo_nacked;
44735- atomic_long_t mesq_send_put_nacked;
44736- atomic_long_t mesq_page_overflow;
44737- atomic_long_t mesq_qf_locked;
44738- atomic_long_t mesq_qf_noop_not_full;
44739- atomic_long_t mesq_qf_switch_head_failed;
44740- atomic_long_t mesq_qf_unexpected_error;
44741- atomic_long_t mesq_noop_unexpected_error;
44742- atomic_long_t mesq_noop_lb_overflow;
44743- atomic_long_t mesq_noop_qlimit_reached;
44744- atomic_long_t mesq_noop_amo_nacked;
44745- atomic_long_t mesq_noop_put_nacked;
44746- atomic_long_t mesq_noop_page_overflow;
44747+ atomic_long_unchecked_t mesq_receive;
44748+ atomic_long_unchecked_t mesq_receive_none;
44749+ atomic_long_unchecked_t mesq_send;
44750+ atomic_long_unchecked_t mesq_send_failed;
44751+ atomic_long_unchecked_t mesq_noop;
44752+ atomic_long_unchecked_t mesq_send_unexpected_error;
44753+ atomic_long_unchecked_t mesq_send_lb_overflow;
44754+ atomic_long_unchecked_t mesq_send_qlimit_reached;
44755+ atomic_long_unchecked_t mesq_send_amo_nacked;
44756+ atomic_long_unchecked_t mesq_send_put_nacked;
44757+ atomic_long_unchecked_t mesq_page_overflow;
44758+ atomic_long_unchecked_t mesq_qf_locked;
44759+ atomic_long_unchecked_t mesq_qf_noop_not_full;
44760+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
44761+ atomic_long_unchecked_t mesq_qf_unexpected_error;
44762+ atomic_long_unchecked_t mesq_noop_unexpected_error;
44763+ atomic_long_unchecked_t mesq_noop_lb_overflow;
44764+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
44765+ atomic_long_unchecked_t mesq_noop_amo_nacked;
44766+ atomic_long_unchecked_t mesq_noop_put_nacked;
44767+ atomic_long_unchecked_t mesq_noop_page_overflow;
44768
44769 };
44770
44771@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
44772 tghop_invalidate, mcsop_last};
44773
44774 struct mcs_op_statistic {
44775- atomic_long_t count;
44776- atomic_long_t total;
44777+ atomic_long_unchecked_t count;
44778+ atomic_long_unchecked_t total;
44779 unsigned long max;
44780 };
44781
44782@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
44783
44784 #define STAT(id) do { \
44785 if (gru_options & OPT_STATS) \
44786- atomic_long_inc(&gru_stats.id); \
44787+ atomic_long_inc_unchecked(&gru_stats.id); \
44788 } while (0)
44789
44790 #ifdef CONFIG_SGI_GRU_DEBUG
44791diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
44792index c862cd4..0d176fe 100644
44793--- a/drivers/misc/sgi-xp/xp.h
44794+++ b/drivers/misc/sgi-xp/xp.h
44795@@ -288,7 +288,7 @@ struct xpc_interface {
44796 xpc_notify_func, void *);
44797 void (*received) (short, int, void *);
44798 enum xp_retval (*partid_to_nasids) (short, void *);
44799-};
44800+} __no_const;
44801
44802 extern struct xpc_interface xpc_interface;
44803
44804diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
44805index 01be66d..e3a0c7e 100644
44806--- a/drivers/misc/sgi-xp/xp_main.c
44807+++ b/drivers/misc/sgi-xp/xp_main.c
44808@@ -78,13 +78,13 @@ xpc_notloaded(void)
44809 }
44810
44811 struct xpc_interface xpc_interface = {
44812- (void (*)(int))xpc_notloaded,
44813- (void (*)(int))xpc_notloaded,
44814- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
44815- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
44816+ .connect = (void (*)(int))xpc_notloaded,
44817+ .disconnect = (void (*)(int))xpc_notloaded,
44818+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
44819+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
44820 void *))xpc_notloaded,
44821- (void (*)(short, int, void *))xpc_notloaded,
44822- (enum xp_retval(*)(short, void *))xpc_notloaded
44823+ .received = (void (*)(short, int, void *))xpc_notloaded,
44824+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
44825 };
44826 EXPORT_SYMBOL_GPL(xpc_interface);
44827
44828diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
44829index b94d5f7..7f494c5 100644
44830--- a/drivers/misc/sgi-xp/xpc.h
44831+++ b/drivers/misc/sgi-xp/xpc.h
44832@@ -835,6 +835,7 @@ struct xpc_arch_operations {
44833 void (*received_payload) (struct xpc_channel *, void *);
44834 void (*notify_senders_of_disconnect) (struct xpc_channel *);
44835 };
44836+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
44837
44838 /* struct xpc_partition act_state values (for XPC HB) */
44839
44840@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
44841 /* found in xpc_main.c */
44842 extern struct device *xpc_part;
44843 extern struct device *xpc_chan;
44844-extern struct xpc_arch_operations xpc_arch_ops;
44845+extern xpc_arch_operations_no_const xpc_arch_ops;
44846 extern int xpc_disengage_timelimit;
44847 extern int xpc_disengage_timedout;
44848 extern int xpc_activate_IRQ_rcvd;
44849diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
44850index 82dc574..8539ab2 100644
44851--- a/drivers/misc/sgi-xp/xpc_main.c
44852+++ b/drivers/misc/sgi-xp/xpc_main.c
44853@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
44854 .notifier_call = xpc_system_die,
44855 };
44856
44857-struct xpc_arch_operations xpc_arch_ops;
44858+xpc_arch_operations_no_const xpc_arch_ops;
44859
44860 /*
44861 * Timer function to enforce the timelimit on the partition disengage.
44862@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
44863
44864 if (((die_args->trapnr == X86_TRAP_MF) ||
44865 (die_args->trapnr == X86_TRAP_XF)) &&
44866- !user_mode_vm(die_args->regs))
44867+ !user_mode(die_args->regs))
44868 xpc_die_deactivate();
44869
44870 break;
44871diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
44872index 29d5d98..fea356f 100644
44873--- a/drivers/mmc/card/block.c
44874+++ b/drivers/mmc/card/block.c
44875@@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
44876 if (idata->ic.postsleep_min_us)
44877 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
44878
44879- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
44880+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
44881 err = -EFAULT;
44882 goto cmd_rel_host;
44883 }
44884diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
44885index e5b5eeb..7bf2212 100644
44886--- a/drivers/mmc/core/mmc_ops.c
44887+++ b/drivers/mmc/core/mmc_ops.c
44888@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
44889 void *data_buf;
44890 int is_on_stack;
44891
44892- is_on_stack = object_is_on_stack(buf);
44893+ is_on_stack = object_starts_on_stack(buf);
44894 if (is_on_stack) {
44895 /*
44896 * dma onto stack is unsafe/nonportable, but callers to this
44897diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
44898index 6bf24ab..13d0293b 100644
44899--- a/drivers/mmc/host/dw_mmc.h
44900+++ b/drivers/mmc/host/dw_mmc.h
44901@@ -258,5 +258,5 @@ struct dw_mci_drv_data {
44902 int (*parse_dt)(struct dw_mci *host);
44903 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
44904 struct dw_mci_tuning_data *tuning_data);
44905-};
44906+} __do_const;
44907 #endif /* _DW_MMC_H_ */
44908diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
44909index f320579..7b7ebac 100644
44910--- a/drivers/mmc/host/mmci.c
44911+++ b/drivers/mmc/host/mmci.c
44912@@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
44913 }
44914
44915 if (variant->busy_detect) {
44916- mmci_ops.card_busy = mmci_card_busy;
44917+ pax_open_kernel();
44918+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
44919+ pax_close_kernel();
44920 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
44921 }
44922
44923diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
44924index 1dcaf8a..025af25 100644
44925--- a/drivers/mmc/host/sdhci-esdhc-imx.c
44926+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
44927@@ -1009,9 +1009,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
44928 host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
44929 }
44930
44931- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
44932- sdhci_esdhc_ops.platform_execute_tuning =
44933+ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
44934+ pax_open_kernel();
44935+ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
44936 esdhc_executing_tuning;
44937+ pax_close_kernel();
44938+ }
44939 boarddata = &imx_data->boarddata;
44940 if (sdhci_esdhc_imx_probe_dt(pdev, boarddata) < 0) {
44941 if (!host->mmc->parent->platform_data) {
44942diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
44943index 6debda9..2ba7427 100644
44944--- a/drivers/mmc/host/sdhci-s3c.c
44945+++ b/drivers/mmc/host/sdhci-s3c.c
44946@@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
44947 * we can use overriding functions instead of default.
44948 */
44949 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
44950- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44951- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44952- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44953+ pax_open_kernel();
44954+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44955+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44956+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44957+ pax_close_kernel();
44958 }
44959
44960 /* It supports additional host capabilities if needed */
44961diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
44962index 096993f..f02c23b 100644
44963--- a/drivers/mtd/chips/cfi_cmdset_0020.c
44964+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
44965@@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
44966 size_t totlen = 0, thislen;
44967 int ret = 0;
44968 size_t buflen = 0;
44969- static char *buffer;
44970+ char *buffer;
44971
44972 if (!ECCBUF_SIZE) {
44973 /* We should fall back to a general writev implementation.
44974diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
44975index 370b9dd..1a1176b 100644
44976--- a/drivers/mtd/nand/denali.c
44977+++ b/drivers/mtd/nand/denali.c
44978@@ -24,6 +24,7 @@
44979 #include <linux/slab.h>
44980 #include <linux/mtd/mtd.h>
44981 #include <linux/module.h>
44982+#include <linux/slab.h>
44983
44984 #include "denali.h"
44985
44986diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
44987index 51b9d6a..52af9a7 100644
44988--- a/drivers/mtd/nftlmount.c
44989+++ b/drivers/mtd/nftlmount.c
44990@@ -24,6 +24,7 @@
44991 #include <asm/errno.h>
44992 #include <linux/delay.h>
44993 #include <linux/slab.h>
44994+#include <linux/sched.h>
44995 #include <linux/mtd/mtd.h>
44996 #include <linux/mtd/nand.h>
44997 #include <linux/mtd/nftl.h>
44998diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
44999index 4b8e895..6b3c498 100644
45000--- a/drivers/mtd/sm_ftl.c
45001+++ b/drivers/mtd/sm_ftl.c
45002@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
45003 #define SM_CIS_VENDOR_OFFSET 0x59
45004 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
45005 {
45006- struct attribute_group *attr_group;
45007+ attribute_group_no_const *attr_group;
45008 struct attribute **attributes;
45009 struct sm_sysfs_attribute *vendor_attribute;
45010
45011diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
45012index 4b8c58b..a200546 100644
45013--- a/drivers/net/bonding/bond_main.c
45014+++ b/drivers/net/bonding/bond_main.c
45015@@ -4527,6 +4527,7 @@ static void __exit bonding_exit(void)
45016
45017 bond_netlink_fini();
45018 unregister_pernet_subsys(&bond_net_ops);
45019+ rtnl_link_unregister(&bond_link_ops);
45020
45021 #ifdef CONFIG_NET_POLL_CONTROLLER
45022 /*
45023diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
45024index 40e7b1c..6a70fff 100644
45025--- a/drivers/net/bonding/bond_netlink.c
45026+++ b/drivers/net/bonding/bond_netlink.c
45027@@ -102,7 +102,7 @@ nla_put_failure:
45028 return -EMSGSIZE;
45029 }
45030
45031-struct rtnl_link_ops bond_link_ops __read_mostly = {
45032+struct rtnl_link_ops bond_link_ops = {
45033 .kind = "bond",
45034 .priv_size = sizeof(struct bonding),
45035 .setup = bond_setup,
45036diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
45037index 36fa577..a158806 100644
45038--- a/drivers/net/ethernet/8390/ax88796.c
45039+++ b/drivers/net/ethernet/8390/ax88796.c
45040@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
45041 if (ax->plat->reg_offsets)
45042 ei_local->reg_offset = ax->plat->reg_offsets;
45043 else {
45044+ resource_size_t _mem_size = mem_size;
45045+ do_div(_mem_size, 0x18);
45046 ei_local->reg_offset = ax->reg_offsets;
45047 for (ret = 0; ret < 0x18; ret++)
45048- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
45049+ ax->reg_offsets[ret] = _mem_size * ret;
45050 }
45051
45052 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
45053diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45054index 41f3ca5a..1ee5364 100644
45055--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45056+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45057@@ -1139,7 +1139,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
45058 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
45059 {
45060 /* RX_MODE controlling object */
45061- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
45062+ bnx2x_init_rx_mode_obj(bp);
45063
45064 /* multicast configuration controlling object */
45065 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
45066diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45067index 18438a5..c923b8e 100644
45068--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45069+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45070@@ -2591,15 +2591,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
45071 return rc;
45072 }
45073
45074-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45075- struct bnx2x_rx_mode_obj *o)
45076+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
45077 {
45078 if (CHIP_IS_E1x(bp)) {
45079- o->wait_comp = bnx2x_empty_rx_mode_wait;
45080- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
45081+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
45082+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
45083 } else {
45084- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
45085- o->config_rx_mode = bnx2x_set_rx_mode_e2;
45086+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
45087+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
45088 }
45089 }
45090
45091diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45092index 6a53c15..6e7d1e7 100644
45093--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45094+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45095@@ -1332,8 +1332,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
45096
45097 /********************* RX MODE ****************/
45098
45099-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45100- struct bnx2x_rx_mode_obj *o);
45101+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
45102
45103 /**
45104 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
45105diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
45106index 5c3835a..d18b952 100644
45107--- a/drivers/net/ethernet/broadcom/tg3.h
45108+++ b/drivers/net/ethernet/broadcom/tg3.h
45109@@ -150,6 +150,7 @@
45110 #define CHIPREV_ID_5750_A0 0x4000
45111 #define CHIPREV_ID_5750_A1 0x4001
45112 #define CHIPREV_ID_5750_A3 0x4003
45113+#define CHIPREV_ID_5750_C1 0x4201
45114 #define CHIPREV_ID_5750_C2 0x4202
45115 #define CHIPREV_ID_5752_A0_HW 0x5000
45116 #define CHIPREV_ID_5752_A0 0x6000
45117diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
45118index 3ca77fa..fcc015f 100644
45119--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
45120+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
45121@@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
45122 }
45123
45124 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
45125- bna_cb_ioceth_enable,
45126- bna_cb_ioceth_disable,
45127- bna_cb_ioceth_hbfail,
45128- bna_cb_ioceth_reset
45129+ .enable_cbfn = bna_cb_ioceth_enable,
45130+ .disable_cbfn = bna_cb_ioceth_disable,
45131+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
45132+ .reset_cbfn = bna_cb_ioceth_reset
45133 };
45134
45135 static void bna_attr_init(struct bna_ioceth *ioceth)
45136diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45137index 8cffcdf..aadf043 100644
45138--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45139+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45140@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
45141 */
45142 struct l2t_skb_cb {
45143 arp_failure_handler_func arp_failure_handler;
45144-};
45145+} __no_const;
45146
45147 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
45148
45149diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45150index fff02ed..d421412 100644
45151--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45152+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45153@@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
45154
45155 int i;
45156 struct adapter *ap = netdev2adap(dev);
45157- static const unsigned int *reg_ranges;
45158+ const unsigned int *reg_ranges;
45159 int arr_size = 0, buf_size = 0;
45160
45161 if (is_t4(ap->params.chip)) {
45162diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
45163index c05b66d..ed69872 100644
45164--- a/drivers/net/ethernet/dec/tulip/de4x5.c
45165+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
45166@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45167 for (i=0; i<ETH_ALEN; i++) {
45168 tmp.addr[i] = dev->dev_addr[i];
45169 }
45170- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45171+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45172 break;
45173
45174 case DE4X5_SET_HWADDR: /* Set the hardware address */
45175@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45176 spin_lock_irqsave(&lp->lock, flags);
45177 memcpy(&statbuf, &lp->pktStats, ioc->len);
45178 spin_unlock_irqrestore(&lp->lock, flags);
45179- if (copy_to_user(ioc->data, &statbuf, ioc->len))
45180+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
45181 return -EFAULT;
45182 break;
45183 }
45184diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
45185index a37039d..a51d7e8 100644
45186--- a/drivers/net/ethernet/emulex/benet/be_main.c
45187+++ b/drivers/net/ethernet/emulex/benet/be_main.c
45188@@ -533,7 +533,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
45189
45190 if (wrapped)
45191 newacc += 65536;
45192- ACCESS_ONCE(*acc) = newacc;
45193+ ACCESS_ONCE_RW(*acc) = newacc;
45194 }
45195
45196 static void populate_erx_stats(struct be_adapter *adapter,
45197diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
45198index 212f44b..fb69959 100644
45199--- a/drivers/net/ethernet/faraday/ftgmac100.c
45200+++ b/drivers/net/ethernet/faraday/ftgmac100.c
45201@@ -31,6 +31,8 @@
45202 #include <linux/netdevice.h>
45203 #include <linux/phy.h>
45204 #include <linux/platform_device.h>
45205+#include <linux/interrupt.h>
45206+#include <linux/irqreturn.h>
45207 #include <net/ip.h>
45208
45209 #include "ftgmac100.h"
45210diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
45211index 8be5b40..081bc1b 100644
45212--- a/drivers/net/ethernet/faraday/ftmac100.c
45213+++ b/drivers/net/ethernet/faraday/ftmac100.c
45214@@ -31,6 +31,8 @@
45215 #include <linux/module.h>
45216 #include <linux/netdevice.h>
45217 #include <linux/platform_device.h>
45218+#include <linux/interrupt.h>
45219+#include <linux/irqreturn.h>
45220
45221 #include "ftmac100.h"
45222
45223diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45224index 5184e2a..acb28c3 100644
45225--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45226+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45227@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
45228 }
45229
45230 /* update the base incval used to calculate frequency adjustment */
45231- ACCESS_ONCE(adapter->base_incval) = incval;
45232+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
45233 smp_mb();
45234
45235 /* need lock to prevent incorrect read while modifying cyclecounter */
45236diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45237index fbe5363..266b4e3 100644
45238--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
45239+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45240@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45241 struct __vxge_hw_fifo *fifo;
45242 struct vxge_hw_fifo_config *config;
45243 u32 txdl_size, txdl_per_memblock;
45244- struct vxge_hw_mempool_cbs fifo_mp_callback;
45245+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
45246+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
45247+ };
45248+
45249 struct __vxge_hw_virtualpath *vpath;
45250
45251 if ((vp == NULL) || (attr == NULL)) {
45252@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45253 goto exit;
45254 }
45255
45256- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
45257-
45258 fifo->mempool =
45259 __vxge_hw_mempool_create(vpath->hldev,
45260 fifo->config->memblock_size,
45261diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45262index 918e18d..4ca3650 100644
45263--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45264+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45265@@ -2086,7 +2086,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
45266 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
45267 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
45268 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
45269- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45270+ pax_open_kernel();
45271+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45272+ pax_close_kernel();
45273 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45274 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
45275 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
45276diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45277index 734d286..b017bf5 100644
45278--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45279+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45280@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
45281 case QLCNIC_NON_PRIV_FUNC:
45282 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
45283 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45284- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45285+ pax_open_kernel();
45286+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45287+ pax_close_kernel();
45288 break;
45289 case QLCNIC_PRIV_FUNC:
45290 ahw->op_mode = QLCNIC_PRIV_FUNC;
45291 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
45292- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45293+ pax_open_kernel();
45294+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45295+ pax_close_kernel();
45296 break;
45297 case QLCNIC_MGMT_FUNC:
45298 ahw->op_mode = QLCNIC_MGMT_FUNC;
45299 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45300- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45301+ pax_open_kernel();
45302+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45303+ pax_close_kernel();
45304 break;
45305 default:
45306 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
45307diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45308index 7763962..c3499a7 100644
45309--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45310+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45311@@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
45312 struct qlcnic_dump_entry *entry;
45313 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
45314 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
45315- static const struct qlcnic_dump_operations *fw_dump_ops;
45316+ const struct qlcnic_dump_operations *fw_dump_ops;
45317 struct device *dev = &adapter->pdev->dev;
45318 struct qlcnic_hardware_context *ahw;
45319 void *temp_buffer;
45320diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
45321index c737f0e..32b8682 100644
45322--- a/drivers/net/ethernet/realtek/r8169.c
45323+++ b/drivers/net/ethernet/realtek/r8169.c
45324@@ -759,22 +759,22 @@ struct rtl8169_private {
45325 struct mdio_ops {
45326 void (*write)(struct rtl8169_private *, int, int);
45327 int (*read)(struct rtl8169_private *, int);
45328- } mdio_ops;
45329+ } __no_const mdio_ops;
45330
45331 struct pll_power_ops {
45332 void (*down)(struct rtl8169_private *);
45333 void (*up)(struct rtl8169_private *);
45334- } pll_power_ops;
45335+ } __no_const pll_power_ops;
45336
45337 struct jumbo_ops {
45338 void (*enable)(struct rtl8169_private *);
45339 void (*disable)(struct rtl8169_private *);
45340- } jumbo_ops;
45341+ } __no_const jumbo_ops;
45342
45343 struct csi_ops {
45344 void (*write)(struct rtl8169_private *, int, int);
45345 u32 (*read)(struct rtl8169_private *, int);
45346- } csi_ops;
45347+ } __no_const csi_ops;
45348
45349 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
45350 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
45351diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
45352index 3dd39dc..85efa46 100644
45353--- a/drivers/net/ethernet/sfc/ptp.c
45354+++ b/drivers/net/ethernet/sfc/ptp.c
45355@@ -541,7 +541,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
45356 ptp->start.dma_addr);
45357
45358 /* Clear flag that signals MC ready */
45359- ACCESS_ONCE(*start) = 0;
45360+ ACCESS_ONCE_RW(*start) = 0;
45361 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
45362 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
45363 EFX_BUG_ON_PARANOID(rc);
45364diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45365index 50617c5..b13724c 100644
45366--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45367+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45368@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
45369
45370 writel(value, ioaddr + MMC_CNTRL);
45371
45372- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
45373- MMC_CNTRL, value);
45374+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
45375+// MMC_CNTRL, value);
45376 }
45377
45378 /* To mask all all interrupts.*/
45379diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
45380index e6fe0d8..2b7d752 100644
45381--- a/drivers/net/hyperv/hyperv_net.h
45382+++ b/drivers/net/hyperv/hyperv_net.h
45383@@ -101,7 +101,7 @@ struct rndis_device {
45384
45385 enum rndis_device_state state;
45386 bool link_state;
45387- atomic_t new_req_id;
45388+ atomic_unchecked_t new_req_id;
45389
45390 spinlock_t request_lock;
45391 struct list_head req_list;
45392diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
45393index 0775f0a..d4fb316 100644
45394--- a/drivers/net/hyperv/rndis_filter.c
45395+++ b/drivers/net/hyperv/rndis_filter.c
45396@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
45397 * template
45398 */
45399 set = &rndis_msg->msg.set_req;
45400- set->req_id = atomic_inc_return(&dev->new_req_id);
45401+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
45402
45403 /* Add to the request list */
45404 spin_lock_irqsave(&dev->request_lock, flags);
45405@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
45406
45407 /* Setup the rndis set */
45408 halt = &request->request_msg.msg.halt_req;
45409- halt->req_id = atomic_inc_return(&dev->new_req_id);
45410+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
45411
45412 /* Ignore return since this msg is optional. */
45413 rndis_filter_send_request(dev, request);
45414diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
45415index bf0d55e..82bcfbd1 100644
45416--- a/drivers/net/ieee802154/fakehard.c
45417+++ b/drivers/net/ieee802154/fakehard.c
45418@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
45419 phy->transmit_power = 0xbf;
45420
45421 dev->netdev_ops = &fake_ops;
45422- dev->ml_priv = &fake_mlme;
45423+ dev->ml_priv = (void *)&fake_mlme;
45424
45425 priv = netdev_priv(dev);
45426 priv->phy = phy;
45427diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
45428index bc8faae..e51e25d 100644
45429--- a/drivers/net/macvlan.c
45430+++ b/drivers/net/macvlan.c
45431@@ -990,13 +990,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
45432 int macvlan_link_register(struct rtnl_link_ops *ops)
45433 {
45434 /* common fields */
45435- ops->priv_size = sizeof(struct macvlan_dev);
45436- ops->validate = macvlan_validate;
45437- ops->maxtype = IFLA_MACVLAN_MAX;
45438- ops->policy = macvlan_policy;
45439- ops->changelink = macvlan_changelink;
45440- ops->get_size = macvlan_get_size;
45441- ops->fill_info = macvlan_fill_info;
45442+ pax_open_kernel();
45443+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
45444+ *(void **)&ops->validate = macvlan_validate;
45445+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
45446+ *(const void **)&ops->policy = macvlan_policy;
45447+ *(void **)&ops->changelink = macvlan_changelink;
45448+ *(void **)&ops->get_size = macvlan_get_size;
45449+ *(void **)&ops->fill_info = macvlan_fill_info;
45450+ pax_close_kernel();
45451
45452 return rtnl_link_register(ops);
45453 };
45454@@ -1051,7 +1053,7 @@ static int macvlan_device_event(struct notifier_block *unused,
45455 return NOTIFY_DONE;
45456 }
45457
45458-static struct notifier_block macvlan_notifier_block __read_mostly = {
45459+static struct notifier_block macvlan_notifier_block = {
45460 .notifier_call = macvlan_device_event,
45461 };
45462
45463diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
45464index 2a89da0..c17fe1d 100644
45465--- a/drivers/net/macvtap.c
45466+++ b/drivers/net/macvtap.c
45467@@ -1012,7 +1012,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
45468 }
45469
45470 ret = 0;
45471- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
45472+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
45473 put_user(q->flags, &ifr->ifr_flags))
45474 ret = -EFAULT;
45475 macvtap_put_vlan(vlan);
45476@@ -1182,7 +1182,7 @@ static int macvtap_device_event(struct notifier_block *unused,
45477 return NOTIFY_DONE;
45478 }
45479
45480-static struct notifier_block macvtap_notifier_block __read_mostly = {
45481+static struct notifier_block macvtap_notifier_block = {
45482 .notifier_call = macvtap_device_event,
45483 };
45484
45485diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
45486index daec9b0..6428fcb 100644
45487--- a/drivers/net/phy/mdio-bitbang.c
45488+++ b/drivers/net/phy/mdio-bitbang.c
45489@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
45490 struct mdiobb_ctrl *ctrl = bus->priv;
45491
45492 module_put(ctrl->ops->owner);
45493+ mdiobus_unregister(bus);
45494 mdiobus_free(bus);
45495 }
45496 EXPORT_SYMBOL(free_mdio_bitbang);
45497diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
45498index 72ff14b..11d442d 100644
45499--- a/drivers/net/ppp/ppp_generic.c
45500+++ b/drivers/net/ppp/ppp_generic.c
45501@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
45502 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
45503 struct ppp_stats stats;
45504 struct ppp_comp_stats cstats;
45505- char *vers;
45506
45507 switch (cmd) {
45508 case SIOCGPPPSTATS:
45509@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
45510 break;
45511
45512 case SIOCGPPPVER:
45513- vers = PPP_VERSION;
45514- if (copy_to_user(addr, vers, strlen(vers) + 1))
45515+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
45516 break;
45517 err = 0;
45518 break;
45519diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
45520index 1252d9c..80e660b 100644
45521--- a/drivers/net/slip/slhc.c
45522+++ b/drivers/net/slip/slhc.c
45523@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
45524 register struct tcphdr *thp;
45525 register struct iphdr *ip;
45526 register struct cstate *cs;
45527- int len, hdrlen;
45528+ long len, hdrlen;
45529 unsigned char *cp = icp;
45530
45531 /* We've got a compressed packet; read the change byte */
45532diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
45533index b75ae5b..953c157 100644
45534--- a/drivers/net/team/team.c
45535+++ b/drivers/net/team/team.c
45536@@ -2865,7 +2865,7 @@ static int team_device_event(struct notifier_block *unused,
45537 return NOTIFY_DONE;
45538 }
45539
45540-static struct notifier_block team_notifier_block __read_mostly = {
45541+static struct notifier_block team_notifier_block = {
45542 .notifier_call = team_device_event,
45543 };
45544
45545diff --git a/drivers/net/tun.c b/drivers/net/tun.c
45546index ecec802..614f08f 100644
45547--- a/drivers/net/tun.c
45548+++ b/drivers/net/tun.c
45549@@ -1839,7 +1839,7 @@ unlock:
45550 }
45551
45552 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
45553- unsigned long arg, int ifreq_len)
45554+ unsigned long arg, size_t ifreq_len)
45555 {
45556 struct tun_file *tfile = file->private_data;
45557 struct tun_struct *tun;
45558@@ -1852,6 +1852,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
45559 unsigned int ifindex;
45560 int ret;
45561
45562+ if (ifreq_len > sizeof ifr)
45563+ return -EFAULT;
45564+
45565 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
45566 if (copy_from_user(&ifr, argp, ifreq_len))
45567 return -EFAULT;
45568diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
45569index 1a48234..a555339 100644
45570--- a/drivers/net/usb/hso.c
45571+++ b/drivers/net/usb/hso.c
45572@@ -71,7 +71,7 @@
45573 #include <asm/byteorder.h>
45574 #include <linux/serial_core.h>
45575 #include <linux/serial.h>
45576-
45577+#include <asm/local.h>
45578
45579 #define MOD_AUTHOR "Option Wireless"
45580 #define MOD_DESCRIPTION "USB High Speed Option driver"
45581@@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
45582 struct urb *urb;
45583
45584 urb = serial->rx_urb[0];
45585- if (serial->port.count > 0) {
45586+ if (atomic_read(&serial->port.count) > 0) {
45587 count = put_rxbuf_data(urb, serial);
45588 if (count == -1)
45589 return;
45590@@ -1215,7 +1215,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
45591 DUMP1(urb->transfer_buffer, urb->actual_length);
45592
45593 /* Anyone listening? */
45594- if (serial->port.count == 0)
45595+ if (atomic_read(&serial->port.count) == 0)
45596 return;
45597
45598 if (status == 0) {
45599@@ -1297,8 +1297,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
45600 tty_port_tty_set(&serial->port, tty);
45601
45602 /* check for port already opened, if not set the termios */
45603- serial->port.count++;
45604- if (serial->port.count == 1) {
45605+ if (atomic_inc_return(&serial->port.count) == 1) {
45606 serial->rx_state = RX_IDLE;
45607 /* Force default termio settings */
45608 _hso_serial_set_termios(tty, NULL);
45609@@ -1310,7 +1309,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
45610 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
45611 if (result) {
45612 hso_stop_serial_device(serial->parent);
45613- serial->port.count--;
45614+ atomic_dec(&serial->port.count);
45615 kref_put(&serial->parent->ref, hso_serial_ref_free);
45616 }
45617 } else {
45618@@ -1347,10 +1346,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
45619
45620 /* reset the rts and dtr */
45621 /* do the actual close */
45622- serial->port.count--;
45623+ atomic_dec(&serial->port.count);
45624
45625- if (serial->port.count <= 0) {
45626- serial->port.count = 0;
45627+ if (atomic_read(&serial->port.count) <= 0) {
45628+ atomic_set(&serial->port.count, 0);
45629 tty_port_tty_set(&serial->port, NULL);
45630 if (!usb_gone)
45631 hso_stop_serial_device(serial->parent);
45632@@ -1426,7 +1425,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
45633
45634 /* the actual setup */
45635 spin_lock_irqsave(&serial->serial_lock, flags);
45636- if (serial->port.count)
45637+ if (atomic_read(&serial->port.count))
45638 _hso_serial_set_termios(tty, old);
45639 else
45640 tty->termios = *old;
45641@@ -1895,7 +1894,7 @@ static void intr_callback(struct urb *urb)
45642 D1("Pending read interrupt on port %d\n", i);
45643 spin_lock(&serial->serial_lock);
45644 if (serial->rx_state == RX_IDLE &&
45645- serial->port.count > 0) {
45646+ atomic_read(&serial->port.count) > 0) {
45647 /* Setup and send a ctrl req read on
45648 * port i */
45649 if (!serial->rx_urb_filled[0]) {
45650@@ -3071,7 +3070,7 @@ static int hso_resume(struct usb_interface *iface)
45651 /* Start all serial ports */
45652 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
45653 if (serial_table[i] && (serial_table[i]->interface == iface)) {
45654- if (dev2ser(serial_table[i])->port.count) {
45655+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
45656 result =
45657 hso_start_serial_device(serial_table[i], GFP_NOIO);
45658 hso_kick_transmit(dev2ser(serial_table[i]));
45659diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
45660index a79e9d3..78cd4fa 100644
45661--- a/drivers/net/usb/sierra_net.c
45662+++ b/drivers/net/usb/sierra_net.c
45663@@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
45664 /* atomic counter partially included in MAC address to make sure 2 devices
45665 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
45666 */
45667-static atomic_t iface_counter = ATOMIC_INIT(0);
45668+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
45669
45670 /*
45671 * SYNC Timer Delay definition used to set the expiry time
45672@@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
45673 dev->net->netdev_ops = &sierra_net_device_ops;
45674
45675 /* change MAC addr to include, ifacenum, and to be unique */
45676- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
45677+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
45678 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
45679
45680 /* we will have to manufacture ethernet headers, prepare template */
45681diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
45682index 0247973..088193a 100644
45683--- a/drivers/net/vxlan.c
45684+++ b/drivers/net/vxlan.c
45685@@ -2615,7 +2615,7 @@ nla_put_failure:
45686 return -EMSGSIZE;
45687 }
45688
45689-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
45690+static struct rtnl_link_ops vxlan_link_ops = {
45691 .kind = "vxlan",
45692 .maxtype = IFLA_VXLAN_MAX,
45693 .policy = vxlan_policy,
45694diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
45695index 5920c99..ff2e4a5 100644
45696--- a/drivers/net/wan/lmc/lmc_media.c
45697+++ b/drivers/net/wan/lmc/lmc_media.c
45698@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
45699 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
45700
45701 lmc_media_t lmc_ds3_media = {
45702- lmc_ds3_init, /* special media init stuff */
45703- lmc_ds3_default, /* reset to default state */
45704- lmc_ds3_set_status, /* reset status to state provided */
45705- lmc_dummy_set_1, /* set clock source */
45706- lmc_dummy_set2_1, /* set line speed */
45707- lmc_ds3_set_100ft, /* set cable length */
45708- lmc_ds3_set_scram, /* set scrambler */
45709- lmc_ds3_get_link_status, /* get link status */
45710- lmc_dummy_set_1, /* set link status */
45711- lmc_ds3_set_crc_length, /* set CRC length */
45712- lmc_dummy_set_1, /* set T1 or E1 circuit type */
45713- lmc_ds3_watchdog
45714+ .init = lmc_ds3_init, /* special media init stuff */
45715+ .defaults = lmc_ds3_default, /* reset to default state */
45716+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
45717+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
45718+ .set_speed = lmc_dummy_set2_1, /* set line speed */
45719+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
45720+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
45721+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
45722+ .set_link_status = lmc_dummy_set_1, /* set link status */
45723+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
45724+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
45725+ .watchdog = lmc_ds3_watchdog
45726 };
45727
45728 lmc_media_t lmc_hssi_media = {
45729- lmc_hssi_init, /* special media init stuff */
45730- lmc_hssi_default, /* reset to default state */
45731- lmc_hssi_set_status, /* reset status to state provided */
45732- lmc_hssi_set_clock, /* set clock source */
45733- lmc_dummy_set2_1, /* set line speed */
45734- lmc_dummy_set_1, /* set cable length */
45735- lmc_dummy_set_1, /* set scrambler */
45736- lmc_hssi_get_link_status, /* get link status */
45737- lmc_hssi_set_link_status, /* set link status */
45738- lmc_hssi_set_crc_length, /* set CRC length */
45739- lmc_dummy_set_1, /* set T1 or E1 circuit type */
45740- lmc_hssi_watchdog
45741+ .init = lmc_hssi_init, /* special media init stuff */
45742+ .defaults = lmc_hssi_default, /* reset to default state */
45743+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
45744+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
45745+ .set_speed = lmc_dummy_set2_1, /* set line speed */
45746+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
45747+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
45748+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
45749+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
45750+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
45751+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
45752+ .watchdog = lmc_hssi_watchdog
45753 };
45754
45755-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
45756- lmc_ssi_default, /* reset to default state */
45757- lmc_ssi_set_status, /* reset status to state provided */
45758- lmc_ssi_set_clock, /* set clock source */
45759- lmc_ssi_set_speed, /* set line speed */
45760- lmc_dummy_set_1, /* set cable length */
45761- lmc_dummy_set_1, /* set scrambler */
45762- lmc_ssi_get_link_status, /* get link status */
45763- lmc_ssi_set_link_status, /* set link status */
45764- lmc_ssi_set_crc_length, /* set CRC length */
45765- lmc_dummy_set_1, /* set T1 or E1 circuit type */
45766- lmc_ssi_watchdog
45767+lmc_media_t lmc_ssi_media = {
45768+ .init = lmc_ssi_init, /* special media init stuff */
45769+ .defaults = lmc_ssi_default, /* reset to default state */
45770+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
45771+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
45772+ .set_speed = lmc_ssi_set_speed, /* set line speed */
45773+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
45774+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
45775+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
45776+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
45777+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
45778+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
45779+ .watchdog = lmc_ssi_watchdog
45780 };
45781
45782 lmc_media_t lmc_t1_media = {
45783- lmc_t1_init, /* special media init stuff */
45784- lmc_t1_default, /* reset to default state */
45785- lmc_t1_set_status, /* reset status to state provided */
45786- lmc_t1_set_clock, /* set clock source */
45787- lmc_dummy_set2_1, /* set line speed */
45788- lmc_dummy_set_1, /* set cable length */
45789- lmc_dummy_set_1, /* set scrambler */
45790- lmc_t1_get_link_status, /* get link status */
45791- lmc_dummy_set_1, /* set link status */
45792- lmc_t1_set_crc_length, /* set CRC length */
45793- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
45794- lmc_t1_watchdog
45795+ .init = lmc_t1_init, /* special media init stuff */
45796+ .defaults = lmc_t1_default, /* reset to default state */
45797+ .set_status = lmc_t1_set_status, /* reset status to state provided */
45798+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
45799+ .set_speed = lmc_dummy_set2_1, /* set line speed */
45800+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
45801+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
45802+ .get_link_status = lmc_t1_get_link_status, /* get link status */
45803+ .set_link_status = lmc_dummy_set_1, /* set link status */
45804+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
45805+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
45806+ .watchdog = lmc_t1_watchdog
45807 };
45808
45809 static void
45810diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
45811index feacc3b..5bac0de 100644
45812--- a/drivers/net/wan/z85230.c
45813+++ b/drivers/net/wan/z85230.c
45814@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
45815
45816 struct z8530_irqhandler z8530_sync =
45817 {
45818- z8530_rx,
45819- z8530_tx,
45820- z8530_status
45821+ .rx = z8530_rx,
45822+ .tx = z8530_tx,
45823+ .status = z8530_status
45824 };
45825
45826 EXPORT_SYMBOL(z8530_sync);
45827@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
45828 }
45829
45830 static struct z8530_irqhandler z8530_dma_sync = {
45831- z8530_dma_rx,
45832- z8530_dma_tx,
45833- z8530_dma_status
45834+ .rx = z8530_dma_rx,
45835+ .tx = z8530_dma_tx,
45836+ .status = z8530_dma_status
45837 };
45838
45839 static struct z8530_irqhandler z8530_txdma_sync = {
45840- z8530_rx,
45841- z8530_dma_tx,
45842- z8530_dma_status
45843+ .rx = z8530_rx,
45844+ .tx = z8530_dma_tx,
45845+ .status = z8530_dma_status
45846 };
45847
45848 /**
45849@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
45850
45851 struct z8530_irqhandler z8530_nop=
45852 {
45853- z8530_rx_clear,
45854- z8530_tx_clear,
45855- z8530_status_clear
45856+ .rx = z8530_rx_clear,
45857+ .tx = z8530_tx_clear,
45858+ .status = z8530_status_clear
45859 };
45860
45861
45862diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
45863index 0b60295..b8bfa5b 100644
45864--- a/drivers/net/wimax/i2400m/rx.c
45865+++ b/drivers/net/wimax/i2400m/rx.c
45866@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
45867 if (i2400m->rx_roq == NULL)
45868 goto error_roq_alloc;
45869
45870- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
45871+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
45872 GFP_KERNEL);
45873 if (rd == NULL) {
45874 result = -ENOMEM;
45875diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
45876index edf4b57..68b51c0 100644
45877--- a/drivers/net/wireless/airo.c
45878+++ b/drivers/net/wireless/airo.c
45879@@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
45880 struct airo_info *ai = dev->ml_priv;
45881 int ridcode;
45882 int enabled;
45883- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
45884+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
45885 unsigned char *iobuf;
45886
45887 /* Only super-user can write RIDs */
45888diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
45889index 34c8a33..3261fdc 100644
45890--- a/drivers/net/wireless/at76c50x-usb.c
45891+++ b/drivers/net/wireless/at76c50x-usb.c
45892@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
45893 }
45894
45895 /* Convert timeout from the DFU status to jiffies */
45896-static inline unsigned long at76_get_timeout(struct dfu_status *s)
45897+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
45898 {
45899 return msecs_to_jiffies((s->poll_timeout[2] << 16)
45900 | (s->poll_timeout[1] << 8)
45901diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
45902index edae50b..b24278c 100644
45903--- a/drivers/net/wireless/ath/ath10k/htc.c
45904+++ b/drivers/net/wireless/ath/ath10k/htc.c
45905@@ -842,7 +842,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
45906 /* registered target arrival callback from the HIF layer */
45907 int ath10k_htc_init(struct ath10k *ar)
45908 {
45909- struct ath10k_hif_cb htc_callbacks;
45910+ static struct ath10k_hif_cb htc_callbacks = {
45911+ .rx_completion = ath10k_htc_rx_completion_handler,
45912+ .tx_completion = ath10k_htc_tx_completion_handler,
45913+ };
45914 struct ath10k_htc_ep *ep = NULL;
45915 struct ath10k_htc *htc = &ar->htc;
45916
45917@@ -852,8 +855,6 @@ int ath10k_htc_init(struct ath10k *ar)
45918 ath10k_htc_reset_endpoint_states(htc);
45919
45920 /* setup HIF layer callbacks */
45921- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
45922- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
45923 htc->ar = ar;
45924
45925 /* Get HIF default pipe for HTC message exchange */
45926diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
45927index 4716d33..a688310 100644
45928--- a/drivers/net/wireless/ath/ath10k/htc.h
45929+++ b/drivers/net/wireless/ath/ath10k/htc.h
45930@@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
45931
45932 struct ath10k_htc_ops {
45933 void (*target_send_suspend_complete)(struct ath10k *ar);
45934-};
45935+} __no_const;
45936
45937 struct ath10k_htc_ep_ops {
45938 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
45939 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
45940 void (*ep_tx_credits)(struct ath10k *);
45941-};
45942+} __no_const;
45943
45944 /* service connection information */
45945 struct ath10k_htc_svc_conn_req {
45946diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
45947index a366d6b..b6f28f8 100644
45948--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
45949+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
45950@@ -218,8 +218,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45951 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
45952 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
45953
45954- ACCESS_ONCE(ads->ds_link) = i->link;
45955- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
45956+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
45957+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
45958
45959 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
45960 ctl6 = SM(i->keytype, AR_EncrType);
45961@@ -233,26 +233,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45962
45963 if ((i->is_first || i->is_last) &&
45964 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
45965- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
45966+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
45967 | set11nTries(i->rates, 1)
45968 | set11nTries(i->rates, 2)
45969 | set11nTries(i->rates, 3)
45970 | (i->dur_update ? AR_DurUpdateEna : 0)
45971 | SM(0, AR_BurstDur);
45972
45973- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
45974+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
45975 | set11nRate(i->rates, 1)
45976 | set11nRate(i->rates, 2)
45977 | set11nRate(i->rates, 3);
45978 } else {
45979- ACCESS_ONCE(ads->ds_ctl2) = 0;
45980- ACCESS_ONCE(ads->ds_ctl3) = 0;
45981+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
45982+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
45983 }
45984
45985 if (!i->is_first) {
45986- ACCESS_ONCE(ads->ds_ctl0) = 0;
45987- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
45988- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
45989+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
45990+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
45991+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
45992 return;
45993 }
45994
45995@@ -277,7 +277,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45996 break;
45997 }
45998
45999- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46000+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46001 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46002 | SM(i->txpower, AR_XmitPower)
46003 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46004@@ -287,19 +287,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46005 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
46006 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
46007
46008- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46009- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46010+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46011+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46012
46013 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
46014 return;
46015
46016- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46017+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46018 | set11nPktDurRTSCTS(i->rates, 1);
46019
46020- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46021+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46022 | set11nPktDurRTSCTS(i->rates, 3);
46023
46024- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46025+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46026 | set11nRateFlags(i->rates, 1)
46027 | set11nRateFlags(i->rates, 2)
46028 | set11nRateFlags(i->rates, 3)
46029diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46030index f6c5c1b..6058354 100644
46031--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46032+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46033@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46034 (i->qcu << AR_TxQcuNum_S) | desc_len;
46035
46036 checksum += val;
46037- ACCESS_ONCE(ads->info) = val;
46038+ ACCESS_ONCE_RW(ads->info) = val;
46039
46040 checksum += i->link;
46041- ACCESS_ONCE(ads->link) = i->link;
46042+ ACCESS_ONCE_RW(ads->link) = i->link;
46043
46044 checksum += i->buf_addr[0];
46045- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
46046+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
46047 checksum += i->buf_addr[1];
46048- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
46049+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
46050 checksum += i->buf_addr[2];
46051- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
46052+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
46053 checksum += i->buf_addr[3];
46054- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
46055+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
46056
46057 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
46058- ACCESS_ONCE(ads->ctl3) = val;
46059+ ACCESS_ONCE_RW(ads->ctl3) = val;
46060 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
46061- ACCESS_ONCE(ads->ctl5) = val;
46062+ ACCESS_ONCE_RW(ads->ctl5) = val;
46063 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
46064- ACCESS_ONCE(ads->ctl7) = val;
46065+ ACCESS_ONCE_RW(ads->ctl7) = val;
46066 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
46067- ACCESS_ONCE(ads->ctl9) = val;
46068+ ACCESS_ONCE_RW(ads->ctl9) = val;
46069
46070 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
46071- ACCESS_ONCE(ads->ctl10) = checksum;
46072+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
46073
46074 if (i->is_first || i->is_last) {
46075- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
46076+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
46077 | set11nTries(i->rates, 1)
46078 | set11nTries(i->rates, 2)
46079 | set11nTries(i->rates, 3)
46080 | (i->dur_update ? AR_DurUpdateEna : 0)
46081 | SM(0, AR_BurstDur);
46082
46083- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
46084+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
46085 | set11nRate(i->rates, 1)
46086 | set11nRate(i->rates, 2)
46087 | set11nRate(i->rates, 3);
46088 } else {
46089- ACCESS_ONCE(ads->ctl13) = 0;
46090- ACCESS_ONCE(ads->ctl14) = 0;
46091+ ACCESS_ONCE_RW(ads->ctl13) = 0;
46092+ ACCESS_ONCE_RW(ads->ctl14) = 0;
46093 }
46094
46095 ads->ctl20 = 0;
46096@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46097
46098 ctl17 = SM(i->keytype, AR_EncrType);
46099 if (!i->is_first) {
46100- ACCESS_ONCE(ads->ctl11) = 0;
46101- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46102- ACCESS_ONCE(ads->ctl15) = 0;
46103- ACCESS_ONCE(ads->ctl16) = 0;
46104- ACCESS_ONCE(ads->ctl17) = ctl17;
46105- ACCESS_ONCE(ads->ctl18) = 0;
46106- ACCESS_ONCE(ads->ctl19) = 0;
46107+ ACCESS_ONCE_RW(ads->ctl11) = 0;
46108+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46109+ ACCESS_ONCE_RW(ads->ctl15) = 0;
46110+ ACCESS_ONCE_RW(ads->ctl16) = 0;
46111+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46112+ ACCESS_ONCE_RW(ads->ctl18) = 0;
46113+ ACCESS_ONCE_RW(ads->ctl19) = 0;
46114 return;
46115 }
46116
46117- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46118+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46119 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46120 | SM(i->txpower, AR_XmitPower)
46121 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46122@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46123 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
46124 ctl12 |= SM(val, AR_PAPRDChainMask);
46125
46126- ACCESS_ONCE(ads->ctl12) = ctl12;
46127- ACCESS_ONCE(ads->ctl17) = ctl17;
46128+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
46129+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46130
46131- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46132+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46133 | set11nPktDurRTSCTS(i->rates, 1);
46134
46135- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46136+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46137 | set11nPktDurRTSCTS(i->rates, 3);
46138
46139- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
46140+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
46141 | set11nRateFlags(i->rates, 1)
46142 | set11nRateFlags(i->rates, 2)
46143 | set11nRateFlags(i->rates, 3)
46144 | SM(i->rtscts_rate, AR_RTSCTSRate);
46145
46146- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
46147+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
46148 }
46149
46150 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
46151diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
46152index a2c9a5d..b52273e 100644
46153--- a/drivers/net/wireless/ath/ath9k/hw.h
46154+++ b/drivers/net/wireless/ath/ath9k/hw.h
46155@@ -635,7 +635,7 @@ struct ath_hw_private_ops {
46156
46157 /* ANI */
46158 void (*ani_cache_ini_regs)(struct ath_hw *ah);
46159-};
46160+} __no_const;
46161
46162 /**
46163 * struct ath_spec_scan - parameters for Atheros spectral scan
46164@@ -711,7 +711,7 @@ struct ath_hw_ops {
46165 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
46166 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
46167 #endif
46168-};
46169+} __no_const;
46170
46171 struct ath_nf_limits {
46172 s16 max;
46173diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
46174index 92190da..f3a4c4c 100644
46175--- a/drivers/net/wireless/b43/phy_lp.c
46176+++ b/drivers/net/wireless/b43/phy_lp.c
46177@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
46178 {
46179 struct ssb_bus *bus = dev->dev->sdev->bus;
46180
46181- static const struct b206x_channel *chandata = NULL;
46182+ const struct b206x_channel *chandata = NULL;
46183 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
46184 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
46185 u16 old_comm15, scale;
46186diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
46187index dea3b50..543db99 100644
46188--- a/drivers/net/wireless/iwlegacy/3945-mac.c
46189+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
46190@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46191 */
46192 if (il3945_mod_params.disable_hw_scan) {
46193 D_INFO("Disabling hw_scan\n");
46194- il3945_mac_ops.hw_scan = NULL;
46195+ pax_open_kernel();
46196+ *(void **)&il3945_mac_ops.hw_scan = NULL;
46197+ pax_close_kernel();
46198 }
46199
46200 D_INFO("*** LOAD DRIVER ***\n");
46201diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46202index d94f8ab..5b568c8 100644
46203--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46204+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46205@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
46206 {
46207 struct iwl_priv *priv = file->private_data;
46208 char buf[64];
46209- int buf_size;
46210+ size_t buf_size;
46211 u32 offset, len;
46212
46213 memset(buf, 0, sizeof(buf));
46214@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
46215 struct iwl_priv *priv = file->private_data;
46216
46217 char buf[8];
46218- int buf_size;
46219+ size_t buf_size;
46220 u32 reset_flag;
46221
46222 memset(buf, 0, sizeof(buf));
46223@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
46224 {
46225 struct iwl_priv *priv = file->private_data;
46226 char buf[8];
46227- int buf_size;
46228+ size_t buf_size;
46229 int ht40;
46230
46231 memset(buf, 0, sizeof(buf));
46232@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
46233 {
46234 struct iwl_priv *priv = file->private_data;
46235 char buf[8];
46236- int buf_size;
46237+ size_t buf_size;
46238 int value;
46239
46240 memset(buf, 0, sizeof(buf));
46241@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
46242 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
46243 DEBUGFS_READ_FILE_OPS(current_sleep_command);
46244
46245-static const char *fmt_value = " %-30s %10u\n";
46246-static const char *fmt_hex = " %-30s 0x%02X\n";
46247-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
46248-static const char *fmt_header =
46249+static const char fmt_value[] = " %-30s %10u\n";
46250+static const char fmt_hex[] = " %-30s 0x%02X\n";
46251+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
46252+static const char fmt_header[] =
46253 "%-32s current cumulative delta max\n";
46254
46255 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
46256@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
46257 {
46258 struct iwl_priv *priv = file->private_data;
46259 char buf[8];
46260- int buf_size;
46261+ size_t buf_size;
46262 int clear;
46263
46264 memset(buf, 0, sizeof(buf));
46265@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
46266 {
46267 struct iwl_priv *priv = file->private_data;
46268 char buf[8];
46269- int buf_size;
46270+ size_t buf_size;
46271 int trace;
46272
46273 memset(buf, 0, sizeof(buf));
46274@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
46275 {
46276 struct iwl_priv *priv = file->private_data;
46277 char buf[8];
46278- int buf_size;
46279+ size_t buf_size;
46280 int missed;
46281
46282 memset(buf, 0, sizeof(buf));
46283@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
46284
46285 struct iwl_priv *priv = file->private_data;
46286 char buf[8];
46287- int buf_size;
46288+ size_t buf_size;
46289 int plcp;
46290
46291 memset(buf, 0, sizeof(buf));
46292@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
46293
46294 struct iwl_priv *priv = file->private_data;
46295 char buf[8];
46296- int buf_size;
46297+ size_t buf_size;
46298 int flush;
46299
46300 memset(buf, 0, sizeof(buf));
46301@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
46302
46303 struct iwl_priv *priv = file->private_data;
46304 char buf[8];
46305- int buf_size;
46306+ size_t buf_size;
46307 int rts;
46308
46309 if (!priv->cfg->ht_params)
46310@@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
46311 {
46312 struct iwl_priv *priv = file->private_data;
46313 char buf[8];
46314- int buf_size;
46315+ size_t buf_size;
46316
46317 memset(buf, 0, sizeof(buf));
46318 buf_size = min(count, sizeof(buf) - 1);
46319@@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
46320 struct iwl_priv *priv = file->private_data;
46321 u32 event_log_flag;
46322 char buf[8];
46323- int buf_size;
46324+ size_t buf_size;
46325
46326 /* check that the interface is up */
46327 if (!iwl_is_ready(priv))
46328@@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
46329 struct iwl_priv *priv = file->private_data;
46330 char buf[8];
46331 u32 calib_disabled;
46332- int buf_size;
46333+ size_t buf_size;
46334
46335 memset(buf, 0, sizeof(buf));
46336 buf_size = min(count, sizeof(buf) - 1);
46337diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
46338index 7aad766..06addb4 100644
46339--- a/drivers/net/wireless/iwlwifi/dvm/main.c
46340+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
46341@@ -1123,7 +1123,7 @@ static void iwl_option_config(struct iwl_priv *priv)
46342 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46343 {
46344 struct iwl_nvm_data *data = priv->nvm_data;
46345- char *debug_msg;
46346+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
46347
46348 if (data->sku_cap_11n_enable &&
46349 !priv->cfg->ht_params) {
46350@@ -1137,7 +1137,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46351 return -EINVAL;
46352 }
46353
46354- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
46355 IWL_DEBUG_INFO(priv, debug_msg,
46356 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
46357 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
46358diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
46359index f53ef83..5e34bcb 100644
46360--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
46361+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
46362@@ -1390,7 +1390,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
46363 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
46364
46365 char buf[8];
46366- int buf_size;
46367+ size_t buf_size;
46368 u32 reset_flag;
46369
46370 memset(buf, 0, sizeof(buf));
46371@@ -1411,7 +1411,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
46372 {
46373 struct iwl_trans *trans = file->private_data;
46374 char buf[8];
46375- int buf_size;
46376+ size_t buf_size;
46377 int csr;
46378
46379 memset(buf, 0, sizeof(buf));
46380diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
46381index a1b32ee..94b3c3d 100644
46382--- a/drivers/net/wireless/mac80211_hwsim.c
46383+++ b/drivers/net/wireless/mac80211_hwsim.c
46384@@ -2224,25 +2224,19 @@ static int __init init_mac80211_hwsim(void)
46385
46386 if (channels > 1) {
46387 hwsim_if_comb.num_different_channels = channels;
46388- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
46389- mac80211_hwsim_ops.cancel_hw_scan =
46390- mac80211_hwsim_cancel_hw_scan;
46391- mac80211_hwsim_ops.sw_scan_start = NULL;
46392- mac80211_hwsim_ops.sw_scan_complete = NULL;
46393- mac80211_hwsim_ops.remain_on_channel =
46394- mac80211_hwsim_roc;
46395- mac80211_hwsim_ops.cancel_remain_on_channel =
46396- mac80211_hwsim_croc;
46397- mac80211_hwsim_ops.add_chanctx =
46398- mac80211_hwsim_add_chanctx;
46399- mac80211_hwsim_ops.remove_chanctx =
46400- mac80211_hwsim_remove_chanctx;
46401- mac80211_hwsim_ops.change_chanctx =
46402- mac80211_hwsim_change_chanctx;
46403- mac80211_hwsim_ops.assign_vif_chanctx =
46404- mac80211_hwsim_assign_vif_chanctx;
46405- mac80211_hwsim_ops.unassign_vif_chanctx =
46406- mac80211_hwsim_unassign_vif_chanctx;
46407+ pax_open_kernel();
46408+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
46409+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
46410+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
46411+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
46412+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
46413+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
46414+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
46415+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
46416+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
46417+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
46418+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
46419+ pax_close_kernel();
46420 }
46421
46422 spin_lock_init(&hwsim_radio_lock);
46423diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
46424index 8169a85..7fa3b47 100644
46425--- a/drivers/net/wireless/rndis_wlan.c
46426+++ b/drivers/net/wireless/rndis_wlan.c
46427@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
46428
46429 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
46430
46431- if (rts_threshold < 0 || rts_threshold > 2347)
46432+ if (rts_threshold > 2347)
46433 rts_threshold = 2347;
46434
46435 tmp = cpu_to_le32(rts_threshold);
46436diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
46437index e4ba2ce..63d7417 100644
46438--- a/drivers/net/wireless/rt2x00/rt2x00.h
46439+++ b/drivers/net/wireless/rt2x00/rt2x00.h
46440@@ -377,7 +377,7 @@ struct rt2x00_intf {
46441 * for hardware which doesn't support hardware
46442 * sequence counting.
46443 */
46444- atomic_t seqno;
46445+ atomic_unchecked_t seqno;
46446 };
46447
46448 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
46449diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
46450index a5d38e8..d3c24ea 100644
46451--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
46452+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
46453@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
46454 * sequence counter given by mac80211.
46455 */
46456 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
46457- seqno = atomic_add_return(0x10, &intf->seqno);
46458+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
46459 else
46460- seqno = atomic_read(&intf->seqno);
46461+ seqno = atomic_read_unchecked(&intf->seqno);
46462
46463 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
46464 hdr->seq_ctrl |= cpu_to_le16(seqno);
46465diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
46466index e2b3d9c..67a5184 100644
46467--- a/drivers/net/wireless/ti/wl1251/sdio.c
46468+++ b/drivers/net/wireless/ti/wl1251/sdio.c
46469@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
46470
46471 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
46472
46473- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
46474- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
46475+ pax_open_kernel();
46476+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
46477+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
46478+ pax_close_kernel();
46479
46480 wl1251_info("using dedicated interrupt line");
46481 } else {
46482- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
46483- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
46484+ pax_open_kernel();
46485+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
46486+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
46487+ pax_close_kernel();
46488
46489 wl1251_info("using SDIO interrupt");
46490 }
46491diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
46492index be7129b..4161356 100644
46493--- a/drivers/net/wireless/ti/wl12xx/main.c
46494+++ b/drivers/net/wireless/ti/wl12xx/main.c
46495@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
46496 sizeof(wl->conf.mem));
46497
46498 /* read data preparation is only needed by wl127x */
46499- wl->ops->prepare_read = wl127x_prepare_read;
46500+ pax_open_kernel();
46501+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
46502+ pax_close_kernel();
46503
46504 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
46505 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
46506@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
46507 sizeof(wl->conf.mem));
46508
46509 /* read data preparation is only needed by wl127x */
46510- wl->ops->prepare_read = wl127x_prepare_read;
46511+ pax_open_kernel();
46512+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
46513+ pax_close_kernel();
46514
46515 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
46516 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
46517diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
46518index ec37b16..7e34d66 100644
46519--- a/drivers/net/wireless/ti/wl18xx/main.c
46520+++ b/drivers/net/wireless/ti/wl18xx/main.c
46521@@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
46522 }
46523
46524 if (!checksum_param) {
46525- wl18xx_ops.set_rx_csum = NULL;
46526- wl18xx_ops.init_vif = NULL;
46527+ pax_open_kernel();
46528+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
46529+ *(void **)&wl18xx_ops.init_vif = NULL;
46530+ pax_close_kernel();
46531 }
46532
46533 /* Enable 11a Band only if we have 5G antennas */
46534diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
46535index 84d94f5..bd6c61c 100644
46536--- a/drivers/net/wireless/zd1211rw/zd_usb.c
46537+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
46538@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
46539 {
46540 struct zd_usb *usb = urb->context;
46541 struct zd_usb_interrupt *intr = &usb->intr;
46542- int len;
46543+ unsigned int len;
46544 u16 int_num;
46545
46546 ZD_ASSERT(in_interrupt());
46547diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
46548index 7130864..00e64de 100644
46549--- a/drivers/nfc/nfcwilink.c
46550+++ b/drivers/nfc/nfcwilink.c
46551@@ -498,7 +498,7 @@ static struct nci_ops nfcwilink_ops = {
46552
46553 static int nfcwilink_probe(struct platform_device *pdev)
46554 {
46555- static struct nfcwilink *drv;
46556+ struct nfcwilink *drv;
46557 int rc;
46558 __u32 protocols;
46559
46560diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
46561index d93b2b6..ae50401 100644
46562--- a/drivers/oprofile/buffer_sync.c
46563+++ b/drivers/oprofile/buffer_sync.c
46564@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
46565 if (cookie == NO_COOKIE)
46566 offset = pc;
46567 if (cookie == INVALID_COOKIE) {
46568- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
46569+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
46570 offset = pc;
46571 }
46572 if (cookie != last_cookie) {
46573@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
46574 /* add userspace sample */
46575
46576 if (!mm) {
46577- atomic_inc(&oprofile_stats.sample_lost_no_mm);
46578+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
46579 return 0;
46580 }
46581
46582 cookie = lookup_dcookie(mm, s->eip, &offset);
46583
46584 if (cookie == INVALID_COOKIE) {
46585- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
46586+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
46587 return 0;
46588 }
46589
46590@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
46591 /* ignore backtraces if failed to add a sample */
46592 if (state == sb_bt_start) {
46593 state = sb_bt_ignore;
46594- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
46595+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
46596 }
46597 }
46598 release_mm(mm);
46599diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
46600index c0cc4e7..44d4e54 100644
46601--- a/drivers/oprofile/event_buffer.c
46602+++ b/drivers/oprofile/event_buffer.c
46603@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
46604 }
46605
46606 if (buffer_pos == buffer_size) {
46607- atomic_inc(&oprofile_stats.event_lost_overflow);
46608+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
46609 return;
46610 }
46611
46612diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
46613index ed2c3ec..deda85a 100644
46614--- a/drivers/oprofile/oprof.c
46615+++ b/drivers/oprofile/oprof.c
46616@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
46617 if (oprofile_ops.switch_events())
46618 return;
46619
46620- atomic_inc(&oprofile_stats.multiplex_counter);
46621+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
46622 start_switch_worker();
46623 }
46624
46625diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
46626index ee2cfce..7f8f699 100644
46627--- a/drivers/oprofile/oprofile_files.c
46628+++ b/drivers/oprofile/oprofile_files.c
46629@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
46630
46631 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
46632
46633-static ssize_t timeout_read(struct file *file, char __user *buf,
46634+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
46635 size_t count, loff_t *offset)
46636 {
46637 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
46638diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
46639index 59659ce..6c860a0 100644
46640--- a/drivers/oprofile/oprofile_stats.c
46641+++ b/drivers/oprofile/oprofile_stats.c
46642@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
46643 cpu_buf->sample_invalid_eip = 0;
46644 }
46645
46646- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
46647- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
46648- atomic_set(&oprofile_stats.event_lost_overflow, 0);
46649- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
46650- atomic_set(&oprofile_stats.multiplex_counter, 0);
46651+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
46652+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
46653+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
46654+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
46655+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
46656 }
46657
46658
46659diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
46660index 1fc622b..8c48fc3 100644
46661--- a/drivers/oprofile/oprofile_stats.h
46662+++ b/drivers/oprofile/oprofile_stats.h
46663@@ -13,11 +13,11 @@
46664 #include <linux/atomic.h>
46665
46666 struct oprofile_stat_struct {
46667- atomic_t sample_lost_no_mm;
46668- atomic_t sample_lost_no_mapping;
46669- atomic_t bt_lost_no_mapping;
46670- atomic_t event_lost_overflow;
46671- atomic_t multiplex_counter;
46672+ atomic_unchecked_t sample_lost_no_mm;
46673+ atomic_unchecked_t sample_lost_no_mapping;
46674+ atomic_unchecked_t bt_lost_no_mapping;
46675+ atomic_unchecked_t event_lost_overflow;
46676+ atomic_unchecked_t multiplex_counter;
46677 };
46678
46679 extern struct oprofile_stat_struct oprofile_stats;
46680diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
46681index 3f49345..c750d0b 100644
46682--- a/drivers/oprofile/oprofilefs.c
46683+++ b/drivers/oprofile/oprofilefs.c
46684@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
46685
46686 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
46687 {
46688- atomic_t *val = file->private_data;
46689- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
46690+ atomic_unchecked_t *val = file->private_data;
46691+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
46692 }
46693
46694
46695@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
46696
46697
46698 int oprofilefs_create_ro_atomic(struct dentry *root,
46699- char const *name, atomic_t *val)
46700+ char const *name, atomic_unchecked_t *val)
46701 {
46702 return __oprofilefs_create_file(root, name,
46703 &atomic_ro_fops, 0444, val);
46704diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
46705index 61be1d9..dec05d7 100644
46706--- a/drivers/oprofile/timer_int.c
46707+++ b/drivers/oprofile/timer_int.c
46708@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
46709 return NOTIFY_OK;
46710 }
46711
46712-static struct notifier_block __refdata oprofile_cpu_notifier = {
46713+static struct notifier_block oprofile_cpu_notifier = {
46714 .notifier_call = oprofile_cpu_notify,
46715 };
46716
46717diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
46718index 92ed045..62d39bd7 100644
46719--- a/drivers/parport/procfs.c
46720+++ b/drivers/parport/procfs.c
46721@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
46722
46723 *ppos += len;
46724
46725- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
46726+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
46727 }
46728
46729 #ifdef CONFIG_PARPORT_1284
46730@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
46731
46732 *ppos += len;
46733
46734- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
46735+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
46736 }
46737 #endif /* IEEE1284.3 support. */
46738
46739diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
46740index ecfac7e..41be7028 100644
46741--- a/drivers/pci/hotplug/acpiphp_ibm.c
46742+++ b/drivers/pci/hotplug/acpiphp_ibm.c
46743@@ -453,7 +453,9 @@ static int __init ibm_acpiphp_init(void)
46744 goto init_cleanup;
46745 }
46746
46747- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
46748+ pax_open_kernel();
46749+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
46750+ pax_close_kernel();
46751 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
46752
46753 return retval;
46754diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
46755index 7536eef..52dc8fa 100644
46756--- a/drivers/pci/hotplug/cpcihp_generic.c
46757+++ b/drivers/pci/hotplug/cpcihp_generic.c
46758@@ -73,7 +73,6 @@ static u16 port;
46759 static unsigned int enum_bit;
46760 static u8 enum_mask;
46761
46762-static struct cpci_hp_controller_ops generic_hpc_ops;
46763 static struct cpci_hp_controller generic_hpc;
46764
46765 static int __init validate_parameters(void)
46766@@ -139,6 +138,10 @@ static int query_enum(void)
46767 return ((value & enum_mask) == enum_mask);
46768 }
46769
46770+static struct cpci_hp_controller_ops generic_hpc_ops = {
46771+ .query_enum = query_enum,
46772+};
46773+
46774 static int __init cpcihp_generic_init(void)
46775 {
46776 int status;
46777@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
46778 pci_dev_put(dev);
46779
46780 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
46781- generic_hpc_ops.query_enum = query_enum;
46782 generic_hpc.ops = &generic_hpc_ops;
46783
46784 status = cpci_hp_register_controller(&generic_hpc);
46785diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
46786index e8c4a7c..7046f5c 100644
46787--- a/drivers/pci/hotplug/cpcihp_zt5550.c
46788+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
46789@@ -59,7 +59,6 @@
46790 /* local variables */
46791 static bool debug;
46792 static bool poll;
46793-static struct cpci_hp_controller_ops zt5550_hpc_ops;
46794 static struct cpci_hp_controller zt5550_hpc;
46795
46796 /* Primary cPCI bus bridge device */
46797@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
46798 return 0;
46799 }
46800
46801+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
46802+ .query_enum = zt5550_hc_query_enum,
46803+};
46804+
46805 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
46806 {
46807 int status;
46808@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
46809 dbg("returned from zt5550_hc_config");
46810
46811 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
46812- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
46813 zt5550_hpc.ops = &zt5550_hpc_ops;
46814 if(!poll) {
46815 zt5550_hpc.irq = hc_dev->irq;
46816 zt5550_hpc.irq_flags = IRQF_SHARED;
46817 zt5550_hpc.dev_id = hc_dev;
46818
46819- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
46820- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
46821- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
46822+ pax_open_kernel();
46823+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
46824+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
46825+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
46826+ pax_open_kernel();
46827 } else {
46828 info("using ENUM# polling mode");
46829 }
46830diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
46831index 76ba8a1..20ca857 100644
46832--- a/drivers/pci/hotplug/cpqphp_nvram.c
46833+++ b/drivers/pci/hotplug/cpqphp_nvram.c
46834@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
46835
46836 void compaq_nvram_init (void __iomem *rom_start)
46837 {
46838+
46839+#ifndef CONFIG_PAX_KERNEXEC
46840 if (rom_start) {
46841 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
46842 }
46843+#endif
46844+
46845 dbg("int15 entry = %p\n", compaq_int15_entry_point);
46846
46847 /* initialize our int15 lock */
46848diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
46849index cfa92a9..29539c5 100644
46850--- a/drivers/pci/hotplug/pci_hotplug_core.c
46851+++ b/drivers/pci/hotplug/pci_hotplug_core.c
46852@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
46853 return -EINVAL;
46854 }
46855
46856- slot->ops->owner = owner;
46857- slot->ops->mod_name = mod_name;
46858+ pax_open_kernel();
46859+ *(struct module **)&slot->ops->owner = owner;
46860+ *(const char **)&slot->ops->mod_name = mod_name;
46861+ pax_close_kernel();
46862
46863 mutex_lock(&pci_hp_mutex);
46864 /*
46865diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
46866index bbd48bb..6907ef4 100644
46867--- a/drivers/pci/hotplug/pciehp_core.c
46868+++ b/drivers/pci/hotplug/pciehp_core.c
46869@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
46870 struct slot *slot = ctrl->slot;
46871 struct hotplug_slot *hotplug = NULL;
46872 struct hotplug_slot_info *info = NULL;
46873- struct hotplug_slot_ops *ops = NULL;
46874+ hotplug_slot_ops_no_const *ops = NULL;
46875 char name[SLOT_NAME_SIZE];
46876 int retval = -ENOMEM;
46877
46878diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
46879index c91e6c1..5c723ef 100644
46880--- a/drivers/pci/pci-sysfs.c
46881+++ b/drivers/pci/pci-sysfs.c
46882@@ -1117,7 +1117,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
46883 {
46884 /* allocate attribute structure, piggyback attribute name */
46885 int name_len = write_combine ? 13 : 10;
46886- struct bin_attribute *res_attr;
46887+ bin_attribute_no_const *res_attr;
46888 int retval;
46889
46890 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
46891@@ -1302,7 +1302,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
46892 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
46893 {
46894 int retval;
46895- struct bin_attribute *attr;
46896+ bin_attribute_no_const *attr;
46897
46898 /* If the device has VPD, try to expose it in sysfs. */
46899 if (dev->vpd) {
46900@@ -1349,7 +1349,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
46901 {
46902 int retval;
46903 int rom_size = 0;
46904- struct bin_attribute *attr;
46905+ bin_attribute_no_const *attr;
46906
46907 if (!sysfs_initialized)
46908 return -EACCES;
46909diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
46910index 9c91ecc..bda4796 100644
46911--- a/drivers/pci/pci.h
46912+++ b/drivers/pci/pci.h
46913@@ -95,7 +95,7 @@ struct pci_vpd_ops {
46914 struct pci_vpd {
46915 unsigned int len;
46916 const struct pci_vpd_ops *ops;
46917- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
46918+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
46919 };
46920
46921 int pci_vpd_pci22_init(struct pci_dev *dev);
46922diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
46923index f1272dc..e92a1ac 100644
46924--- a/drivers/pci/pcie/aspm.c
46925+++ b/drivers/pci/pcie/aspm.c
46926@@ -27,9 +27,9 @@
46927 #define MODULE_PARAM_PREFIX "pcie_aspm."
46928
46929 /* Note: those are not register definitions */
46930-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
46931-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
46932-#define ASPM_STATE_L1 (4) /* L1 state */
46933+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
46934+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
46935+#define ASPM_STATE_L1 (4U) /* L1 state */
46936 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
46937 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
46938
46939diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
46940index 38e403d..a2ce55a 100644
46941--- a/drivers/pci/probe.c
46942+++ b/drivers/pci/probe.c
46943@@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
46944 struct pci_bus_region region, inverted_region;
46945 bool bar_too_big = false, bar_disabled = false;
46946
46947- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
46948+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
46949
46950 /* No printks while decoding is disabled! */
46951 if (!dev->mmio_always_on) {
46952diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
46953index 46d1378..30e452b 100644
46954--- a/drivers/pci/proc.c
46955+++ b/drivers/pci/proc.c
46956@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
46957 static int __init pci_proc_init(void)
46958 {
46959 struct pci_dev *dev = NULL;
46960+
46961+#ifdef CONFIG_GRKERNSEC_PROC_ADD
46962+#ifdef CONFIG_GRKERNSEC_PROC_USER
46963+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
46964+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46965+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
46966+#endif
46967+#else
46968 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
46969+#endif
46970 proc_create("devices", 0, proc_bus_pci_dir,
46971 &proc_bus_pci_dev_operations);
46972 proc_initialized = 1;
46973diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
46974index 3e5b4497..dcdfb70 100644
46975--- a/drivers/platform/chrome/chromeos_laptop.c
46976+++ b/drivers/platform/chrome/chromeos_laptop.c
46977@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
46978 return 0;
46979 }
46980
46981-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
46982+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
46983 {
46984 .ident = "Samsung Series 5 550 - Touchpad",
46985 .matches = {
46986diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
46987index 19c313b..ed28b38 100644
46988--- a/drivers/platform/x86/asus-wmi.c
46989+++ b/drivers/platform/x86/asus-wmi.c
46990@@ -1618,6 +1618,10 @@ static int show_dsts(struct seq_file *m, void *data)
46991 int err;
46992 u32 retval = -1;
46993
46994+#ifdef CONFIG_GRKERNSEC_KMEM
46995+ return -EPERM;
46996+#endif
46997+
46998 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
46999
47000 if (err < 0)
47001@@ -1634,6 +1638,10 @@ static int show_devs(struct seq_file *m, void *data)
47002 int err;
47003 u32 retval = -1;
47004
47005+#ifdef CONFIG_GRKERNSEC_KMEM
47006+ return -EPERM;
47007+#endif
47008+
47009 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
47010 &retval);
47011
47012@@ -1658,6 +1666,10 @@ static int show_call(struct seq_file *m, void *data)
47013 union acpi_object *obj;
47014 acpi_status status;
47015
47016+#ifdef CONFIG_GRKERNSEC_KMEM
47017+ return -EPERM;
47018+#endif
47019+
47020 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
47021 1, asus->debug.method_id,
47022 &input, &output);
47023diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
47024index 62f8030..c7f2a45 100644
47025--- a/drivers/platform/x86/msi-laptop.c
47026+++ b/drivers/platform/x86/msi-laptop.c
47027@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
47028
47029 if (!quirks->ec_read_only) {
47030 /* allow userland write sysfs file */
47031- dev_attr_bluetooth.store = store_bluetooth;
47032- dev_attr_wlan.store = store_wlan;
47033- dev_attr_threeg.store = store_threeg;
47034- dev_attr_bluetooth.attr.mode |= S_IWUSR;
47035- dev_attr_wlan.attr.mode |= S_IWUSR;
47036- dev_attr_threeg.attr.mode |= S_IWUSR;
47037+ pax_open_kernel();
47038+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
47039+ *(void **)&dev_attr_wlan.store = store_wlan;
47040+ *(void **)&dev_attr_threeg.store = store_threeg;
47041+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
47042+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
47043+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
47044+ pax_close_kernel();
47045 }
47046
47047 /* disable hardware control by fn key */
47048diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
47049index 70222f2..8c8ce66 100644
47050--- a/drivers/platform/x86/msi-wmi.c
47051+++ b/drivers/platform/x86/msi-wmi.c
47052@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
47053 static void msi_wmi_notify(u32 value, void *context)
47054 {
47055 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
47056- static struct key_entry *key;
47057+ struct key_entry *key;
47058 union acpi_object *obj;
47059 acpi_status status;
47060
47061diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
47062index fb233ae..23a325c 100644
47063--- a/drivers/platform/x86/sony-laptop.c
47064+++ b/drivers/platform/x86/sony-laptop.c
47065@@ -2453,7 +2453,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
47066 }
47067
47068 /* High speed charging function */
47069-static struct device_attribute *hsc_handle;
47070+static device_attribute_no_const *hsc_handle;
47071
47072 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
47073 struct device_attribute *attr,
47074diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
47075index 58b0274..6704626 100644
47076--- a/drivers/platform/x86/thinkpad_acpi.c
47077+++ b/drivers/platform/x86/thinkpad_acpi.c
47078@@ -2100,7 +2100,7 @@ static int hotkey_mask_get(void)
47079 return 0;
47080 }
47081
47082-void static hotkey_mask_warn_incomplete_mask(void)
47083+static void hotkey_mask_warn_incomplete_mask(void)
47084 {
47085 /* log only what the user can fix... */
47086 const u32 wantedmask = hotkey_driver_mask &
47087@@ -2327,11 +2327,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
47088 }
47089 }
47090
47091-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47092- struct tp_nvram_state *newn,
47093- const u32 event_mask)
47094-{
47095-
47096 #define TPACPI_COMPARE_KEY(__scancode, __member) \
47097 do { \
47098 if ((event_mask & (1 << __scancode)) && \
47099@@ -2345,36 +2340,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47100 tpacpi_hotkey_send_key(__scancode); \
47101 } while (0)
47102
47103- void issue_volchange(const unsigned int oldvol,
47104- const unsigned int newvol)
47105- {
47106- unsigned int i = oldvol;
47107+static void issue_volchange(const unsigned int oldvol,
47108+ const unsigned int newvol,
47109+ const u32 event_mask)
47110+{
47111+ unsigned int i = oldvol;
47112
47113- while (i > newvol) {
47114- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47115- i--;
47116- }
47117- while (i < newvol) {
47118- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47119- i++;
47120- }
47121+ while (i > newvol) {
47122+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47123+ i--;
47124 }
47125+ while (i < newvol) {
47126+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47127+ i++;
47128+ }
47129+}
47130
47131- void issue_brightnesschange(const unsigned int oldbrt,
47132- const unsigned int newbrt)
47133- {
47134- unsigned int i = oldbrt;
47135+static void issue_brightnesschange(const unsigned int oldbrt,
47136+ const unsigned int newbrt,
47137+ const u32 event_mask)
47138+{
47139+ unsigned int i = oldbrt;
47140
47141- while (i > newbrt) {
47142- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47143- i--;
47144- }
47145- while (i < newbrt) {
47146- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47147- i++;
47148- }
47149+ while (i > newbrt) {
47150+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47151+ i--;
47152+ }
47153+ while (i < newbrt) {
47154+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47155+ i++;
47156 }
47157+}
47158
47159+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47160+ struct tp_nvram_state *newn,
47161+ const u32 event_mask)
47162+{
47163 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
47164 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
47165 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
47166@@ -2408,7 +2409,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47167 oldn->volume_level != newn->volume_level) {
47168 /* recently muted, or repeated mute keypress, or
47169 * multiple presses ending in mute */
47170- issue_volchange(oldn->volume_level, newn->volume_level);
47171+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47172 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
47173 }
47174 } else {
47175@@ -2418,7 +2419,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47176 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47177 }
47178 if (oldn->volume_level != newn->volume_level) {
47179- issue_volchange(oldn->volume_level, newn->volume_level);
47180+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47181 } else if (oldn->volume_toggle != newn->volume_toggle) {
47182 /* repeated vol up/down keypress at end of scale ? */
47183 if (newn->volume_level == 0)
47184@@ -2431,7 +2432,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47185 /* handle brightness */
47186 if (oldn->brightness_level != newn->brightness_level) {
47187 issue_brightnesschange(oldn->brightness_level,
47188- newn->brightness_level);
47189+ newn->brightness_level,
47190+ event_mask);
47191 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
47192 /* repeated key presses that didn't change state */
47193 if (newn->brightness_level == 0)
47194@@ -2440,10 +2442,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47195 && !tp_features.bright_unkfw)
47196 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47197 }
47198+}
47199
47200 #undef TPACPI_COMPARE_KEY
47201 #undef TPACPI_MAY_SEND_KEY
47202-}
47203
47204 /*
47205 * Polling driver
47206diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
47207index 769d265..a3a05ca 100644
47208--- a/drivers/pnp/pnpbios/bioscalls.c
47209+++ b/drivers/pnp/pnpbios/bioscalls.c
47210@@ -58,7 +58,7 @@ do { \
47211 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
47212 } while(0)
47213
47214-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
47215+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
47216 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
47217
47218 /*
47219@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47220
47221 cpu = get_cpu();
47222 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
47223+
47224+ pax_open_kernel();
47225 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
47226+ pax_close_kernel();
47227
47228 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
47229 spin_lock_irqsave(&pnp_bios_lock, flags);
47230@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47231 :"memory");
47232 spin_unlock_irqrestore(&pnp_bios_lock, flags);
47233
47234+ pax_open_kernel();
47235 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
47236+ pax_close_kernel();
47237+
47238 put_cpu();
47239
47240 /* If we get here and this is set then the PnP BIOS faulted on us. */
47241@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
47242 return status;
47243 }
47244
47245-void pnpbios_calls_init(union pnp_bios_install_struct *header)
47246+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
47247 {
47248 int i;
47249
47250@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47251 pnp_bios_callpoint.offset = header->fields.pm16offset;
47252 pnp_bios_callpoint.segment = PNP_CS16;
47253
47254+ pax_open_kernel();
47255+
47256 for_each_possible_cpu(i) {
47257 struct desc_struct *gdt = get_cpu_gdt_table(i);
47258 if (!gdt)
47259@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47260 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
47261 (unsigned long)__va(header->fields.pm16dseg));
47262 }
47263+
47264+ pax_close_kernel();
47265 }
47266diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
47267index d95e101..67f0c3f 100644
47268--- a/drivers/pnp/resource.c
47269+++ b/drivers/pnp/resource.c
47270@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
47271 return 1;
47272
47273 /* check if the resource is valid */
47274- if (*irq < 0 || *irq > 15)
47275+ if (*irq > 15)
47276 return 0;
47277
47278 /* check if the resource is reserved */
47279@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
47280 return 1;
47281
47282 /* check if the resource is valid */
47283- if (*dma < 0 || *dma == 4 || *dma > 7)
47284+ if (*dma == 4 || *dma > 7)
47285 return 0;
47286
47287 /* check if the resource is reserved */
47288diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
47289index 0c52e2a..3421ab7 100644
47290--- a/drivers/power/pda_power.c
47291+++ b/drivers/power/pda_power.c
47292@@ -37,7 +37,11 @@ static int polling;
47293
47294 #if IS_ENABLED(CONFIG_USB_PHY)
47295 static struct usb_phy *transceiver;
47296-static struct notifier_block otg_nb;
47297+static int otg_handle_notification(struct notifier_block *nb,
47298+ unsigned long event, void *unused);
47299+static struct notifier_block otg_nb = {
47300+ .notifier_call = otg_handle_notification
47301+};
47302 #endif
47303
47304 static struct regulator *ac_draw;
47305@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
47306
47307 #if IS_ENABLED(CONFIG_USB_PHY)
47308 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
47309- otg_nb.notifier_call = otg_handle_notification;
47310 ret = usb_register_notifier(transceiver, &otg_nb);
47311 if (ret) {
47312 dev_err(dev, "failure to register otg notifier\n");
47313diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
47314index cc439fd..8fa30df 100644
47315--- a/drivers/power/power_supply.h
47316+++ b/drivers/power/power_supply.h
47317@@ -16,12 +16,12 @@ struct power_supply;
47318
47319 #ifdef CONFIG_SYSFS
47320
47321-extern void power_supply_init_attrs(struct device_type *dev_type);
47322+extern void power_supply_init_attrs(void);
47323 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
47324
47325 #else
47326
47327-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
47328+static inline void power_supply_init_attrs(void) {}
47329 #define power_supply_uevent NULL
47330
47331 #endif /* CONFIG_SYSFS */
47332diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
47333index 557af94..84dc1fe 100644
47334--- a/drivers/power/power_supply_core.c
47335+++ b/drivers/power/power_supply_core.c
47336@@ -24,7 +24,10 @@
47337 struct class *power_supply_class;
47338 EXPORT_SYMBOL_GPL(power_supply_class);
47339
47340-static struct device_type power_supply_dev_type;
47341+extern const struct attribute_group *power_supply_attr_groups[];
47342+static struct device_type power_supply_dev_type = {
47343+ .groups = power_supply_attr_groups,
47344+};
47345
47346 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
47347 struct power_supply *supply)
47348@@ -584,7 +587,7 @@ static int __init power_supply_class_init(void)
47349 return PTR_ERR(power_supply_class);
47350
47351 power_supply_class->dev_uevent = power_supply_uevent;
47352- power_supply_init_attrs(&power_supply_dev_type);
47353+ power_supply_init_attrs();
47354
47355 return 0;
47356 }
47357diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
47358index 44420d1..967126e 100644
47359--- a/drivers/power/power_supply_sysfs.c
47360+++ b/drivers/power/power_supply_sysfs.c
47361@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
47362 .is_visible = power_supply_attr_is_visible,
47363 };
47364
47365-static const struct attribute_group *power_supply_attr_groups[] = {
47366+const struct attribute_group *power_supply_attr_groups[] = {
47367 &power_supply_attr_group,
47368 NULL,
47369 };
47370
47371-void power_supply_init_attrs(struct device_type *dev_type)
47372+void power_supply_init_attrs(void)
47373 {
47374 int i;
47375
47376- dev_type->groups = power_supply_attr_groups;
47377-
47378 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
47379 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
47380 }
47381diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
47382index 84419af..268ede8 100644
47383--- a/drivers/powercap/powercap_sys.c
47384+++ b/drivers/powercap/powercap_sys.c
47385@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
47386 struct device_attribute name_attr;
47387 };
47388
47389+static ssize_t show_constraint_name(struct device *dev,
47390+ struct device_attribute *dev_attr,
47391+ char *buf);
47392+
47393 static struct powercap_constraint_attr
47394- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
47395+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
47396+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
47397+ .power_limit_attr = {
47398+ .attr = {
47399+ .name = NULL,
47400+ .mode = S_IWUSR | S_IRUGO
47401+ },
47402+ .show = show_constraint_power_limit_uw,
47403+ .store = store_constraint_power_limit_uw
47404+ },
47405+
47406+ .time_window_attr = {
47407+ .attr = {
47408+ .name = NULL,
47409+ .mode = S_IWUSR | S_IRUGO
47410+ },
47411+ .show = show_constraint_time_window_us,
47412+ .store = store_constraint_time_window_us
47413+ },
47414+
47415+ .max_power_attr = {
47416+ .attr = {
47417+ .name = NULL,
47418+ .mode = S_IRUGO
47419+ },
47420+ .show = show_constraint_max_power_uw,
47421+ .store = NULL
47422+ },
47423+
47424+ .min_power_attr = {
47425+ .attr = {
47426+ .name = NULL,
47427+ .mode = S_IRUGO
47428+ },
47429+ .show = show_constraint_min_power_uw,
47430+ .store = NULL
47431+ },
47432+
47433+ .max_time_window_attr = {
47434+ .attr = {
47435+ .name = NULL,
47436+ .mode = S_IRUGO
47437+ },
47438+ .show = show_constraint_max_time_window_us,
47439+ .store = NULL
47440+ },
47441+
47442+ .min_time_window_attr = {
47443+ .attr = {
47444+ .name = NULL,
47445+ .mode = S_IRUGO
47446+ },
47447+ .show = show_constraint_min_time_window_us,
47448+ .store = NULL
47449+ },
47450+
47451+ .name_attr = {
47452+ .attr = {
47453+ .name = NULL,
47454+ .mode = S_IRUGO
47455+ },
47456+ .show = show_constraint_name,
47457+ .store = NULL
47458+ }
47459+ }
47460+};
47461
47462 /* A list of powercap control_types */
47463 static LIST_HEAD(powercap_cntrl_list);
47464@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
47465 }
47466
47467 static int create_constraint_attribute(int id, const char *name,
47468- int mode,
47469- struct device_attribute *dev_attr,
47470- ssize_t (*show)(struct device *,
47471- struct device_attribute *, char *),
47472- ssize_t (*store)(struct device *,
47473- struct device_attribute *,
47474- const char *, size_t)
47475- )
47476+ struct device_attribute *dev_attr)
47477 {
47478+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
47479
47480- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
47481- id, name);
47482- if (!dev_attr->attr.name)
47483+ if (!name)
47484 return -ENOMEM;
47485- dev_attr->attr.mode = mode;
47486- dev_attr->show = show;
47487- dev_attr->store = store;
47488+
47489+ pax_open_kernel();
47490+ *(const char **)&dev_attr->attr.name = name;
47491+ pax_close_kernel();
47492
47493 return 0;
47494 }
47495@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
47496
47497 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
47498 ret = create_constraint_attribute(i, "power_limit_uw",
47499- S_IWUSR | S_IRUGO,
47500- &constraint_attrs[i].power_limit_attr,
47501- show_constraint_power_limit_uw,
47502- store_constraint_power_limit_uw);
47503+ &constraint_attrs[i].power_limit_attr);
47504 if (ret)
47505 goto err_alloc;
47506 ret = create_constraint_attribute(i, "time_window_us",
47507- S_IWUSR | S_IRUGO,
47508- &constraint_attrs[i].time_window_attr,
47509- show_constraint_time_window_us,
47510- store_constraint_time_window_us);
47511+ &constraint_attrs[i].time_window_attr);
47512 if (ret)
47513 goto err_alloc;
47514- ret = create_constraint_attribute(i, "name", S_IRUGO,
47515- &constraint_attrs[i].name_attr,
47516- show_constraint_name,
47517- NULL);
47518+ ret = create_constraint_attribute(i, "name",
47519+ &constraint_attrs[i].name_attr);
47520 if (ret)
47521 goto err_alloc;
47522- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
47523- &constraint_attrs[i].max_power_attr,
47524- show_constraint_max_power_uw,
47525- NULL);
47526+ ret = create_constraint_attribute(i, "max_power_uw",
47527+ &constraint_attrs[i].max_power_attr);
47528 if (ret)
47529 goto err_alloc;
47530- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
47531- &constraint_attrs[i].min_power_attr,
47532- show_constraint_min_power_uw,
47533- NULL);
47534+ ret = create_constraint_attribute(i, "min_power_uw",
47535+ &constraint_attrs[i].min_power_attr);
47536 if (ret)
47537 goto err_alloc;
47538 ret = create_constraint_attribute(i, "max_time_window_us",
47539- S_IRUGO,
47540- &constraint_attrs[i].max_time_window_attr,
47541- show_constraint_max_time_window_us,
47542- NULL);
47543+ &constraint_attrs[i].max_time_window_attr);
47544 if (ret)
47545 goto err_alloc;
47546 ret = create_constraint_attribute(i, "min_time_window_us",
47547- S_IRUGO,
47548- &constraint_attrs[i].min_time_window_attr,
47549- show_constraint_min_time_window_us,
47550- NULL);
47551+ &constraint_attrs[i].min_time_window_attr);
47552 if (ret)
47553 goto err_alloc;
47554
47555@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
47556 power_zone->zone_dev_attrs[count++] =
47557 &dev_attr_max_energy_range_uj.attr;
47558 if (power_zone->ops->get_energy_uj) {
47559+ pax_open_kernel();
47560 if (power_zone->ops->reset_energy_uj)
47561- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
47562+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
47563 else
47564- dev_attr_energy_uj.attr.mode = S_IRUGO;
47565+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
47566+ pax_close_kernel();
47567 power_zone->zone_dev_attrs[count++] =
47568 &dev_attr_energy_uj.attr;
47569 }
47570diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
47571index d85f313..ae857d0 100644
47572--- a/drivers/regulator/core.c
47573+++ b/drivers/regulator/core.c
47574@@ -3362,7 +3362,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
47575 {
47576 const struct regulation_constraints *constraints = NULL;
47577 const struct regulator_init_data *init_data;
47578- static atomic_t regulator_no = ATOMIC_INIT(0);
47579+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
47580 struct regulator_dev *rdev;
47581 struct device *dev;
47582 int ret, i;
47583@@ -3432,7 +3432,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
47584 rdev->dev.of_node = config->of_node;
47585 rdev->dev.parent = dev;
47586 dev_set_name(&rdev->dev, "regulator.%d",
47587- atomic_inc_return(&regulator_no) - 1);
47588+ atomic_inc_return_unchecked(&regulator_no) - 1);
47589 ret = device_register(&rdev->dev);
47590 if (ret != 0) {
47591 put_device(&rdev->dev);
47592diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
47593index 8d94d3d..653b623 100644
47594--- a/drivers/regulator/max8660.c
47595+++ b/drivers/regulator/max8660.c
47596@@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
47597 max8660->shadow_regs[MAX8660_OVER1] = 5;
47598 } else {
47599 /* Otherwise devices can be toggled via software */
47600- max8660_dcdc_ops.enable = max8660_dcdc_enable;
47601- max8660_dcdc_ops.disable = max8660_dcdc_disable;
47602+ pax_open_kernel();
47603+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
47604+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
47605+ pax_close_kernel();
47606 }
47607
47608 /*
47609diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
47610index 892aa1e..ebd1b9c 100644
47611--- a/drivers/regulator/max8973-regulator.c
47612+++ b/drivers/regulator/max8973-regulator.c
47613@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
47614 if (!pdata || !pdata->enable_ext_control) {
47615 max->desc.enable_reg = MAX8973_VOUT;
47616 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
47617- max->ops.enable = regulator_enable_regmap;
47618- max->ops.disable = regulator_disable_regmap;
47619- max->ops.is_enabled = regulator_is_enabled_regmap;
47620+ pax_open_kernel();
47621+ *(void **)&max->ops.enable = regulator_enable_regmap;
47622+ *(void **)&max->ops.disable = regulator_disable_regmap;
47623+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
47624+ pax_close_kernel();
47625 }
47626
47627 if (pdata) {
47628diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
47629index 96c9f80..90974ca 100644
47630--- a/drivers/regulator/mc13892-regulator.c
47631+++ b/drivers/regulator/mc13892-regulator.c
47632@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
47633 }
47634 mc13xxx_unlock(mc13892);
47635
47636- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
47637+ pax_open_kernel();
47638+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
47639 = mc13892_vcam_set_mode;
47640- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
47641+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
47642 = mc13892_vcam_get_mode;
47643+ pax_close_kernel();
47644
47645 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
47646 ARRAY_SIZE(mc13892_regulators));
47647diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
47648index f148762..5a6d1e5 100644
47649--- a/drivers/rtc/rtc-cmos.c
47650+++ b/drivers/rtc/rtc-cmos.c
47651@@ -731,7 +731,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
47652 hpet_rtc_timer_init();
47653
47654 /* export at least the first block of NVRAM */
47655- nvram.size = address_space - NVRAM_OFFSET;
47656+ pax_open_kernel();
47657+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
47658+ pax_close_kernel();
47659 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
47660 if (retval < 0) {
47661 dev_dbg(dev, "can't create nvram file? %d\n", retval);
47662diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
47663index d049393..bb20be0 100644
47664--- a/drivers/rtc/rtc-dev.c
47665+++ b/drivers/rtc/rtc-dev.c
47666@@ -16,6 +16,7 @@
47667 #include <linux/module.h>
47668 #include <linux/rtc.h>
47669 #include <linux/sched.h>
47670+#include <linux/grsecurity.h>
47671 #include "rtc-core.h"
47672
47673 static dev_t rtc_devt;
47674@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
47675 if (copy_from_user(&tm, uarg, sizeof(tm)))
47676 return -EFAULT;
47677
47678+ gr_log_timechange();
47679+
47680 return rtc_set_time(rtc, &tm);
47681
47682 case RTC_PIE_ON:
47683diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
47684index 4e75345..09f8663 100644
47685--- a/drivers/rtc/rtc-ds1307.c
47686+++ b/drivers/rtc/rtc-ds1307.c
47687@@ -107,7 +107,7 @@ struct ds1307 {
47688 u8 offset; /* register's offset */
47689 u8 regs[11];
47690 u16 nvram_offset;
47691- struct bin_attribute *nvram;
47692+ bin_attribute_no_const *nvram;
47693 enum ds_type type;
47694 unsigned long flags;
47695 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
47696diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
47697index 11880c1..b823aa4 100644
47698--- a/drivers/rtc/rtc-m48t59.c
47699+++ b/drivers/rtc/rtc-m48t59.c
47700@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
47701 if (IS_ERR(m48t59->rtc))
47702 return PTR_ERR(m48t59->rtc);
47703
47704- m48t59_nvram_attr.size = pdata->offset;
47705+ pax_open_kernel();
47706+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
47707+ pax_close_kernel();
47708
47709 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
47710 if (ret)
47711diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
47712index 14b5f8d..cc9bd26 100644
47713--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
47714+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
47715@@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
47716 for (bit = 0; bit < 8; bit++) {
47717
47718 if ((pci_status[i] & (0x1 << bit)) != 0) {
47719- static const char *s;
47720+ const char *s;
47721
47722 s = pci_status_strings[bit];
47723 if (i == 7/*TARG*/ && bit == 3)
47724@@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
47725
47726 for (bit = 0; bit < 8; bit++) {
47727
47728- if ((split_status[i] & (0x1 << bit)) != 0) {
47729- static const char *s;
47730-
47731- s = split_status_strings[bit];
47732- printk(s, ahd_name(ahd),
47733+ if ((split_status[i] & (0x1 << bit)) != 0)
47734+ printk(split_status_strings[bit], ahd_name(ahd),
47735 split_status_source[i]);
47736- }
47737
47738 if (i > 1)
47739 continue;
47740
47741- if ((sg_split_status[i] & (0x1 << bit)) != 0) {
47742- static const char *s;
47743-
47744- s = split_status_strings[bit];
47745- printk(s, ahd_name(ahd), "SG");
47746- }
47747+ if ((sg_split_status[i] & (0x1 << bit)) != 0)
47748+ printk(split_status_strings[bit], ahd_name(ahd), "SG");
47749 }
47750 }
47751 /*
47752diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
47753index e693af6..2e525b6 100644
47754--- a/drivers/scsi/bfa/bfa_fcpim.h
47755+++ b/drivers/scsi/bfa/bfa_fcpim.h
47756@@ -36,7 +36,7 @@ struct bfa_iotag_s {
47757
47758 struct bfa_itn_s {
47759 bfa_isr_func_t isr;
47760-};
47761+} __no_const;
47762
47763 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
47764 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
47765diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
47766index a3ab5cc..8143622 100644
47767--- a/drivers/scsi/bfa/bfa_fcs.c
47768+++ b/drivers/scsi/bfa/bfa_fcs.c
47769@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
47770 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
47771
47772 static struct bfa_fcs_mod_s fcs_modules[] = {
47773- { bfa_fcs_port_attach, NULL, NULL },
47774- { bfa_fcs_uf_attach, NULL, NULL },
47775- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
47776- bfa_fcs_fabric_modexit },
47777+ {
47778+ .attach = bfa_fcs_port_attach,
47779+ .modinit = NULL,
47780+ .modexit = NULL
47781+ },
47782+ {
47783+ .attach = bfa_fcs_uf_attach,
47784+ .modinit = NULL,
47785+ .modexit = NULL
47786+ },
47787+ {
47788+ .attach = bfa_fcs_fabric_attach,
47789+ .modinit = bfa_fcs_fabric_modinit,
47790+ .modexit = bfa_fcs_fabric_modexit
47791+ },
47792 };
47793
47794 /*
47795diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
47796index f5e4e61..a0acaf6 100644
47797--- a/drivers/scsi/bfa/bfa_fcs_lport.c
47798+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
47799@@ -89,15 +89,26 @@ static struct {
47800 void (*offline) (struct bfa_fcs_lport_s *port);
47801 } __port_action[] = {
47802 {
47803- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
47804- bfa_fcs_lport_unknown_offline}, {
47805- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
47806- bfa_fcs_lport_fab_offline}, {
47807- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
47808- bfa_fcs_lport_n2n_offline}, {
47809- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
47810- bfa_fcs_lport_loop_offline},
47811- };
47812+ .init = bfa_fcs_lport_unknown_init,
47813+ .online = bfa_fcs_lport_unknown_online,
47814+ .offline = bfa_fcs_lport_unknown_offline
47815+ },
47816+ {
47817+ .init = bfa_fcs_lport_fab_init,
47818+ .online = bfa_fcs_lport_fab_online,
47819+ .offline = bfa_fcs_lport_fab_offline
47820+ },
47821+ {
47822+ .init = bfa_fcs_lport_n2n_init,
47823+ .online = bfa_fcs_lport_n2n_online,
47824+ .offline = bfa_fcs_lport_n2n_offline
47825+ },
47826+ {
47827+ .init = bfa_fcs_lport_loop_init,
47828+ .online = bfa_fcs_lport_loop_online,
47829+ .offline = bfa_fcs_lport_loop_offline
47830+ },
47831+};
47832
47833 /*
47834 * fcs_port_sm FCS logical port state machine
47835diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
47836index 90814fe..4384138 100644
47837--- a/drivers/scsi/bfa/bfa_ioc.h
47838+++ b/drivers/scsi/bfa/bfa_ioc.h
47839@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
47840 bfa_ioc_disable_cbfn_t disable_cbfn;
47841 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
47842 bfa_ioc_reset_cbfn_t reset_cbfn;
47843-};
47844+} __no_const;
47845
47846 /*
47847 * IOC event notification mechanism.
47848@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
47849 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
47850 enum bfi_ioc_state fwstate);
47851 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
47852-};
47853+} __no_const;
47854
47855 /*
47856 * Queue element to wait for room in request queue. FIFO order is
47857diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
47858index a14c784..6de6790 100644
47859--- a/drivers/scsi/bfa/bfa_modules.h
47860+++ b/drivers/scsi/bfa/bfa_modules.h
47861@@ -78,12 +78,12 @@ enum {
47862 \
47863 extern struct bfa_module_s hal_mod_ ## __mod; \
47864 struct bfa_module_s hal_mod_ ## __mod = { \
47865- bfa_ ## __mod ## _meminfo, \
47866- bfa_ ## __mod ## _attach, \
47867- bfa_ ## __mod ## _detach, \
47868- bfa_ ## __mod ## _start, \
47869- bfa_ ## __mod ## _stop, \
47870- bfa_ ## __mod ## _iocdisable, \
47871+ .meminfo = bfa_ ## __mod ## _meminfo, \
47872+ .attach = bfa_ ## __mod ## _attach, \
47873+ .detach = bfa_ ## __mod ## _detach, \
47874+ .start = bfa_ ## __mod ## _start, \
47875+ .stop = bfa_ ## __mod ## _stop, \
47876+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
47877 }
47878
47879 #define BFA_CACHELINE_SZ (256)
47880diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
47881index 045c4e1..13de803 100644
47882--- a/drivers/scsi/fcoe/fcoe_sysfs.c
47883+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
47884@@ -33,8 +33,8 @@
47885 */
47886 #include "libfcoe.h"
47887
47888-static atomic_t ctlr_num;
47889-static atomic_t fcf_num;
47890+static atomic_unchecked_t ctlr_num;
47891+static atomic_unchecked_t fcf_num;
47892
47893 /*
47894 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
47895@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
47896 if (!ctlr)
47897 goto out;
47898
47899- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
47900+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
47901 ctlr->f = f;
47902 ctlr->mode = FIP_CONN_TYPE_FABRIC;
47903 INIT_LIST_HEAD(&ctlr->fcfs);
47904@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
47905 fcf->dev.parent = &ctlr->dev;
47906 fcf->dev.bus = &fcoe_bus_type;
47907 fcf->dev.type = &fcoe_fcf_device_type;
47908- fcf->id = atomic_inc_return(&fcf_num) - 1;
47909+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
47910 fcf->state = FCOE_FCF_STATE_UNKNOWN;
47911
47912 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
47913@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
47914 {
47915 int error;
47916
47917- atomic_set(&ctlr_num, 0);
47918- atomic_set(&fcf_num, 0);
47919+ atomic_set_unchecked(&ctlr_num, 0);
47920+ atomic_set_unchecked(&fcf_num, 0);
47921
47922 error = bus_register(&fcoe_bus_type);
47923 if (error)
47924diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
47925index f2c5005..db36c02 100644
47926--- a/drivers/scsi/hosts.c
47927+++ b/drivers/scsi/hosts.c
47928@@ -42,7 +42,7 @@
47929 #include "scsi_logging.h"
47930
47931
47932-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
47933+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
47934
47935
47936 static void scsi_host_cls_release(struct device *dev)
47937@@ -367,7 +367,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
47938 * subtract one because we increment first then return, but we need to
47939 * know what the next host number was before increment
47940 */
47941- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
47942+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
47943 shost->dma_channel = 0xff;
47944
47945 /* These three are default values which can be overridden */
47946diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
47947index 20a5e6e..8b23cea 100644
47948--- a/drivers/scsi/hpsa.c
47949+++ b/drivers/scsi/hpsa.c
47950@@ -578,7 +578,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
47951 unsigned long flags;
47952
47953 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
47954- return h->access.command_completed(h, q);
47955+ return h->access->command_completed(h, q);
47956
47957 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
47958 a = rq->head[rq->current_entry];
47959@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
47960 while (!list_empty(&h->reqQ)) {
47961 c = list_entry(h->reqQ.next, struct CommandList, list);
47962 /* can't do anything if fifo is full */
47963- if ((h->access.fifo_full(h))) {
47964+ if ((h->access->fifo_full(h))) {
47965 dev_warn(&h->pdev->dev, "fifo full\n");
47966 break;
47967 }
47968@@ -3466,7 +3466,7 @@ static void start_io(struct ctlr_info *h)
47969
47970 /* Tell the controller execute command */
47971 spin_unlock_irqrestore(&h->lock, flags);
47972- h->access.submit_command(h, c);
47973+ h->access->submit_command(h, c);
47974 spin_lock_irqsave(&h->lock, flags);
47975 }
47976 spin_unlock_irqrestore(&h->lock, flags);
47977@@ -3474,17 +3474,17 @@ static void start_io(struct ctlr_info *h)
47978
47979 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
47980 {
47981- return h->access.command_completed(h, q);
47982+ return h->access->command_completed(h, q);
47983 }
47984
47985 static inline bool interrupt_pending(struct ctlr_info *h)
47986 {
47987- return h->access.intr_pending(h);
47988+ return h->access->intr_pending(h);
47989 }
47990
47991 static inline long interrupt_not_for_us(struct ctlr_info *h)
47992 {
47993- return (h->access.intr_pending(h) == 0) ||
47994+ return (h->access->intr_pending(h) == 0) ||
47995 (h->interrupts_enabled == 0);
47996 }
47997
47998@@ -4386,7 +4386,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
47999 if (prod_index < 0)
48000 return -ENODEV;
48001 h->product_name = products[prod_index].product_name;
48002- h->access = *(products[prod_index].access);
48003+ h->access = products[prod_index].access;
48004
48005 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
48006 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
48007@@ -4668,7 +4668,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
48008
48009 assert_spin_locked(&lockup_detector_lock);
48010 remove_ctlr_from_lockup_detector_list(h);
48011- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48012+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48013 spin_lock_irqsave(&h->lock, flags);
48014 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
48015 spin_unlock_irqrestore(&h->lock, flags);
48016@@ -4845,7 +4845,7 @@ reinit_after_soft_reset:
48017 }
48018
48019 /* make sure the board interrupts are off */
48020- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48021+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48022
48023 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
48024 goto clean2;
48025@@ -4879,7 +4879,7 @@ reinit_after_soft_reset:
48026 * fake ones to scoop up any residual completions.
48027 */
48028 spin_lock_irqsave(&h->lock, flags);
48029- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48030+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48031 spin_unlock_irqrestore(&h->lock, flags);
48032 free_irqs(h);
48033 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
48034@@ -4898,9 +4898,9 @@ reinit_after_soft_reset:
48035 dev_info(&h->pdev->dev, "Board READY.\n");
48036 dev_info(&h->pdev->dev,
48037 "Waiting for stale completions to drain.\n");
48038- h->access.set_intr_mask(h, HPSA_INTR_ON);
48039+ h->access->set_intr_mask(h, HPSA_INTR_ON);
48040 msleep(10000);
48041- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48042+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48043
48044 rc = controller_reset_failed(h->cfgtable);
48045 if (rc)
48046@@ -4921,7 +4921,7 @@ reinit_after_soft_reset:
48047 }
48048
48049 /* Turn the interrupts on so we can service requests */
48050- h->access.set_intr_mask(h, HPSA_INTR_ON);
48051+ h->access->set_intr_mask(h, HPSA_INTR_ON);
48052
48053 hpsa_hba_inquiry(h);
48054 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
48055@@ -4976,7 +4976,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
48056 * To write all data in the battery backed cache to disks
48057 */
48058 hpsa_flush_cache(h);
48059- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48060+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48061 hpsa_free_irqs_and_disable_msix(h);
48062 }
48063
48064@@ -5143,7 +5143,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
48065 return;
48066 }
48067 /* Change the access methods to the performant access methods */
48068- h->access = SA5_performant_access;
48069+ h->access = &SA5_performant_access;
48070 h->transMethod = CFGTBL_Trans_Performant;
48071 }
48072
48073diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
48074index bc85e72..d463049 100644
48075--- a/drivers/scsi/hpsa.h
48076+++ b/drivers/scsi/hpsa.h
48077@@ -79,7 +79,7 @@ struct ctlr_info {
48078 unsigned int msix_vector;
48079 unsigned int msi_vector;
48080 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
48081- struct access_method access;
48082+ struct access_method *access;
48083
48084 /* queue and queue Info */
48085 struct list_head reqQ;
48086@@ -381,19 +381,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
48087 }
48088
48089 static struct access_method SA5_access = {
48090- SA5_submit_command,
48091- SA5_intr_mask,
48092- SA5_fifo_full,
48093- SA5_intr_pending,
48094- SA5_completed,
48095+ .submit_command = SA5_submit_command,
48096+ .set_intr_mask = SA5_intr_mask,
48097+ .fifo_full = SA5_fifo_full,
48098+ .intr_pending = SA5_intr_pending,
48099+ .command_completed = SA5_completed,
48100 };
48101
48102 static struct access_method SA5_performant_access = {
48103- SA5_submit_command,
48104- SA5_performant_intr_mask,
48105- SA5_fifo_full,
48106- SA5_performant_intr_pending,
48107- SA5_performant_completed,
48108+ .submit_command = SA5_submit_command,
48109+ .set_intr_mask = SA5_performant_intr_mask,
48110+ .fifo_full = SA5_fifo_full,
48111+ .intr_pending = SA5_performant_intr_pending,
48112+ .command_completed = SA5_performant_completed,
48113 };
48114
48115 struct board_type {
48116diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
48117index 1b3a094..068e683 100644
48118--- a/drivers/scsi/libfc/fc_exch.c
48119+++ b/drivers/scsi/libfc/fc_exch.c
48120@@ -101,12 +101,12 @@ struct fc_exch_mgr {
48121 u16 pool_max_index;
48122
48123 struct {
48124- atomic_t no_free_exch;
48125- atomic_t no_free_exch_xid;
48126- atomic_t xid_not_found;
48127- atomic_t xid_busy;
48128- atomic_t seq_not_found;
48129- atomic_t non_bls_resp;
48130+ atomic_unchecked_t no_free_exch;
48131+ atomic_unchecked_t no_free_exch_xid;
48132+ atomic_unchecked_t xid_not_found;
48133+ atomic_unchecked_t xid_busy;
48134+ atomic_unchecked_t seq_not_found;
48135+ atomic_unchecked_t non_bls_resp;
48136 } stats;
48137 };
48138
48139@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
48140 /* allocate memory for exchange */
48141 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
48142 if (!ep) {
48143- atomic_inc(&mp->stats.no_free_exch);
48144+ atomic_inc_unchecked(&mp->stats.no_free_exch);
48145 goto out;
48146 }
48147 memset(ep, 0, sizeof(*ep));
48148@@ -874,7 +874,7 @@ out:
48149 return ep;
48150 err:
48151 spin_unlock_bh(&pool->lock);
48152- atomic_inc(&mp->stats.no_free_exch_xid);
48153+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
48154 mempool_free(ep, mp->ep_pool);
48155 return NULL;
48156 }
48157@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48158 xid = ntohs(fh->fh_ox_id); /* we originated exch */
48159 ep = fc_exch_find(mp, xid);
48160 if (!ep) {
48161- atomic_inc(&mp->stats.xid_not_found);
48162+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48163 reject = FC_RJT_OX_ID;
48164 goto out;
48165 }
48166@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48167 ep = fc_exch_find(mp, xid);
48168 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
48169 if (ep) {
48170- atomic_inc(&mp->stats.xid_busy);
48171+ atomic_inc_unchecked(&mp->stats.xid_busy);
48172 reject = FC_RJT_RX_ID;
48173 goto rel;
48174 }
48175@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48176 }
48177 xid = ep->xid; /* get our XID */
48178 } else if (!ep) {
48179- atomic_inc(&mp->stats.xid_not_found);
48180+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48181 reject = FC_RJT_RX_ID; /* XID not found */
48182 goto out;
48183 }
48184@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48185 } else {
48186 sp = &ep->seq;
48187 if (sp->id != fh->fh_seq_id) {
48188- atomic_inc(&mp->stats.seq_not_found);
48189+ atomic_inc_unchecked(&mp->stats.seq_not_found);
48190 if (f_ctl & FC_FC_END_SEQ) {
48191 /*
48192 * Update sequence_id based on incoming last
48193@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48194
48195 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
48196 if (!ep) {
48197- atomic_inc(&mp->stats.xid_not_found);
48198+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48199 goto out;
48200 }
48201 if (ep->esb_stat & ESB_ST_COMPLETE) {
48202- atomic_inc(&mp->stats.xid_not_found);
48203+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48204 goto rel;
48205 }
48206 if (ep->rxid == FC_XID_UNKNOWN)
48207 ep->rxid = ntohs(fh->fh_rx_id);
48208 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
48209- atomic_inc(&mp->stats.xid_not_found);
48210+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48211 goto rel;
48212 }
48213 if (ep->did != ntoh24(fh->fh_s_id) &&
48214 ep->did != FC_FID_FLOGI) {
48215- atomic_inc(&mp->stats.xid_not_found);
48216+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48217 goto rel;
48218 }
48219 sof = fr_sof(fp);
48220@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48221 sp->ssb_stat |= SSB_ST_RESP;
48222 sp->id = fh->fh_seq_id;
48223 } else if (sp->id != fh->fh_seq_id) {
48224- atomic_inc(&mp->stats.seq_not_found);
48225+ atomic_inc_unchecked(&mp->stats.seq_not_found);
48226 goto rel;
48227 }
48228
48229@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48230 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
48231
48232 if (!sp)
48233- atomic_inc(&mp->stats.xid_not_found);
48234+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48235 else
48236- atomic_inc(&mp->stats.non_bls_resp);
48237+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
48238
48239 fc_frame_free(fp);
48240 }
48241@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
48242
48243 list_for_each_entry(ema, &lport->ema_list, ema_list) {
48244 mp = ema->mp;
48245- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
48246+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
48247 st->fc_no_free_exch_xid +=
48248- atomic_read(&mp->stats.no_free_exch_xid);
48249- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
48250- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
48251- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
48252- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
48253+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
48254+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
48255+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
48256+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
48257+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
48258 }
48259 }
48260 EXPORT_SYMBOL(fc_exch_update_stats);
48261diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
48262index d289583..b745eec 100644
48263--- a/drivers/scsi/libsas/sas_ata.c
48264+++ b/drivers/scsi/libsas/sas_ata.c
48265@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
48266 .postreset = ata_std_postreset,
48267 .error_handler = ata_std_error_handler,
48268 .post_internal_cmd = sas_ata_post_internal,
48269- .qc_defer = ata_std_qc_defer,
48270+ .qc_defer = ata_std_qc_defer,
48271 .qc_prep = ata_noop_qc_prep,
48272 .qc_issue = sas_ata_qc_issue,
48273 .qc_fill_rtf = sas_ata_qc_fill_rtf,
48274diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
48275index 4e1b75c..0bbdfa9 100644
48276--- a/drivers/scsi/lpfc/lpfc.h
48277+++ b/drivers/scsi/lpfc/lpfc.h
48278@@ -432,7 +432,7 @@ struct lpfc_vport {
48279 struct dentry *debug_nodelist;
48280 struct dentry *vport_debugfs_root;
48281 struct lpfc_debugfs_trc *disc_trc;
48282- atomic_t disc_trc_cnt;
48283+ atomic_unchecked_t disc_trc_cnt;
48284 #endif
48285 uint8_t stat_data_enabled;
48286 uint8_t stat_data_blocked;
48287@@ -865,8 +865,8 @@ struct lpfc_hba {
48288 struct timer_list fabric_block_timer;
48289 unsigned long bit_flags;
48290 #define FABRIC_COMANDS_BLOCKED 0
48291- atomic_t num_rsrc_err;
48292- atomic_t num_cmd_success;
48293+ atomic_unchecked_t num_rsrc_err;
48294+ atomic_unchecked_t num_cmd_success;
48295 unsigned long last_rsrc_error_time;
48296 unsigned long last_ramp_down_time;
48297 unsigned long last_ramp_up_time;
48298@@ -902,7 +902,7 @@ struct lpfc_hba {
48299
48300 struct dentry *debug_slow_ring_trc;
48301 struct lpfc_debugfs_trc *slow_ring_trc;
48302- atomic_t slow_ring_trc_cnt;
48303+ atomic_unchecked_t slow_ring_trc_cnt;
48304 /* iDiag debugfs sub-directory */
48305 struct dentry *idiag_root;
48306 struct dentry *idiag_pci_cfg;
48307diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
48308index 60084e6..0e2e700 100644
48309--- a/drivers/scsi/lpfc/lpfc_debugfs.c
48310+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
48311@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
48312
48313 #include <linux/debugfs.h>
48314
48315-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
48316+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
48317 static unsigned long lpfc_debugfs_start_time = 0L;
48318
48319 /* iDiag */
48320@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
48321 lpfc_debugfs_enable = 0;
48322
48323 len = 0;
48324- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
48325+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
48326 (lpfc_debugfs_max_disc_trc - 1);
48327 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
48328 dtp = vport->disc_trc + i;
48329@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
48330 lpfc_debugfs_enable = 0;
48331
48332 len = 0;
48333- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
48334+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
48335 (lpfc_debugfs_max_slow_ring_trc - 1);
48336 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
48337 dtp = phba->slow_ring_trc + i;
48338@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
48339 !vport || !vport->disc_trc)
48340 return;
48341
48342- index = atomic_inc_return(&vport->disc_trc_cnt) &
48343+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
48344 (lpfc_debugfs_max_disc_trc - 1);
48345 dtp = vport->disc_trc + index;
48346 dtp->fmt = fmt;
48347 dtp->data1 = data1;
48348 dtp->data2 = data2;
48349 dtp->data3 = data3;
48350- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
48351+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
48352 dtp->jif = jiffies;
48353 #endif
48354 return;
48355@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
48356 !phba || !phba->slow_ring_trc)
48357 return;
48358
48359- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
48360+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
48361 (lpfc_debugfs_max_slow_ring_trc - 1);
48362 dtp = phba->slow_ring_trc + index;
48363 dtp->fmt = fmt;
48364 dtp->data1 = data1;
48365 dtp->data2 = data2;
48366 dtp->data3 = data3;
48367- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
48368+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
48369 dtp->jif = jiffies;
48370 #endif
48371 return;
48372@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
48373 "slow_ring buffer\n");
48374 goto debug_failed;
48375 }
48376- atomic_set(&phba->slow_ring_trc_cnt, 0);
48377+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
48378 memset(phba->slow_ring_trc, 0,
48379 (sizeof(struct lpfc_debugfs_trc) *
48380 lpfc_debugfs_max_slow_ring_trc));
48381@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
48382 "buffer\n");
48383 goto debug_failed;
48384 }
48385- atomic_set(&vport->disc_trc_cnt, 0);
48386+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
48387
48388 snprintf(name, sizeof(name), "discovery_trace");
48389 vport->debug_disc_trc =
48390diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
48391index 68c94cc..8c27be5 100644
48392--- a/drivers/scsi/lpfc/lpfc_init.c
48393+++ b/drivers/scsi/lpfc/lpfc_init.c
48394@@ -10949,8 +10949,10 @@ lpfc_init(void)
48395 "misc_register returned with status %d", error);
48396
48397 if (lpfc_enable_npiv) {
48398- lpfc_transport_functions.vport_create = lpfc_vport_create;
48399- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
48400+ pax_open_kernel();
48401+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
48402+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
48403+ pax_close_kernel();
48404 }
48405 lpfc_transport_template =
48406 fc_attach_transport(&lpfc_transport_functions);
48407diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
48408index b2ede05..aaf482ca 100644
48409--- a/drivers/scsi/lpfc/lpfc_scsi.c
48410+++ b/drivers/scsi/lpfc/lpfc_scsi.c
48411@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
48412 uint32_t evt_posted;
48413
48414 spin_lock_irqsave(&phba->hbalock, flags);
48415- atomic_inc(&phba->num_rsrc_err);
48416+ atomic_inc_unchecked(&phba->num_rsrc_err);
48417 phba->last_rsrc_error_time = jiffies;
48418
48419 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
48420@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
48421 unsigned long flags;
48422 struct lpfc_hba *phba = vport->phba;
48423 uint32_t evt_posted;
48424- atomic_inc(&phba->num_cmd_success);
48425+ atomic_inc_unchecked(&phba->num_cmd_success);
48426
48427 if (vport->cfg_lun_queue_depth <= queue_depth)
48428 return;
48429@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
48430 unsigned long num_rsrc_err, num_cmd_success;
48431 int i;
48432
48433- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
48434- num_cmd_success = atomic_read(&phba->num_cmd_success);
48435+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
48436+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
48437
48438 /*
48439 * The error and success command counters are global per
48440@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
48441 }
48442 }
48443 lpfc_destroy_vport_work_array(phba, vports);
48444- atomic_set(&phba->num_rsrc_err, 0);
48445- atomic_set(&phba->num_cmd_success, 0);
48446+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
48447+ atomic_set_unchecked(&phba->num_cmd_success, 0);
48448 }
48449
48450 /**
48451@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
48452 }
48453 }
48454 lpfc_destroy_vport_work_array(phba, vports);
48455- atomic_set(&phba->num_rsrc_err, 0);
48456- atomic_set(&phba->num_cmd_success, 0);
48457+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
48458+ atomic_set_unchecked(&phba->num_cmd_success, 0);
48459 }
48460
48461 /**
48462diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
48463index 7f0af4f..193ac3e 100644
48464--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
48465+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
48466@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
48467 {
48468 struct scsi_device *sdev = to_scsi_device(dev);
48469 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
48470- static struct _raid_device *raid_device;
48471+ struct _raid_device *raid_device;
48472 unsigned long flags;
48473 Mpi2RaidVolPage0_t vol_pg0;
48474 Mpi2ConfigReply_t mpi_reply;
48475@@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
48476 {
48477 struct scsi_device *sdev = to_scsi_device(dev);
48478 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
48479- static struct _raid_device *raid_device;
48480+ struct _raid_device *raid_device;
48481 unsigned long flags;
48482 Mpi2RaidVolPage0_t vol_pg0;
48483 Mpi2ConfigReply_t mpi_reply;
48484@@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
48485 struct fw_event_work *fw_event)
48486 {
48487 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
48488- static struct _raid_device *raid_device;
48489+ struct _raid_device *raid_device;
48490 unsigned long flags;
48491 u16 handle;
48492
48493@@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
48494 u64 sas_address;
48495 struct _sas_device *sas_device;
48496 struct _sas_node *expander_device;
48497- static struct _raid_device *raid_device;
48498+ struct _raid_device *raid_device;
48499 u8 retry_count;
48500 unsigned long flags;
48501
48502diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
48503index be8ce54..94ed33a 100644
48504--- a/drivers/scsi/pmcraid.c
48505+++ b/drivers/scsi/pmcraid.c
48506@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
48507 res->scsi_dev = scsi_dev;
48508 scsi_dev->hostdata = res;
48509 res->change_detected = 0;
48510- atomic_set(&res->read_failures, 0);
48511- atomic_set(&res->write_failures, 0);
48512+ atomic_set_unchecked(&res->read_failures, 0);
48513+ atomic_set_unchecked(&res->write_failures, 0);
48514 rc = 0;
48515 }
48516 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
48517@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
48518
48519 /* If this was a SCSI read/write command keep count of errors */
48520 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
48521- atomic_inc(&res->read_failures);
48522+ atomic_inc_unchecked(&res->read_failures);
48523 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
48524- atomic_inc(&res->write_failures);
48525+ atomic_inc_unchecked(&res->write_failures);
48526
48527 if (!RES_IS_GSCSI(res->cfg_entry) &&
48528 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
48529@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
48530 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
48531 * hrrq_id assigned here in queuecommand
48532 */
48533- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
48534+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
48535 pinstance->num_hrrq;
48536 cmd->cmd_done = pmcraid_io_done;
48537
48538@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
48539 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
48540 * hrrq_id assigned here in queuecommand
48541 */
48542- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
48543+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
48544 pinstance->num_hrrq;
48545
48546 if (request_size) {
48547@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
48548
48549 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
48550 /* add resources only after host is added into system */
48551- if (!atomic_read(&pinstance->expose_resources))
48552+ if (!atomic_read_unchecked(&pinstance->expose_resources))
48553 return;
48554
48555 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
48556@@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
48557 init_waitqueue_head(&pinstance->reset_wait_q);
48558
48559 atomic_set(&pinstance->outstanding_cmds, 0);
48560- atomic_set(&pinstance->last_message_id, 0);
48561- atomic_set(&pinstance->expose_resources, 0);
48562+ atomic_set_unchecked(&pinstance->last_message_id, 0);
48563+ atomic_set_unchecked(&pinstance->expose_resources, 0);
48564
48565 INIT_LIST_HEAD(&pinstance->free_res_q);
48566 INIT_LIST_HEAD(&pinstance->used_res_q);
48567@@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
48568 /* Schedule worker thread to handle CCN and take care of adding and
48569 * removing devices to OS
48570 */
48571- atomic_set(&pinstance->expose_resources, 1);
48572+ atomic_set_unchecked(&pinstance->expose_resources, 1);
48573 schedule_work(&pinstance->worker_q);
48574 return rc;
48575
48576diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
48577index e1d150f..6c6df44 100644
48578--- a/drivers/scsi/pmcraid.h
48579+++ b/drivers/scsi/pmcraid.h
48580@@ -748,7 +748,7 @@ struct pmcraid_instance {
48581 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
48582
48583 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
48584- atomic_t last_message_id;
48585+ atomic_unchecked_t last_message_id;
48586
48587 /* configuration table */
48588 struct pmcraid_config_table *cfg_table;
48589@@ -777,7 +777,7 @@ struct pmcraid_instance {
48590 atomic_t outstanding_cmds;
48591
48592 /* should add/delete resources to mid-layer now ?*/
48593- atomic_t expose_resources;
48594+ atomic_unchecked_t expose_resources;
48595
48596
48597
48598@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
48599 struct pmcraid_config_table_entry_ext cfg_entry_ext;
48600 };
48601 struct scsi_device *scsi_dev; /* Link scsi_device structure */
48602- atomic_t read_failures; /* count of failed READ commands */
48603- atomic_t write_failures; /* count of failed WRITE commands */
48604+ atomic_unchecked_t read_failures; /* count of failed READ commands */
48605+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
48606
48607 /* To indicate add/delete/modify during CCN */
48608 u8 change_detected;
48609diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
48610index 5f174b8..98d32b0 100644
48611--- a/drivers/scsi/qla2xxx/qla_attr.c
48612+++ b/drivers/scsi/qla2xxx/qla_attr.c
48613@@ -2040,7 +2040,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
48614 return 0;
48615 }
48616
48617-struct fc_function_template qla2xxx_transport_functions = {
48618+fc_function_template_no_const qla2xxx_transport_functions = {
48619
48620 .show_host_node_name = 1,
48621 .show_host_port_name = 1,
48622@@ -2088,7 +2088,7 @@ struct fc_function_template qla2xxx_transport_functions = {
48623 .bsg_timeout = qla24xx_bsg_timeout,
48624 };
48625
48626-struct fc_function_template qla2xxx_transport_vport_functions = {
48627+fc_function_template_no_const qla2xxx_transport_vport_functions = {
48628
48629 .show_host_node_name = 1,
48630 .show_host_port_name = 1,
48631diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
48632index 4446bf5..9a3574d 100644
48633--- a/drivers/scsi/qla2xxx/qla_gbl.h
48634+++ b/drivers/scsi/qla2xxx/qla_gbl.h
48635@@ -538,8 +538,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
48636 struct device_attribute;
48637 extern struct device_attribute *qla2x00_host_attrs[];
48638 struct fc_function_template;
48639-extern struct fc_function_template qla2xxx_transport_functions;
48640-extern struct fc_function_template qla2xxx_transport_vport_functions;
48641+extern fc_function_template_no_const qla2xxx_transport_functions;
48642+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
48643 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
48644 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
48645 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
48646diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
48647index 52be35e..b933907 100644
48648--- a/drivers/scsi/qla2xxx/qla_os.c
48649+++ b/drivers/scsi/qla2xxx/qla_os.c
48650@@ -1568,8 +1568,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
48651 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
48652 /* Ok, a 64bit DMA mask is applicable. */
48653 ha->flags.enable_64bit_addressing = 1;
48654- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
48655- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
48656+ pax_open_kernel();
48657+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
48658+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
48659+ pax_close_kernel();
48660 return;
48661 }
48662 }
48663diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
48664index 084d1fd..9f939eb 100644
48665--- a/drivers/scsi/qla4xxx/ql4_def.h
48666+++ b/drivers/scsi/qla4xxx/ql4_def.h
48667@@ -296,7 +296,7 @@ struct ddb_entry {
48668 * (4000 only) */
48669 atomic_t relogin_timer; /* Max Time to wait for
48670 * relogin to complete */
48671- atomic_t relogin_retry_count; /* Num of times relogin has been
48672+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
48673 * retried */
48674 uint32_t default_time2wait; /* Default Min time between
48675 * relogins (+aens) */
48676diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
48677index cf174a4..128a420 100644
48678--- a/drivers/scsi/qla4xxx/ql4_os.c
48679+++ b/drivers/scsi/qla4xxx/ql4_os.c
48680@@ -3311,12 +3311,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
48681 */
48682 if (!iscsi_is_session_online(cls_sess)) {
48683 /* Reset retry relogin timer */
48684- atomic_inc(&ddb_entry->relogin_retry_count);
48685+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
48686 DEBUG2(ql4_printk(KERN_INFO, ha,
48687 "%s: index[%d] relogin timed out-retrying"
48688 " relogin (%d), retry (%d)\n", __func__,
48689 ddb_entry->fw_ddb_index,
48690- atomic_read(&ddb_entry->relogin_retry_count),
48691+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
48692 ddb_entry->default_time2wait + 4));
48693 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
48694 atomic_set(&ddb_entry->retry_relogin_timer,
48695@@ -5458,7 +5458,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
48696
48697 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
48698 atomic_set(&ddb_entry->relogin_timer, 0);
48699- atomic_set(&ddb_entry->relogin_retry_count, 0);
48700+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
48701 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
48702 ddb_entry->default_relogin_timeout =
48703 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
48704diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
48705index fe0bcb1..c9255be 100644
48706--- a/drivers/scsi/scsi.c
48707+++ b/drivers/scsi/scsi.c
48708@@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
48709 struct Scsi_Host *host = cmd->device->host;
48710 int rtn = 0;
48711
48712- atomic_inc(&cmd->device->iorequest_cnt);
48713+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
48714
48715 /* check if the device is still usable */
48716 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
48717diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
48718index 7bd7f0d..44147bf 100644
48719--- a/drivers/scsi/scsi_lib.c
48720+++ b/drivers/scsi/scsi_lib.c
48721@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
48722 shost = sdev->host;
48723 scsi_init_cmd_errh(cmd);
48724 cmd->result = DID_NO_CONNECT << 16;
48725- atomic_inc(&cmd->device->iorequest_cnt);
48726+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
48727
48728 /*
48729 * SCSI request completion path will do scsi_device_unbusy(),
48730@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
48731
48732 INIT_LIST_HEAD(&cmd->eh_entry);
48733
48734- atomic_inc(&cmd->device->iodone_cnt);
48735+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
48736 if (cmd->result)
48737- atomic_inc(&cmd->device->ioerr_cnt);
48738+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
48739
48740 disposition = scsi_decide_disposition(cmd);
48741 if (disposition != SUCCESS &&
48742diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
48743index 8ff62c2..693b6f7 100644
48744--- a/drivers/scsi/scsi_sysfs.c
48745+++ b/drivers/scsi/scsi_sysfs.c
48746@@ -725,7 +725,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
48747 char *buf) \
48748 { \
48749 struct scsi_device *sdev = to_scsi_device(dev); \
48750- unsigned long long count = atomic_read(&sdev->field); \
48751+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
48752 return snprintf(buf, 20, "0x%llx\n", count); \
48753 } \
48754 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
48755diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
48756index 84a1fdf..693b0d6 100644
48757--- a/drivers/scsi/scsi_tgt_lib.c
48758+++ b/drivers/scsi/scsi_tgt_lib.c
48759@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
48760 int err;
48761
48762 dprintk("%lx %u\n", uaddr, len);
48763- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
48764+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
48765 if (err) {
48766 /*
48767 * TODO: need to fixup sg_tablesize, max_segment_size,
48768diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
48769index 4628fd5..a94a1c2 100644
48770--- a/drivers/scsi/scsi_transport_fc.c
48771+++ b/drivers/scsi/scsi_transport_fc.c
48772@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
48773 * Netlink Infrastructure
48774 */
48775
48776-static atomic_t fc_event_seq;
48777+static atomic_unchecked_t fc_event_seq;
48778
48779 /**
48780 * fc_get_event_number - Obtain the next sequential FC event number
48781@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
48782 u32
48783 fc_get_event_number(void)
48784 {
48785- return atomic_add_return(1, &fc_event_seq);
48786+ return atomic_add_return_unchecked(1, &fc_event_seq);
48787 }
48788 EXPORT_SYMBOL(fc_get_event_number);
48789
48790@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
48791 {
48792 int error;
48793
48794- atomic_set(&fc_event_seq, 0);
48795+ atomic_set_unchecked(&fc_event_seq, 0);
48796
48797 error = transport_class_register(&fc_host_class);
48798 if (error)
48799@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
48800 char *cp;
48801
48802 *val = simple_strtoul(buf, &cp, 0);
48803- if ((*cp && (*cp != '\n')) || (*val < 0))
48804+ if (*cp && (*cp != '\n'))
48805 return -EINVAL;
48806 /*
48807 * Check for overflow; dev_loss_tmo is u32
48808diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
48809index 63a6ca4..5d5cadd 100644
48810--- a/drivers/scsi/scsi_transport_iscsi.c
48811+++ b/drivers/scsi/scsi_transport_iscsi.c
48812@@ -79,7 +79,7 @@ struct iscsi_internal {
48813 struct transport_container session_cont;
48814 };
48815
48816-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
48817+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
48818 static struct workqueue_struct *iscsi_eh_timer_workq;
48819
48820 static DEFINE_IDA(iscsi_sess_ida);
48821@@ -1737,7 +1737,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
48822 int err;
48823
48824 ihost = shost->shost_data;
48825- session->sid = atomic_add_return(1, &iscsi_session_nr);
48826+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
48827
48828 if (target_id == ISCSI_MAX_TARGET) {
48829 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
48830@@ -4103,7 +4103,7 @@ static __init int iscsi_transport_init(void)
48831 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
48832 ISCSI_TRANSPORT_VERSION);
48833
48834- atomic_set(&iscsi_session_nr, 0);
48835+ atomic_set_unchecked(&iscsi_session_nr, 0);
48836
48837 err = class_register(&iscsi_transport_class);
48838 if (err)
48839diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
48840index 2700a5a..752ec38 100644
48841--- a/drivers/scsi/scsi_transport_srp.c
48842+++ b/drivers/scsi/scsi_transport_srp.c
48843@@ -36,7 +36,7 @@
48844 #include "scsi_transport_srp_internal.h"
48845
48846 struct srp_host_attrs {
48847- atomic_t next_port_id;
48848+ atomic_unchecked_t next_port_id;
48849 };
48850 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
48851
48852@@ -94,7 +94,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
48853 struct Scsi_Host *shost = dev_to_shost(dev);
48854 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
48855
48856- atomic_set(&srp_host->next_port_id, 0);
48857+ atomic_set_unchecked(&srp_host->next_port_id, 0);
48858 return 0;
48859 }
48860
48861@@ -730,7 +730,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
48862 rport_fast_io_fail_timedout);
48863 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
48864
48865- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
48866+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
48867 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
48868
48869 transport_setup_device(&rport->dev);
48870diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
48871index 69725f7..03aaee1 100644
48872--- a/drivers/scsi/sd.c
48873+++ b/drivers/scsi/sd.c
48874@@ -2964,7 +2964,7 @@ static int sd_probe(struct device *dev)
48875 sdkp->disk = gd;
48876 sdkp->index = index;
48877 atomic_set(&sdkp->openers, 0);
48878- atomic_set(&sdkp->device->ioerr_cnt, 0);
48879+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
48880
48881 if (!sdp->request_queue->rq_timeout) {
48882 if (sdp->type != TYPE_MOD)
48883diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
48884index df5e961..df6b97f 100644
48885--- a/drivers/scsi/sg.c
48886+++ b/drivers/scsi/sg.c
48887@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
48888 sdp->disk->disk_name,
48889 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
48890 NULL,
48891- (char *)arg);
48892+ (char __user *)arg);
48893 case BLKTRACESTART:
48894 return blk_trace_startstop(sdp->device->request_queue, 1);
48895 case BLKTRACESTOP:
48896diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
48897index 349ebba..ff2a249 100644
48898--- a/drivers/spi/spi.c
48899+++ b/drivers/spi/spi.c
48900@@ -1945,7 +1945,7 @@ int spi_bus_unlock(struct spi_master *master)
48901 EXPORT_SYMBOL_GPL(spi_bus_unlock);
48902
48903 /* portable code must never pass more than 32 bytes */
48904-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
48905+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
48906
48907 static u8 *buf;
48908
48909diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
48910index 2c61783..4d49e4e 100644
48911--- a/drivers/staging/android/timed_output.c
48912+++ b/drivers/staging/android/timed_output.c
48913@@ -25,7 +25,7 @@
48914 #include "timed_output.h"
48915
48916 static struct class *timed_output_class;
48917-static atomic_t device_count;
48918+static atomic_unchecked_t device_count;
48919
48920 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
48921 char *buf)
48922@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
48923 timed_output_class = class_create(THIS_MODULE, "timed_output");
48924 if (IS_ERR(timed_output_class))
48925 return PTR_ERR(timed_output_class);
48926- atomic_set(&device_count, 0);
48927+ atomic_set_unchecked(&device_count, 0);
48928 timed_output_class->dev_groups = timed_output_groups;
48929 }
48930
48931@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
48932 if (ret < 0)
48933 return ret;
48934
48935- tdev->index = atomic_inc_return(&device_count);
48936+ tdev->index = atomic_inc_return_unchecked(&device_count);
48937 tdev->dev = device_create(timed_output_class, NULL,
48938 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
48939 if (IS_ERR(tdev->dev))
48940diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
48941index c0f7cd7..5424212 100644
48942--- a/drivers/staging/gdm724x/gdm_tty.c
48943+++ b/drivers/staging/gdm724x/gdm_tty.c
48944@@ -45,7 +45,7 @@
48945 #define gdm_tty_send_control(n, r, v, d, l) (\
48946 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
48947
48948-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
48949+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
48950
48951 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
48952 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
48953diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
48954index b7613c8..c302392 100644
48955--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
48956+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
48957@@ -487,13 +487,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
48958 return 0;
48959 }
48960
48961-sfw_test_client_ops_t brw_test_client;
48962-void brw_init_test_client(void)
48963-{
48964- brw_test_client.tso_init = brw_client_init;
48965- brw_test_client.tso_fini = brw_client_fini;
48966- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
48967- brw_test_client.tso_done_rpc = brw_client_done_rpc;
48968+sfw_test_client_ops_t brw_test_client = {
48969+ .tso_init = brw_client_init,
48970+ .tso_fini = brw_client_fini,
48971+ .tso_prep_rpc = brw_client_prep_rpc,
48972+ .tso_done_rpc = brw_client_done_rpc,
48973 };
48974
48975 srpc_service_t brw_test_service;
48976diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
48977index 483c785..e1a2a7b 100644
48978--- a/drivers/staging/lustre/lnet/selftest/framework.c
48979+++ b/drivers/staging/lustre/lnet/selftest/framework.c
48980@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
48981
48982 extern sfw_test_client_ops_t ping_test_client;
48983 extern srpc_service_t ping_test_service;
48984-extern void ping_init_test_client(void);
48985 extern void ping_init_test_service(void);
48986
48987 extern sfw_test_client_ops_t brw_test_client;
48988 extern srpc_service_t brw_test_service;
48989-extern void brw_init_test_client(void);
48990 extern void brw_init_test_service(void);
48991
48992
48993@@ -1684,12 +1682,10 @@ sfw_startup (void)
48994 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
48995 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
48996
48997- brw_init_test_client();
48998 brw_init_test_service();
48999 rc = sfw_register_test(&brw_test_service, &brw_test_client);
49000 LASSERT (rc == 0);
49001
49002- ping_init_test_client();
49003 ping_init_test_service();
49004 rc = sfw_register_test(&ping_test_service, &ping_test_client);
49005 LASSERT (rc == 0);
49006diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
49007index f0f9194..b589047 100644
49008--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
49009+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
49010@@ -210,14 +210,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
49011 return 0;
49012 }
49013
49014-sfw_test_client_ops_t ping_test_client;
49015-void ping_init_test_client(void)
49016-{
49017- ping_test_client.tso_init = ping_client_init;
49018- ping_test_client.tso_fini = ping_client_fini;
49019- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
49020- ping_test_client.tso_done_rpc = ping_client_done_rpc;
49021-}
49022+sfw_test_client_ops_t ping_test_client = {
49023+ .tso_init = ping_client_init,
49024+ .tso_fini = ping_client_fini,
49025+ .tso_prep_rpc = ping_client_prep_rpc,
49026+ .tso_done_rpc = ping_client_done_rpc,
49027+};
49028
49029 srpc_service_t ping_test_service;
49030 void ping_init_test_service(void)
49031diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49032index bc2b82f..67fd598 100644
49033--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
49034+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49035@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
49036 ldlm_completion_callback lcs_completion;
49037 ldlm_blocking_callback lcs_blocking;
49038 ldlm_glimpse_callback lcs_glimpse;
49039-};
49040+} __no_const;
49041
49042 /* ldlm_lockd.c */
49043 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
49044diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
49045index d0aea15..7af68e1 100644
49046--- a/drivers/staging/lustre/lustre/include/obd.h
49047+++ b/drivers/staging/lustre/lustre/include/obd.h
49048@@ -1417,7 +1417,7 @@ struct md_ops {
49049 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
49050 * wrapper function in include/linux/obd_class.h.
49051 */
49052-};
49053+} __no_const;
49054
49055 struct lsm_operations {
49056 void (*lsm_free)(struct lov_stripe_md *);
49057diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49058index 39fcdac..222780f 100644
49059--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49060+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49061@@ -249,7 +249,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
49062 int added = (mode == LCK_NL);
49063 int overlaps = 0;
49064 int splitted = 0;
49065- const struct ldlm_callback_suite null_cbs = { NULL };
49066+ const struct ldlm_callback_suite null_cbs = { };
49067 int rc;
49068
49069 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
49070diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49071index fc6c977..df1f956 100644
49072--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49073+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49074@@ -219,7 +219,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
49075 int LL_PROC_PROTO(proc_console_max_delay_cs)
49076 {
49077 int rc, max_delay_cs;
49078- ctl_table_t dummy = *table;
49079+ ctl_table_no_const dummy = *table;
49080 cfs_duration_t d;
49081
49082 dummy.data = &max_delay_cs;
49083@@ -250,7 +250,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
49084 int LL_PROC_PROTO(proc_console_min_delay_cs)
49085 {
49086 int rc, min_delay_cs;
49087- ctl_table_t dummy = *table;
49088+ ctl_table_no_const dummy = *table;
49089 cfs_duration_t d;
49090
49091 dummy.data = &min_delay_cs;
49092@@ -281,7 +281,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
49093 int LL_PROC_PROTO(proc_console_backoff)
49094 {
49095 int rc, backoff;
49096- ctl_table_t dummy = *table;
49097+ ctl_table_no_const dummy = *table;
49098
49099 dummy.data = &backoff;
49100 dummy.proc_handler = &proc_dointvec;
49101diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
49102index f3108c7..cd4f9da 100644
49103--- a/drivers/staging/lustre/lustre/libcfs/module.c
49104+++ b/drivers/staging/lustre/lustre/libcfs/module.c
49105@@ -348,11 +348,11 @@ out:
49106
49107
49108 struct cfs_psdev_ops libcfs_psdev_ops = {
49109- libcfs_psdev_open,
49110- libcfs_psdev_release,
49111- NULL,
49112- NULL,
49113- libcfs_ioctl
49114+ .p_open = libcfs_psdev_open,
49115+ .p_close = libcfs_psdev_release,
49116+ .p_read = NULL,
49117+ .p_write = NULL,
49118+ .p_ioctl = libcfs_ioctl
49119 };
49120
49121 extern int insert_proc(void);
49122diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
49123index 3675020..e80d92c 100644
49124--- a/drivers/staging/media/solo6x10/solo6x10-core.c
49125+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
49126@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
49127
49128 static int solo_sysfs_init(struct solo_dev *solo_dev)
49129 {
49130- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
49131+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
49132 struct device *dev = &solo_dev->dev;
49133 const char *driver;
49134 int i;
49135diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
49136index 1db18c7..35e6afc 100644
49137--- a/drivers/staging/media/solo6x10/solo6x10-g723.c
49138+++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
49139@@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
49140
49141 int solo_g723_init(struct solo_dev *solo_dev)
49142 {
49143- static struct snd_device_ops ops = { NULL };
49144+ static struct snd_device_ops ops = { };
49145 struct snd_card *card;
49146 struct snd_kcontrol_new kctl;
49147 char name[32];
49148diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49149index 7f2f247..d999137 100644
49150--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
49151+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49152@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
49153
49154 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
49155 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
49156- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
49157+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
49158 if (p2m_id < 0)
49159 p2m_id = -p2m_id;
49160 }
49161diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
49162index f1bbb8c..a73eaba 100644
49163--- a/drivers/staging/media/solo6x10/solo6x10.h
49164+++ b/drivers/staging/media/solo6x10/solo6x10.h
49165@@ -237,7 +237,7 @@ struct solo_dev {
49166
49167 /* P2M DMA Engine */
49168 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
49169- atomic_t p2m_count;
49170+ atomic_unchecked_t p2m_count;
49171 int p2m_jiffies;
49172 unsigned int p2m_timeouts;
49173
49174diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
49175index 0315f60..2ecae10 100644
49176--- a/drivers/staging/octeon/ethernet-rx.c
49177+++ b/drivers/staging/octeon/ethernet-rx.c
49178@@ -418,11 +418,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49179 /* Increment RX stats for virtual ports */
49180 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
49181 #ifdef CONFIG_64BIT
49182- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
49183- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
49184+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
49185+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
49186 #else
49187- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
49188- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
49189+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
49190+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
49191 #endif
49192 }
49193 netif_receive_skb(skb);
49194@@ -433,9 +433,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49195 dev->name);
49196 */
49197 #ifdef CONFIG_64BIT
49198- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
49199+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49200 #else
49201- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
49202+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
49203 #endif
49204 dev_kfree_skb_irq(skb);
49205 }
49206diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
49207index bd6ca71..8f0961e 100644
49208--- a/drivers/staging/octeon/ethernet.c
49209+++ b/drivers/staging/octeon/ethernet.c
49210@@ -254,11 +254,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
49211 * since the RX tasklet also increments it.
49212 */
49213 #ifdef CONFIG_64BIT
49214- atomic64_add(rx_status.dropped_packets,
49215- (atomic64_t *)&priv->stats.rx_dropped);
49216+ atomic64_add_unchecked(rx_status.dropped_packets,
49217+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49218 #else
49219- atomic_add(rx_status.dropped_packets,
49220- (atomic_t *)&priv->stats.rx_dropped);
49221+ atomic_add_unchecked(rx_status.dropped_packets,
49222+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
49223 #endif
49224 }
49225
49226diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
49227index 439c3c9..2d74293 100644
49228--- a/drivers/staging/rtl8188eu/include/hal_intf.h
49229+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
49230@@ -271,7 +271,7 @@ struct hal_ops {
49231 s32 (*c2h_handler)(struct adapter *padapter,
49232 struct c2h_evt_hdr *c2h_evt);
49233 c2h_id_filter c2h_id_filter_ccx;
49234-};
49235+} __no_const;
49236
49237 enum rt_eeprom_type {
49238 EEPROM_93C46,
49239diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
49240index eb6f0e5..e6a0958 100644
49241--- a/drivers/staging/rtl8188eu/include/rtw_io.h
49242+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
49243@@ -126,7 +126,7 @@ struct _io_ops {
49244 u32 (*_write_scsi)(struct intf_hdl *pintfhdl,u32 cnt, u8 *pmem);
49245 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
49246 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
49247-};
49248+} __no_const;
49249
49250 struct io_req {
49251 struct list_head list;
49252diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
49253index dc23395..cf7e9b1 100644
49254--- a/drivers/staging/rtl8712/rtl871x_io.h
49255+++ b/drivers/staging/rtl8712/rtl871x_io.h
49256@@ -108,7 +108,7 @@ struct _io_ops {
49257 u8 *pmem);
49258 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
49259 u8 *pmem);
49260-};
49261+} __no_const;
49262
49263 struct io_req {
49264 struct list_head list;
49265diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
49266index 1f5088b..0e59820 100644
49267--- a/drivers/staging/sbe-2t3e3/netdev.c
49268+++ b/drivers/staging/sbe-2t3e3/netdev.c
49269@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
49270 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
49271
49272 if (rlen)
49273- if (copy_to_user(data, &resp, rlen))
49274+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
49275 return -EFAULT;
49276
49277 return 0;
49278diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
49279index a863a98..d272795 100644
49280--- a/drivers/staging/usbip/vhci.h
49281+++ b/drivers/staging/usbip/vhci.h
49282@@ -83,7 +83,7 @@ struct vhci_hcd {
49283 unsigned resuming:1;
49284 unsigned long re_timeout;
49285
49286- atomic_t seqnum;
49287+ atomic_unchecked_t seqnum;
49288
49289 /*
49290 * NOTE:
49291diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
49292index e810ad5..931336f 100644
49293--- a/drivers/staging/usbip/vhci_hcd.c
49294+++ b/drivers/staging/usbip/vhci_hcd.c
49295@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
49296
49297 spin_lock(&vdev->priv_lock);
49298
49299- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
49300+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
49301 if (priv->seqnum == 0xffff)
49302 dev_info(&urb->dev->dev, "seqnum max\n");
49303
49304@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
49305 return -ENOMEM;
49306 }
49307
49308- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
49309+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
49310 if (unlink->seqnum == 0xffff)
49311 pr_info("seqnum max\n");
49312
49313@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
49314 vdev->rhport = rhport;
49315 }
49316
49317- atomic_set(&vhci->seqnum, 0);
49318+ atomic_set_unchecked(&vhci->seqnum, 0);
49319 spin_lock_init(&vhci->lock);
49320
49321 hcd->power_budget = 0; /* no limit */
49322diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
49323index d07fcb5..358e1e1 100644
49324--- a/drivers/staging/usbip/vhci_rx.c
49325+++ b/drivers/staging/usbip/vhci_rx.c
49326@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
49327 if (!urb) {
49328 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
49329 pr_info("max seqnum %d\n",
49330- atomic_read(&the_controller->seqnum));
49331+ atomic_read_unchecked(&the_controller->seqnum));
49332 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
49333 return;
49334 }
49335diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
49336index ab8b2ba..99184aa 100644
49337--- a/drivers/staging/vt6655/hostap.c
49338+++ b/drivers/staging/vt6655/hostap.c
49339@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
49340 *
49341 */
49342
49343+static net_device_ops_no_const apdev_netdev_ops;
49344+
49345 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
49346 {
49347 PSDevice apdev_priv;
49348 struct net_device *dev = pDevice->dev;
49349 int ret;
49350- const struct net_device_ops apdev_netdev_ops = {
49351- .ndo_start_xmit = pDevice->tx_80211,
49352- };
49353
49354 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
49355
49356@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
49357 *apdev_priv = *pDevice;
49358 eth_hw_addr_inherit(pDevice->apdev, dev);
49359
49360+ /* only half broken now */
49361+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
49362 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
49363
49364 pDevice->apdev->type = ARPHRD_IEEE80211;
49365diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
49366index 67ba48b..24e602f 100644
49367--- a/drivers/staging/vt6656/hostap.c
49368+++ b/drivers/staging/vt6656/hostap.c
49369@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
49370 *
49371 */
49372
49373+static net_device_ops_no_const apdev_netdev_ops;
49374+
49375 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
49376 {
49377 struct vnt_private *apdev_priv;
49378 struct net_device *dev = pDevice->dev;
49379 int ret;
49380- const struct net_device_ops apdev_netdev_ops = {
49381- .ndo_start_xmit = pDevice->tx_80211,
49382- };
49383
49384 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
49385
49386@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
49387 *apdev_priv = *pDevice;
49388 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
49389
49390+ /* only half broken now */
49391+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
49392 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
49393
49394 pDevice->apdev->type = ARPHRD_IEEE80211;
49395diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
49396index 24884ca..26c8220 100644
49397--- a/drivers/target/sbp/sbp_target.c
49398+++ b/drivers/target/sbp/sbp_target.c
49399@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
49400
49401 #define SESSION_MAINTENANCE_INTERVAL HZ
49402
49403-static atomic_t login_id = ATOMIC_INIT(0);
49404+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
49405
49406 static void session_maintenance_work(struct work_struct *);
49407 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
49408@@ -444,7 +444,7 @@ static void sbp_management_request_login(
49409 login->lun = se_lun;
49410 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
49411 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
49412- login->login_id = atomic_inc_return(&login_id);
49413+ login->login_id = atomic_inc_return_unchecked(&login_id);
49414
49415 login->tgt_agt = sbp_target_agent_register(login);
49416 if (IS_ERR(login->tgt_agt)) {
49417diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
49418index d06de84..fd38c9b 100644
49419--- a/drivers/target/target_core_device.c
49420+++ b/drivers/target/target_core_device.c
49421@@ -1435,7 +1435,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
49422 spin_lock_init(&dev->se_tmr_lock);
49423 spin_lock_init(&dev->qf_cmd_lock);
49424 sema_init(&dev->caw_sem, 1);
49425- atomic_set(&dev->dev_ordered_id, 0);
49426+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
49427 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
49428 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
49429 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
49430diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
49431index 91953da..a842b90 100644
49432--- a/drivers/target/target_core_transport.c
49433+++ b/drivers/target/target_core_transport.c
49434@@ -1112,7 +1112,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
49435 * Used to determine when ORDERED commands should go from
49436 * Dormant to Active status.
49437 */
49438- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
49439+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
49440 smp_mb__after_atomic_inc();
49441 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
49442 cmd->se_ordered_id, cmd->sam_task_attr,
49443diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
49444index 33f83fe..d80f8e1 100644
49445--- a/drivers/tty/cyclades.c
49446+++ b/drivers/tty/cyclades.c
49447@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
49448 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
49449 info->port.count);
49450 #endif
49451- info->port.count++;
49452+ atomic_inc(&info->port.count);
49453 #ifdef CY_DEBUG_COUNT
49454 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
49455- current->pid, info->port.count);
49456+ current->pid, atomic_read(&info->port.count));
49457 #endif
49458
49459 /*
49460@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
49461 for (j = 0; j < cy_card[i].nports; j++) {
49462 info = &cy_card[i].ports[j];
49463
49464- if (info->port.count) {
49465+ if (atomic_read(&info->port.count)) {
49466 /* XXX is the ldisc num worth this? */
49467 struct tty_struct *tty;
49468 struct tty_ldisc *ld;
49469diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
49470index 9eba119..5070303 100644
49471--- a/drivers/tty/hvc/hvc_console.c
49472+++ b/drivers/tty/hvc/hvc_console.c
49473@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
49474
49475 spin_lock_irqsave(&hp->port.lock, flags);
49476 /* Check and then increment for fast path open. */
49477- if (hp->port.count++ > 0) {
49478+ if (atomic_inc_return(&hp->port.count) > 1) {
49479 spin_unlock_irqrestore(&hp->port.lock, flags);
49480 hvc_kick();
49481 return 0;
49482@@ -393,7 +393,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
49483
49484 spin_lock_irqsave(&hp->port.lock, flags);
49485
49486- if (--hp->port.count == 0) {
49487+ if (atomic_dec_return(&hp->port.count) == 0) {
49488 spin_unlock_irqrestore(&hp->port.lock, flags);
49489 /* We are done with the tty pointer now. */
49490 tty_port_tty_set(&hp->port, NULL);
49491@@ -415,9 +415,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
49492 */
49493 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
49494 } else {
49495- if (hp->port.count < 0)
49496+ if (atomic_read(&hp->port.count) < 0)
49497 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
49498- hp->vtermno, hp->port.count);
49499+ hp->vtermno, atomic_read(&hp->port.count));
49500 spin_unlock_irqrestore(&hp->port.lock, flags);
49501 }
49502 }
49503@@ -447,12 +447,12 @@ static void hvc_hangup(struct tty_struct *tty)
49504 * open->hangup case this can be called after the final close so prevent
49505 * that from happening for now.
49506 */
49507- if (hp->port.count <= 0) {
49508+ if (atomic_read(&hp->port.count) <= 0) {
49509 spin_unlock_irqrestore(&hp->port.lock, flags);
49510 return;
49511 }
49512
49513- hp->port.count = 0;
49514+ atomic_set(&hp->port.count, 0);
49515 spin_unlock_irqrestore(&hp->port.lock, flags);
49516 tty_port_tty_set(&hp->port, NULL);
49517
49518@@ -500,7 +500,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
49519 return -EPIPE;
49520
49521 /* FIXME what's this (unprotected) check for? */
49522- if (hp->port.count <= 0)
49523+ if (atomic_read(&hp->port.count) <= 0)
49524 return -EIO;
49525
49526 spin_lock_irqsave(&hp->lock, flags);
49527diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
49528index 81e939e..95ead10 100644
49529--- a/drivers/tty/hvc/hvcs.c
49530+++ b/drivers/tty/hvc/hvcs.c
49531@@ -83,6 +83,7 @@
49532 #include <asm/hvcserver.h>
49533 #include <asm/uaccess.h>
49534 #include <asm/vio.h>
49535+#include <asm/local.h>
49536
49537 /*
49538 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
49539@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
49540
49541 spin_lock_irqsave(&hvcsd->lock, flags);
49542
49543- if (hvcsd->port.count > 0) {
49544+ if (atomic_read(&hvcsd->port.count) > 0) {
49545 spin_unlock_irqrestore(&hvcsd->lock, flags);
49546 printk(KERN_INFO "HVCS: vterm state unchanged. "
49547 "The hvcs device node is still in use.\n");
49548@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
49549 }
49550 }
49551
49552- hvcsd->port.count = 0;
49553+ atomic_set(&hvcsd->port.count, 0);
49554 hvcsd->port.tty = tty;
49555 tty->driver_data = hvcsd;
49556
49557@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
49558 unsigned long flags;
49559
49560 spin_lock_irqsave(&hvcsd->lock, flags);
49561- hvcsd->port.count++;
49562+ atomic_inc(&hvcsd->port.count);
49563 hvcsd->todo_mask |= HVCS_SCHED_READ;
49564 spin_unlock_irqrestore(&hvcsd->lock, flags);
49565
49566@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
49567 hvcsd = tty->driver_data;
49568
49569 spin_lock_irqsave(&hvcsd->lock, flags);
49570- if (--hvcsd->port.count == 0) {
49571+ if (atomic_dec_and_test(&hvcsd->port.count)) {
49572
49573 vio_disable_interrupts(hvcsd->vdev);
49574
49575@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
49576
49577 free_irq(irq, hvcsd);
49578 return;
49579- } else if (hvcsd->port.count < 0) {
49580+ } else if (atomic_read(&hvcsd->port.count) < 0) {
49581 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
49582 " is missmanaged.\n",
49583- hvcsd->vdev->unit_address, hvcsd->port.count);
49584+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
49585 }
49586
49587 spin_unlock_irqrestore(&hvcsd->lock, flags);
49588@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
49589
49590 spin_lock_irqsave(&hvcsd->lock, flags);
49591 /* Preserve this so that we know how many kref refs to put */
49592- temp_open_count = hvcsd->port.count;
49593+ temp_open_count = atomic_read(&hvcsd->port.count);
49594
49595 /*
49596 * Don't kref put inside the spinlock because the destruction
49597@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
49598 tty->driver_data = NULL;
49599 hvcsd->port.tty = NULL;
49600
49601- hvcsd->port.count = 0;
49602+ atomic_set(&hvcsd->port.count, 0);
49603
49604 /* This will drop any buffered data on the floor which is OK in a hangup
49605 * scenario. */
49606@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
49607 * the middle of a write operation? This is a crummy place to do this
49608 * but we want to keep it all in the spinlock.
49609 */
49610- if (hvcsd->port.count <= 0) {
49611+ if (atomic_read(&hvcsd->port.count) <= 0) {
49612 spin_unlock_irqrestore(&hvcsd->lock, flags);
49613 return -ENODEV;
49614 }
49615@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
49616 {
49617 struct hvcs_struct *hvcsd = tty->driver_data;
49618
49619- if (!hvcsd || hvcsd->port.count <= 0)
49620+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
49621 return 0;
49622
49623 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
49624diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
49625index 4190199..48f2920 100644
49626--- a/drivers/tty/hvc/hvsi.c
49627+++ b/drivers/tty/hvc/hvsi.c
49628@@ -85,7 +85,7 @@ struct hvsi_struct {
49629 int n_outbuf;
49630 uint32_t vtermno;
49631 uint32_t virq;
49632- atomic_t seqno; /* HVSI packet sequence number */
49633+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
49634 uint16_t mctrl;
49635 uint8_t state; /* HVSI protocol state */
49636 uint8_t flags;
49637@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
49638
49639 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
49640 packet.hdr.len = sizeof(struct hvsi_query_response);
49641- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49642+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49643 packet.verb = VSV_SEND_VERSION_NUMBER;
49644 packet.u.version = HVSI_VERSION;
49645 packet.query_seqno = query_seqno+1;
49646@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
49647
49648 packet.hdr.type = VS_QUERY_PACKET_HEADER;
49649 packet.hdr.len = sizeof(struct hvsi_query);
49650- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49651+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49652 packet.verb = verb;
49653
49654 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
49655@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
49656 int wrote;
49657
49658 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
49659- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49660+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49661 packet.hdr.len = sizeof(struct hvsi_control);
49662 packet.verb = VSV_SET_MODEM_CTL;
49663 packet.mask = HVSI_TSDTR;
49664@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
49665 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
49666
49667 packet.hdr.type = VS_DATA_PACKET_HEADER;
49668- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49669+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49670 packet.hdr.len = count + sizeof(struct hvsi_header);
49671 memcpy(&packet.data, buf, count);
49672
49673@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
49674 struct hvsi_control packet __ALIGNED__;
49675
49676 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
49677- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49678+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49679 packet.hdr.len = 6;
49680 packet.verb = VSV_CLOSE_PROTOCOL;
49681
49682diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
49683index 347050e..14f8fbf 100644
49684--- a/drivers/tty/hvc/hvsi_lib.c
49685+++ b/drivers/tty/hvc/hvsi_lib.c
49686@@ -9,7 +9,7 @@
49687
49688 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
49689 {
49690- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
49691+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
49692
49693 /* Assumes that always succeeds, works in practice */
49694 return pv->put_chars(pv->termno, (char *)packet, packet->len);
49695@@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
49696
49697 /* Reset state */
49698 pv->established = 0;
49699- atomic_set(&pv->seqno, 0);
49700+ atomic_set_unchecked(&pv->seqno, 0);
49701
49702 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
49703
49704diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
49705index 8fd72ff..34a0bed 100644
49706--- a/drivers/tty/ipwireless/tty.c
49707+++ b/drivers/tty/ipwireless/tty.c
49708@@ -29,6 +29,7 @@
49709 #include <linux/tty_driver.h>
49710 #include <linux/tty_flip.h>
49711 #include <linux/uaccess.h>
49712+#include <asm/local.h>
49713
49714 #include "tty.h"
49715 #include "network.h"
49716@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
49717 mutex_unlock(&tty->ipw_tty_mutex);
49718 return -ENODEV;
49719 }
49720- if (tty->port.count == 0)
49721+ if (atomic_read(&tty->port.count) == 0)
49722 tty->tx_bytes_queued = 0;
49723
49724- tty->port.count++;
49725+ atomic_inc(&tty->port.count);
49726
49727 tty->port.tty = linux_tty;
49728 linux_tty->driver_data = tty;
49729@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
49730
49731 static void do_ipw_close(struct ipw_tty *tty)
49732 {
49733- tty->port.count--;
49734-
49735- if (tty->port.count == 0) {
49736+ if (atomic_dec_return(&tty->port.count) == 0) {
49737 struct tty_struct *linux_tty = tty->port.tty;
49738
49739 if (linux_tty != NULL) {
49740@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
49741 return;
49742
49743 mutex_lock(&tty->ipw_tty_mutex);
49744- if (tty->port.count == 0) {
49745+ if (atomic_read(&tty->port.count) == 0) {
49746 mutex_unlock(&tty->ipw_tty_mutex);
49747 return;
49748 }
49749@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
49750
49751 mutex_lock(&tty->ipw_tty_mutex);
49752
49753- if (!tty->port.count) {
49754+ if (!atomic_read(&tty->port.count)) {
49755 mutex_unlock(&tty->ipw_tty_mutex);
49756 return;
49757 }
49758@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
49759 return -ENODEV;
49760
49761 mutex_lock(&tty->ipw_tty_mutex);
49762- if (!tty->port.count) {
49763+ if (!atomic_read(&tty->port.count)) {
49764 mutex_unlock(&tty->ipw_tty_mutex);
49765 return -EINVAL;
49766 }
49767@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
49768 if (!tty)
49769 return -ENODEV;
49770
49771- if (!tty->port.count)
49772+ if (!atomic_read(&tty->port.count))
49773 return -EINVAL;
49774
49775 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
49776@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
49777 if (!tty)
49778 return 0;
49779
49780- if (!tty->port.count)
49781+ if (!atomic_read(&tty->port.count))
49782 return 0;
49783
49784 return tty->tx_bytes_queued;
49785@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
49786 if (!tty)
49787 return -ENODEV;
49788
49789- if (!tty->port.count)
49790+ if (!atomic_read(&tty->port.count))
49791 return -EINVAL;
49792
49793 return get_control_lines(tty);
49794@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
49795 if (!tty)
49796 return -ENODEV;
49797
49798- if (!tty->port.count)
49799+ if (!atomic_read(&tty->port.count))
49800 return -EINVAL;
49801
49802 return set_control_lines(tty, set, clear);
49803@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
49804 if (!tty)
49805 return -ENODEV;
49806
49807- if (!tty->port.count)
49808+ if (!atomic_read(&tty->port.count))
49809 return -EINVAL;
49810
49811 /* FIXME: Exactly how is the tty object locked here .. */
49812@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
49813 * are gone */
49814 mutex_lock(&ttyj->ipw_tty_mutex);
49815 }
49816- while (ttyj->port.count)
49817+ while (atomic_read(&ttyj->port.count))
49818 do_ipw_close(ttyj);
49819 ipwireless_disassociate_network_ttys(network,
49820 ttyj->channel_idx);
49821diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
49822index 1deaca4..c8582d4 100644
49823--- a/drivers/tty/moxa.c
49824+++ b/drivers/tty/moxa.c
49825@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
49826 }
49827
49828 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
49829- ch->port.count++;
49830+ atomic_inc(&ch->port.count);
49831 tty->driver_data = ch;
49832 tty_port_tty_set(&ch->port, tty);
49833 mutex_lock(&ch->port.mutex);
49834diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
49835index c0f76da..d974c32 100644
49836--- a/drivers/tty/n_gsm.c
49837+++ b/drivers/tty/n_gsm.c
49838@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
49839 spin_lock_init(&dlci->lock);
49840 mutex_init(&dlci->mutex);
49841 dlci->fifo = &dlci->_fifo;
49842- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
49843+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
49844 kfree(dlci);
49845 return NULL;
49846 }
49847@@ -2935,7 +2935,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
49848 struct gsm_dlci *dlci = tty->driver_data;
49849 struct tty_port *port = &dlci->port;
49850
49851- port->count++;
49852+ atomic_inc(&port->count);
49853 dlci_get(dlci);
49854 dlci_get(dlci->gsm->dlci[0]);
49855 mux_get(dlci->gsm);
49856diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
49857index 34aacaa..dad073b 100644
49858--- a/drivers/tty/n_tty.c
49859+++ b/drivers/tty/n_tty.c
49860@@ -114,7 +114,7 @@ struct n_tty_data {
49861 int minimum_to_wake;
49862
49863 /* consumer-published */
49864- size_t read_tail;
49865+ size_t read_tail __intentional_overflow(-1);
49866 size_t line_start;
49867
49868 /* protected by output lock */
49869@@ -2502,6 +2502,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
49870 {
49871 *ops = tty_ldisc_N_TTY;
49872 ops->owner = NULL;
49873- ops->refcount = ops->flags = 0;
49874+ atomic_set(&ops->refcount, 0);
49875+ ops->flags = 0;
49876 }
49877 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
49878diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
49879index 25c9bc7..24077b7 100644
49880--- a/drivers/tty/pty.c
49881+++ b/drivers/tty/pty.c
49882@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
49883 panic("Couldn't register Unix98 pts driver");
49884
49885 /* Now create the /dev/ptmx special device */
49886+ pax_open_kernel();
49887 tty_default_fops(&ptmx_fops);
49888- ptmx_fops.open = ptmx_open;
49889+ *(void **)&ptmx_fops.open = ptmx_open;
49890+ pax_close_kernel();
49891
49892 cdev_init(&ptmx_cdev, &ptmx_fops);
49893 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
49894diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
49895index 354564e..fe50d9a 100644
49896--- a/drivers/tty/rocket.c
49897+++ b/drivers/tty/rocket.c
49898@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
49899 tty->driver_data = info;
49900 tty_port_tty_set(port, tty);
49901
49902- if (port->count++ == 0) {
49903+ if (atomic_inc_return(&port->count) == 1) {
49904 atomic_inc(&rp_num_ports_open);
49905
49906 #ifdef ROCKET_DEBUG_OPEN
49907@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
49908 #endif
49909 }
49910 #ifdef ROCKET_DEBUG_OPEN
49911- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
49912+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
49913 #endif
49914
49915 /*
49916@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
49917 spin_unlock_irqrestore(&info->port.lock, flags);
49918 return;
49919 }
49920- if (info->port.count)
49921+ if (atomic_read(&info->port.count))
49922 atomic_dec(&rp_num_ports_open);
49923 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
49924 spin_unlock_irqrestore(&info->port.lock, flags);
49925diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
49926index 1274499..f541382 100644
49927--- a/drivers/tty/serial/ioc4_serial.c
49928+++ b/drivers/tty/serial/ioc4_serial.c
49929@@ -437,7 +437,7 @@ struct ioc4_soft {
49930 } is_intr_info[MAX_IOC4_INTR_ENTS];
49931
49932 /* Number of entries active in the above array */
49933- atomic_t is_num_intrs;
49934+ atomic_unchecked_t is_num_intrs;
49935 } is_intr_type[IOC4_NUM_INTR_TYPES];
49936
49937 /* is_ir_lock must be held while
49938@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
49939 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
49940 || (type == IOC4_OTHER_INTR_TYPE)));
49941
49942- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
49943+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
49944 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
49945
49946 /* Save off the lower level interrupt handler */
49947@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
49948
49949 soft = arg;
49950 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
49951- num_intrs = (int)atomic_read(
49952+ num_intrs = (int)atomic_read_unchecked(
49953 &soft->is_intr_type[intr_type].is_num_intrs);
49954
49955 this_mir = this_ir = pending_intrs(soft, intr_type);
49956diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
49957index a260cde..6b2b5ce 100644
49958--- a/drivers/tty/serial/kgdboc.c
49959+++ b/drivers/tty/serial/kgdboc.c
49960@@ -24,8 +24,9 @@
49961 #define MAX_CONFIG_LEN 40
49962
49963 static struct kgdb_io kgdboc_io_ops;
49964+static struct kgdb_io kgdboc_io_ops_console;
49965
49966-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
49967+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
49968 static int configured = -1;
49969
49970 static char config[MAX_CONFIG_LEN];
49971@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
49972 kgdboc_unregister_kbd();
49973 if (configured == 1)
49974 kgdb_unregister_io_module(&kgdboc_io_ops);
49975+ else if (configured == 2)
49976+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
49977 }
49978
49979 static int configure_kgdboc(void)
49980@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
49981 int err;
49982 char *cptr = config;
49983 struct console *cons;
49984+ int is_console = 0;
49985
49986 err = kgdboc_option_setup(config);
49987 if (err || !strlen(config) || isspace(config[0]))
49988 goto noconfig;
49989
49990 err = -ENODEV;
49991- kgdboc_io_ops.is_console = 0;
49992 kgdb_tty_driver = NULL;
49993
49994 kgdboc_use_kms = 0;
49995@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
49996 int idx;
49997 if (cons->device && cons->device(cons, &idx) == p &&
49998 idx == tty_line) {
49999- kgdboc_io_ops.is_console = 1;
50000+ is_console = 1;
50001 break;
50002 }
50003 cons = cons->next;
50004@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
50005 kgdb_tty_line = tty_line;
50006
50007 do_register:
50008- err = kgdb_register_io_module(&kgdboc_io_ops);
50009+ if (is_console) {
50010+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
50011+ configured = 2;
50012+ } else {
50013+ err = kgdb_register_io_module(&kgdboc_io_ops);
50014+ configured = 1;
50015+ }
50016 if (err)
50017 goto noconfig;
50018
50019@@ -205,8 +214,6 @@ do_register:
50020 if (err)
50021 goto nmi_con_failed;
50022
50023- configured = 1;
50024-
50025 return 0;
50026
50027 nmi_con_failed:
50028@@ -223,7 +230,7 @@ noconfig:
50029 static int __init init_kgdboc(void)
50030 {
50031 /* Already configured? */
50032- if (configured == 1)
50033+ if (configured >= 1)
50034 return 0;
50035
50036 return configure_kgdboc();
50037@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
50038 if (config[len - 1] == '\n')
50039 config[len - 1] = '\0';
50040
50041- if (configured == 1)
50042+ if (configured >= 1)
50043 cleanup_kgdboc();
50044
50045 /* Go and configure with the new params. */
50046@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
50047 .post_exception = kgdboc_post_exp_handler,
50048 };
50049
50050+static struct kgdb_io kgdboc_io_ops_console = {
50051+ .name = "kgdboc",
50052+ .read_char = kgdboc_get_char,
50053+ .write_char = kgdboc_put_char,
50054+ .pre_exception = kgdboc_pre_exp_handler,
50055+ .post_exception = kgdboc_post_exp_handler,
50056+ .is_console = 1
50057+};
50058+
50059 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
50060 /* This is only available if kgdboc is a built in for early debugging */
50061 static int __init kgdboc_early_init(char *opt)
50062diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
50063index b5d779c..3622cfe 100644
50064--- a/drivers/tty/serial/msm_serial.c
50065+++ b/drivers/tty/serial/msm_serial.c
50066@@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
50067 .cons = MSM_CONSOLE,
50068 };
50069
50070-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
50071+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
50072
50073 static const struct of_device_id msm_uartdm_table[] = {
50074 { .compatible = "qcom,msm-uartdm" },
50075@@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
50076 int irq;
50077
50078 if (pdev->id == -1)
50079- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
50080+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
50081
50082 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
50083 return -ENXIO;
50084diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
50085index c1af04d..0815c8a 100644
50086--- a/drivers/tty/serial/samsung.c
50087+++ b/drivers/tty/serial/samsung.c
50088@@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
50089 }
50090 }
50091
50092+static int s3c64xx_serial_startup(struct uart_port *port);
50093 static int s3c24xx_serial_startup(struct uart_port *port)
50094 {
50095 struct s3c24xx_uart_port *ourport = to_ourport(port);
50096 int ret;
50097
50098+ /* Startup sequence is different for s3c64xx and higher SoC's */
50099+ if (s3c24xx_serial_has_interrupt_mask(port))
50100+ return s3c64xx_serial_startup(port);
50101+
50102 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
50103 port->mapbase, port->membase);
50104
50105@@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
50106 /* setup info for port */
50107 port->dev = &platdev->dev;
50108
50109- /* Startup sequence is different for s3c64xx and higher SoC's */
50110- if (s3c24xx_serial_has_interrupt_mask(port))
50111- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
50112-
50113 port->uartclk = 1;
50114
50115 if (cfg->uart_flags & UPF_CONS_FLOW) {
50116diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
50117index 0f02351..07c59c5 100644
50118--- a/drivers/tty/serial/serial_core.c
50119+++ b/drivers/tty/serial/serial_core.c
50120@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
50121 uart_flush_buffer(tty);
50122 uart_shutdown(tty, state);
50123 spin_lock_irqsave(&port->lock, flags);
50124- port->count = 0;
50125+ atomic_set(&port->count, 0);
50126 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
50127 spin_unlock_irqrestore(&port->lock, flags);
50128 tty_port_tty_set(port, NULL);
50129@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50130 goto end;
50131 }
50132
50133- port->count++;
50134+ atomic_inc(&port->count);
50135 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
50136 retval = -ENXIO;
50137 goto err_dec_count;
50138@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50139 /*
50140 * Make sure the device is in D0 state.
50141 */
50142- if (port->count == 1)
50143+ if (atomic_read(&port->count) == 1)
50144 uart_change_pm(state, UART_PM_STATE_ON);
50145
50146 /*
50147@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50148 end:
50149 return retval;
50150 err_dec_count:
50151- port->count--;
50152+ atomic_inc(&port->count);
50153 mutex_unlock(&port->mutex);
50154 goto end;
50155 }
50156diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
50157index e1ce141..6d4ed80 100644
50158--- a/drivers/tty/synclink.c
50159+++ b/drivers/tty/synclink.c
50160@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50161
50162 if (debug_level >= DEBUG_LEVEL_INFO)
50163 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
50164- __FILE__,__LINE__, info->device_name, info->port.count);
50165+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
50166
50167 if (tty_port_close_start(&info->port, tty, filp) == 0)
50168 goto cleanup;
50169@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50170 cleanup:
50171 if (debug_level >= DEBUG_LEVEL_INFO)
50172 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
50173- tty->driver->name, info->port.count);
50174+ tty->driver->name, atomic_read(&info->port.count));
50175
50176 } /* end of mgsl_close() */
50177
50178@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
50179
50180 mgsl_flush_buffer(tty);
50181 shutdown(info);
50182-
50183- info->port.count = 0;
50184+
50185+ atomic_set(&info->port.count, 0);
50186 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
50187 info->port.tty = NULL;
50188
50189@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50190
50191 if (debug_level >= DEBUG_LEVEL_INFO)
50192 printk("%s(%d):block_til_ready before block on %s count=%d\n",
50193- __FILE__,__LINE__, tty->driver->name, port->count );
50194+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50195
50196 spin_lock_irqsave(&info->irq_spinlock, flags);
50197 if (!tty_hung_up_p(filp)) {
50198 extra_count = true;
50199- port->count--;
50200+ atomic_dec(&port->count);
50201 }
50202 spin_unlock_irqrestore(&info->irq_spinlock, flags);
50203 port->blocked_open++;
50204@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50205
50206 if (debug_level >= DEBUG_LEVEL_INFO)
50207 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
50208- __FILE__,__LINE__, tty->driver->name, port->count );
50209+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50210
50211 tty_unlock(tty);
50212 schedule();
50213@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50214
50215 /* FIXME: Racy on hangup during close wait */
50216 if (extra_count)
50217- port->count++;
50218+ atomic_inc(&port->count);
50219 port->blocked_open--;
50220
50221 if (debug_level >= DEBUG_LEVEL_INFO)
50222 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
50223- __FILE__,__LINE__, tty->driver->name, port->count );
50224+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50225
50226 if (!retval)
50227 port->flags |= ASYNC_NORMAL_ACTIVE;
50228@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
50229
50230 if (debug_level >= DEBUG_LEVEL_INFO)
50231 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
50232- __FILE__,__LINE__,tty->driver->name, info->port.count);
50233+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
50234
50235 /* If port is closing, signal caller to try again */
50236 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
50237@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
50238 spin_unlock_irqrestore(&info->netlock, flags);
50239 goto cleanup;
50240 }
50241- info->port.count++;
50242+ atomic_inc(&info->port.count);
50243 spin_unlock_irqrestore(&info->netlock, flags);
50244
50245- if (info->port.count == 1) {
50246+ if (atomic_read(&info->port.count) == 1) {
50247 /* 1st open on this device, init hardware */
50248 retval = startup(info);
50249 if (retval < 0)
50250@@ -3446,8 +3446,8 @@ cleanup:
50251 if (retval) {
50252 if (tty->count == 1)
50253 info->port.tty = NULL; /* tty layer will release tty struct */
50254- if(info->port.count)
50255- info->port.count--;
50256+ if (atomic_read(&info->port.count))
50257+ atomic_dec(&info->port.count);
50258 }
50259
50260 return retval;
50261@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
50262 unsigned short new_crctype;
50263
50264 /* return error if TTY interface open */
50265- if (info->port.count)
50266+ if (atomic_read(&info->port.count))
50267 return -EBUSY;
50268
50269 switch (encoding)
50270@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
50271
50272 /* arbitrate between network and tty opens */
50273 spin_lock_irqsave(&info->netlock, flags);
50274- if (info->port.count != 0 || info->netcount != 0) {
50275+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
50276 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
50277 spin_unlock_irqrestore(&info->netlock, flags);
50278 return -EBUSY;
50279@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50280 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
50281
50282 /* return error if TTY interface open */
50283- if (info->port.count)
50284+ if (atomic_read(&info->port.count))
50285 return -EBUSY;
50286
50287 if (cmd != SIOCWANDEV)
50288diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
50289index 1abf946..1ee34fc 100644
50290--- a/drivers/tty/synclink_gt.c
50291+++ b/drivers/tty/synclink_gt.c
50292@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
50293 tty->driver_data = info;
50294 info->port.tty = tty;
50295
50296- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
50297+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
50298
50299 /* If port is closing, signal caller to try again */
50300 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
50301@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
50302 mutex_unlock(&info->port.mutex);
50303 goto cleanup;
50304 }
50305- info->port.count++;
50306+ atomic_inc(&info->port.count);
50307 spin_unlock_irqrestore(&info->netlock, flags);
50308
50309- if (info->port.count == 1) {
50310+ if (atomic_read(&info->port.count) == 1) {
50311 /* 1st open on this device, init hardware */
50312 retval = startup(info);
50313 if (retval < 0) {
50314@@ -715,8 +715,8 @@ cleanup:
50315 if (retval) {
50316 if (tty->count == 1)
50317 info->port.tty = NULL; /* tty layer will release tty struct */
50318- if(info->port.count)
50319- info->port.count--;
50320+ if(atomic_read(&info->port.count))
50321+ atomic_dec(&info->port.count);
50322 }
50323
50324 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
50325@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
50326
50327 if (sanity_check(info, tty->name, "close"))
50328 return;
50329- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
50330+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
50331
50332 if (tty_port_close_start(&info->port, tty, filp) == 0)
50333 goto cleanup;
50334@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
50335 tty_port_close_end(&info->port, tty);
50336 info->port.tty = NULL;
50337 cleanup:
50338- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
50339+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
50340 }
50341
50342 static void hangup(struct tty_struct *tty)
50343@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
50344 shutdown(info);
50345
50346 spin_lock_irqsave(&info->port.lock, flags);
50347- info->port.count = 0;
50348+ atomic_set(&info->port.count, 0);
50349 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
50350 info->port.tty = NULL;
50351 spin_unlock_irqrestore(&info->port.lock, flags);
50352@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
50353 unsigned short new_crctype;
50354
50355 /* return error if TTY interface open */
50356- if (info->port.count)
50357+ if (atomic_read(&info->port.count))
50358 return -EBUSY;
50359
50360 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
50361@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
50362
50363 /* arbitrate between network and tty opens */
50364 spin_lock_irqsave(&info->netlock, flags);
50365- if (info->port.count != 0 || info->netcount != 0) {
50366+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
50367 DBGINFO(("%s hdlc_open busy\n", dev->name));
50368 spin_unlock_irqrestore(&info->netlock, flags);
50369 return -EBUSY;
50370@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50371 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
50372
50373 /* return error if TTY interface open */
50374- if (info->port.count)
50375+ if (atomic_read(&info->port.count))
50376 return -EBUSY;
50377
50378 if (cmd != SIOCWANDEV)
50379@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
50380 if (port == NULL)
50381 continue;
50382 spin_lock(&port->lock);
50383- if ((port->port.count || port->netcount) &&
50384+ if ((atomic_read(&port->port.count) || port->netcount) &&
50385 port->pending_bh && !port->bh_running &&
50386 !port->bh_requested) {
50387 DBGISR(("%s bh queued\n", port->device_name));
50388@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50389 spin_lock_irqsave(&info->lock, flags);
50390 if (!tty_hung_up_p(filp)) {
50391 extra_count = true;
50392- port->count--;
50393+ atomic_dec(&port->count);
50394 }
50395 spin_unlock_irqrestore(&info->lock, flags);
50396 port->blocked_open++;
50397@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50398 remove_wait_queue(&port->open_wait, &wait);
50399
50400 if (extra_count)
50401- port->count++;
50402+ atomic_inc(&port->count);
50403 port->blocked_open--;
50404
50405 if (!retval)
50406diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
50407index dc6e969..5dc8786 100644
50408--- a/drivers/tty/synclinkmp.c
50409+++ b/drivers/tty/synclinkmp.c
50410@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
50411
50412 if (debug_level >= DEBUG_LEVEL_INFO)
50413 printk("%s(%d):%s open(), old ref count = %d\n",
50414- __FILE__,__LINE__,tty->driver->name, info->port.count);
50415+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
50416
50417 /* If port is closing, signal caller to try again */
50418 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
50419@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
50420 spin_unlock_irqrestore(&info->netlock, flags);
50421 goto cleanup;
50422 }
50423- info->port.count++;
50424+ atomic_inc(&info->port.count);
50425 spin_unlock_irqrestore(&info->netlock, flags);
50426
50427- if (info->port.count == 1) {
50428+ if (atomic_read(&info->port.count) == 1) {
50429 /* 1st open on this device, init hardware */
50430 retval = startup(info);
50431 if (retval < 0)
50432@@ -796,8 +796,8 @@ cleanup:
50433 if (retval) {
50434 if (tty->count == 1)
50435 info->port.tty = NULL; /* tty layer will release tty struct */
50436- if(info->port.count)
50437- info->port.count--;
50438+ if(atomic_read(&info->port.count))
50439+ atomic_dec(&info->port.count);
50440 }
50441
50442 return retval;
50443@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
50444
50445 if (debug_level >= DEBUG_LEVEL_INFO)
50446 printk("%s(%d):%s close() entry, count=%d\n",
50447- __FILE__,__LINE__, info->device_name, info->port.count);
50448+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
50449
50450 if (tty_port_close_start(&info->port, tty, filp) == 0)
50451 goto cleanup;
50452@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
50453 cleanup:
50454 if (debug_level >= DEBUG_LEVEL_INFO)
50455 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
50456- tty->driver->name, info->port.count);
50457+ tty->driver->name, atomic_read(&info->port.count));
50458 }
50459
50460 /* Called by tty_hangup() when a hangup is signaled.
50461@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
50462 shutdown(info);
50463
50464 spin_lock_irqsave(&info->port.lock, flags);
50465- info->port.count = 0;
50466+ atomic_set(&info->port.count, 0);
50467 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
50468 info->port.tty = NULL;
50469 spin_unlock_irqrestore(&info->port.lock, flags);
50470@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
50471 unsigned short new_crctype;
50472
50473 /* return error if TTY interface open */
50474- if (info->port.count)
50475+ if (atomic_read(&info->port.count))
50476 return -EBUSY;
50477
50478 switch (encoding)
50479@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
50480
50481 /* arbitrate between network and tty opens */
50482 spin_lock_irqsave(&info->netlock, flags);
50483- if (info->port.count != 0 || info->netcount != 0) {
50484+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
50485 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
50486 spin_unlock_irqrestore(&info->netlock, flags);
50487 return -EBUSY;
50488@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50489 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
50490
50491 /* return error if TTY interface open */
50492- if (info->port.count)
50493+ if (atomic_read(&info->port.count))
50494 return -EBUSY;
50495
50496 if (cmd != SIOCWANDEV)
50497@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
50498 * do not request bottom half processing if the
50499 * device is not open in a normal mode.
50500 */
50501- if ( port && (port->port.count || port->netcount) &&
50502+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
50503 port->pending_bh && !port->bh_running &&
50504 !port->bh_requested ) {
50505 if ( debug_level >= DEBUG_LEVEL_ISR )
50506@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50507
50508 if (debug_level >= DEBUG_LEVEL_INFO)
50509 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
50510- __FILE__,__LINE__, tty->driver->name, port->count );
50511+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50512
50513 spin_lock_irqsave(&info->lock, flags);
50514 if (!tty_hung_up_p(filp)) {
50515 extra_count = true;
50516- port->count--;
50517+ atomic_dec(&port->count);
50518 }
50519 spin_unlock_irqrestore(&info->lock, flags);
50520 port->blocked_open++;
50521@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50522
50523 if (debug_level >= DEBUG_LEVEL_INFO)
50524 printk("%s(%d):%s block_til_ready() count=%d\n",
50525- __FILE__,__LINE__, tty->driver->name, port->count );
50526+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50527
50528 tty_unlock(tty);
50529 schedule();
50530@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50531 remove_wait_queue(&port->open_wait, &wait);
50532
50533 if (extra_count)
50534- port->count++;
50535+ atomic_inc(&port->count);
50536 port->blocked_open--;
50537
50538 if (debug_level >= DEBUG_LEVEL_INFO)
50539 printk("%s(%d):%s block_til_ready() after, count=%d\n",
50540- __FILE__,__LINE__, tty->driver->name, port->count );
50541+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50542
50543 if (!retval)
50544 port->flags |= ASYNC_NORMAL_ACTIVE;
50545diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
50546index ce396ec..04a37be 100644
50547--- a/drivers/tty/sysrq.c
50548+++ b/drivers/tty/sysrq.c
50549@@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
50550 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
50551 size_t count, loff_t *ppos)
50552 {
50553- if (count) {
50554+ if (count && capable(CAP_SYS_ADMIN)) {
50555 char c;
50556
50557 if (get_user(c, buf))
50558diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
50559index c74a00a..02cf211a 100644
50560--- a/drivers/tty/tty_io.c
50561+++ b/drivers/tty/tty_io.c
50562@@ -3474,7 +3474,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
50563
50564 void tty_default_fops(struct file_operations *fops)
50565 {
50566- *fops = tty_fops;
50567+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
50568 }
50569
50570 /*
50571diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
50572index 6458e11..6cfc218 100644
50573--- a/drivers/tty/tty_ldisc.c
50574+++ b/drivers/tty/tty_ldisc.c
50575@@ -72,7 +72,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
50576 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
50577 tty_ldiscs[disc] = new_ldisc;
50578 new_ldisc->num = disc;
50579- new_ldisc->refcount = 0;
50580+ atomic_set(&new_ldisc->refcount, 0);
50581 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
50582
50583 return ret;
50584@@ -100,7 +100,7 @@ int tty_unregister_ldisc(int disc)
50585 return -EINVAL;
50586
50587 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
50588- if (tty_ldiscs[disc]->refcount)
50589+ if (atomic_read(&tty_ldiscs[disc]->refcount))
50590 ret = -EBUSY;
50591 else
50592 tty_ldiscs[disc] = NULL;
50593@@ -121,7 +121,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
50594 if (ldops) {
50595 ret = ERR_PTR(-EAGAIN);
50596 if (try_module_get(ldops->owner)) {
50597- ldops->refcount++;
50598+ atomic_inc(&ldops->refcount);
50599 ret = ldops;
50600 }
50601 }
50602@@ -134,7 +134,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
50603 unsigned long flags;
50604
50605 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
50606- ldops->refcount--;
50607+ atomic_dec(&ldops->refcount);
50608 module_put(ldops->owner);
50609 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
50610 }
50611diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
50612index c94d234..8210f2d 100644
50613--- a/drivers/tty/tty_port.c
50614+++ b/drivers/tty/tty_port.c
50615@@ -236,7 +236,7 @@ void tty_port_hangup(struct tty_port *port)
50616 unsigned long flags;
50617
50618 spin_lock_irqsave(&port->lock, flags);
50619- port->count = 0;
50620+ atomic_set(&port->count, 0);
50621 port->flags &= ~ASYNC_NORMAL_ACTIVE;
50622 tty = port->tty;
50623 if (tty)
50624@@ -394,7 +394,7 @@ int tty_port_block_til_ready(struct tty_port *port,
50625 /* The port lock protects the port counts */
50626 spin_lock_irqsave(&port->lock, flags);
50627 if (!tty_hung_up_p(filp))
50628- port->count--;
50629+ atomic_dec(&port->count);
50630 port->blocked_open++;
50631 spin_unlock_irqrestore(&port->lock, flags);
50632
50633@@ -436,7 +436,7 @@ int tty_port_block_til_ready(struct tty_port *port,
50634 we must not mess that up further */
50635 spin_lock_irqsave(&port->lock, flags);
50636 if (!tty_hung_up_p(filp))
50637- port->count++;
50638+ atomic_inc(&port->count);
50639 port->blocked_open--;
50640 if (retval == 0)
50641 port->flags |= ASYNC_NORMAL_ACTIVE;
50642@@ -470,19 +470,19 @@ int tty_port_close_start(struct tty_port *port,
50643 return 0;
50644 }
50645
50646- if (tty->count == 1 && port->count != 1) {
50647+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
50648 printk(KERN_WARNING
50649 "tty_port_close_start: tty->count = 1 port count = %d.\n",
50650- port->count);
50651- port->count = 1;
50652+ atomic_read(&port->count));
50653+ atomic_set(&port->count, 1);
50654 }
50655- if (--port->count < 0) {
50656+ if (atomic_dec_return(&port->count) < 0) {
50657 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
50658- port->count);
50659- port->count = 0;
50660+ atomic_read(&port->count));
50661+ atomic_set(&port->count, 0);
50662 }
50663
50664- if (port->count) {
50665+ if (atomic_read(&port->count)) {
50666 spin_unlock_irqrestore(&port->lock, flags);
50667 return 0;
50668 }
50669@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
50670 {
50671 spin_lock_irq(&port->lock);
50672 if (!tty_hung_up_p(filp))
50673- ++port->count;
50674+ atomic_inc(&port->count);
50675 spin_unlock_irq(&port->lock);
50676 tty_port_tty_set(port, tty);
50677
50678diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
50679index d0e3a44..5f8b754 100644
50680--- a/drivers/tty/vt/keyboard.c
50681+++ b/drivers/tty/vt/keyboard.c
50682@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
50683 kbd->kbdmode == VC_OFF) &&
50684 value != KVAL(K_SAK))
50685 return; /* SAK is allowed even in raw mode */
50686+
50687+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50688+ {
50689+ void *func = fn_handler[value];
50690+ if (func == fn_show_state || func == fn_show_ptregs ||
50691+ func == fn_show_mem)
50692+ return;
50693+ }
50694+#endif
50695+
50696 fn_handler[value](vc);
50697 }
50698
50699@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
50700 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
50701 return -EFAULT;
50702
50703- if (!capable(CAP_SYS_TTY_CONFIG))
50704- perm = 0;
50705-
50706 switch (cmd) {
50707 case KDGKBENT:
50708 /* Ensure another thread doesn't free it under us */
50709@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
50710 spin_unlock_irqrestore(&kbd_event_lock, flags);
50711 return put_user(val, &user_kbe->kb_value);
50712 case KDSKBENT:
50713+ if (!capable(CAP_SYS_TTY_CONFIG))
50714+ perm = 0;
50715+
50716 if (!perm)
50717 return -EPERM;
50718 if (!i && v == K_NOSUCHMAP) {
50719@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
50720 int i, j, k;
50721 int ret;
50722
50723- if (!capable(CAP_SYS_TTY_CONFIG))
50724- perm = 0;
50725-
50726 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
50727 if (!kbs) {
50728 ret = -ENOMEM;
50729@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
50730 kfree(kbs);
50731 return ((p && *p) ? -EOVERFLOW : 0);
50732 case KDSKBSENT:
50733+ if (!capable(CAP_SYS_TTY_CONFIG))
50734+ perm = 0;
50735+
50736 if (!perm) {
50737 ret = -EPERM;
50738 goto reterr;
50739diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
50740index a673e5b..36e5d32 100644
50741--- a/drivers/uio/uio.c
50742+++ b/drivers/uio/uio.c
50743@@ -25,6 +25,7 @@
50744 #include <linux/kobject.h>
50745 #include <linux/cdev.h>
50746 #include <linux/uio_driver.h>
50747+#include <asm/local.h>
50748
50749 #define UIO_MAX_DEVICES (1U << MINORBITS)
50750
50751@@ -32,7 +33,7 @@ struct uio_device {
50752 struct module *owner;
50753 struct device *dev;
50754 int minor;
50755- atomic_t event;
50756+ atomic_unchecked_t event;
50757 struct fasync_struct *async_queue;
50758 wait_queue_head_t wait;
50759 struct uio_info *info;
50760@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
50761 struct device_attribute *attr, char *buf)
50762 {
50763 struct uio_device *idev = dev_get_drvdata(dev);
50764- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
50765+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
50766 }
50767 static DEVICE_ATTR_RO(event);
50768
50769@@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
50770 {
50771 struct uio_device *idev = info->uio_dev;
50772
50773- atomic_inc(&idev->event);
50774+ atomic_inc_unchecked(&idev->event);
50775 wake_up_interruptible(&idev->wait);
50776 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
50777 }
50778@@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
50779 }
50780
50781 listener->dev = idev;
50782- listener->event_count = atomic_read(&idev->event);
50783+ listener->event_count = atomic_read_unchecked(&idev->event);
50784 filep->private_data = listener;
50785
50786 if (idev->info->open) {
50787@@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
50788 return -EIO;
50789
50790 poll_wait(filep, &idev->wait, wait);
50791- if (listener->event_count != atomic_read(&idev->event))
50792+ if (listener->event_count != atomic_read_unchecked(&idev->event))
50793 return POLLIN | POLLRDNORM;
50794 return 0;
50795 }
50796@@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
50797 do {
50798 set_current_state(TASK_INTERRUPTIBLE);
50799
50800- event_count = atomic_read(&idev->event);
50801+ event_count = atomic_read_unchecked(&idev->event);
50802 if (event_count != listener->event_count) {
50803 if (copy_to_user(buf, &event_count, count))
50804 retval = -EFAULT;
50805@@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
50806 static int uio_find_mem_index(struct vm_area_struct *vma)
50807 {
50808 struct uio_device *idev = vma->vm_private_data;
50809+ unsigned long size;
50810
50811 if (vma->vm_pgoff < MAX_UIO_MAPS) {
50812- if (idev->info->mem[vma->vm_pgoff].size == 0)
50813+ size = idev->info->mem[vma->vm_pgoff].size;
50814+ if (size == 0)
50815+ return -1;
50816+ if (vma->vm_end - vma->vm_start > size)
50817 return -1;
50818 return (int)vma->vm_pgoff;
50819 }
50820@@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
50821 idev->owner = owner;
50822 idev->info = info;
50823 init_waitqueue_head(&idev->wait);
50824- atomic_set(&idev->event, 0);
50825+ atomic_set_unchecked(&idev->event, 0);
50826
50827 ret = uio_get_minor(idev);
50828 if (ret)
50829diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
50830index 8a7eb77..c00402f 100644
50831--- a/drivers/usb/atm/cxacru.c
50832+++ b/drivers/usb/atm/cxacru.c
50833@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
50834 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
50835 if (ret < 2)
50836 return -EINVAL;
50837- if (index < 0 || index > 0x7f)
50838+ if (index > 0x7f)
50839 return -EINVAL;
50840 pos += tmp;
50841
50842diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
50843index 25a7bfc..57f3cf5 100644
50844--- a/drivers/usb/atm/usbatm.c
50845+++ b/drivers/usb/atm/usbatm.c
50846@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50847 if (printk_ratelimit())
50848 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
50849 __func__, vpi, vci);
50850- atomic_inc(&vcc->stats->rx_err);
50851+ atomic_inc_unchecked(&vcc->stats->rx_err);
50852 return;
50853 }
50854
50855@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50856 if (length > ATM_MAX_AAL5_PDU) {
50857 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
50858 __func__, length, vcc);
50859- atomic_inc(&vcc->stats->rx_err);
50860+ atomic_inc_unchecked(&vcc->stats->rx_err);
50861 goto out;
50862 }
50863
50864@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50865 if (sarb->len < pdu_length) {
50866 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
50867 __func__, pdu_length, sarb->len, vcc);
50868- atomic_inc(&vcc->stats->rx_err);
50869+ atomic_inc_unchecked(&vcc->stats->rx_err);
50870 goto out;
50871 }
50872
50873 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
50874 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
50875 __func__, vcc);
50876- atomic_inc(&vcc->stats->rx_err);
50877+ atomic_inc_unchecked(&vcc->stats->rx_err);
50878 goto out;
50879 }
50880
50881@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50882 if (printk_ratelimit())
50883 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
50884 __func__, length);
50885- atomic_inc(&vcc->stats->rx_drop);
50886+ atomic_inc_unchecked(&vcc->stats->rx_drop);
50887 goto out;
50888 }
50889
50890@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50891
50892 vcc->push(vcc, skb);
50893
50894- atomic_inc(&vcc->stats->rx);
50895+ atomic_inc_unchecked(&vcc->stats->rx);
50896 out:
50897 skb_trim(sarb, 0);
50898 }
50899@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
50900 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
50901
50902 usbatm_pop(vcc, skb);
50903- atomic_inc(&vcc->stats->tx);
50904+ atomic_inc_unchecked(&vcc->stats->tx);
50905
50906 skb = skb_dequeue(&instance->sndqueue);
50907 }
50908@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
50909 if (!left--)
50910 return sprintf(page,
50911 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
50912- atomic_read(&atm_dev->stats.aal5.tx),
50913- atomic_read(&atm_dev->stats.aal5.tx_err),
50914- atomic_read(&atm_dev->stats.aal5.rx),
50915- atomic_read(&atm_dev->stats.aal5.rx_err),
50916- atomic_read(&atm_dev->stats.aal5.rx_drop));
50917+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
50918+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
50919+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
50920+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
50921+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
50922
50923 if (!left--) {
50924 if (instance->disconnected)
50925diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
50926index 2a3bbdf..91d72cf 100644
50927--- a/drivers/usb/core/devices.c
50928+++ b/drivers/usb/core/devices.c
50929@@ -126,7 +126,7 @@ static const char format_endpt[] =
50930 * time it gets called.
50931 */
50932 static struct device_connect_event {
50933- atomic_t count;
50934+ atomic_unchecked_t count;
50935 wait_queue_head_t wait;
50936 } device_event = {
50937 .count = ATOMIC_INIT(1),
50938@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
50939
50940 void usbfs_conn_disc_event(void)
50941 {
50942- atomic_add(2, &device_event.count);
50943+ atomic_add_unchecked(2, &device_event.count);
50944 wake_up(&device_event.wait);
50945 }
50946
50947@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
50948
50949 poll_wait(file, &device_event.wait, wait);
50950
50951- event_count = atomic_read(&device_event.count);
50952+ event_count = atomic_read_unchecked(&device_event.count);
50953 if (file->f_version != event_count) {
50954 file->f_version = event_count;
50955 return POLLIN | POLLRDNORM;
50956diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
50957index 967152a..16fa2e5 100644
50958--- a/drivers/usb/core/devio.c
50959+++ b/drivers/usb/core/devio.c
50960@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
50961 struct dev_state *ps = file->private_data;
50962 struct usb_device *dev = ps->dev;
50963 ssize_t ret = 0;
50964- unsigned len;
50965+ size_t len;
50966 loff_t pos;
50967 int i;
50968
50969@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
50970 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
50971 struct usb_config_descriptor *config =
50972 (struct usb_config_descriptor *)dev->rawdescriptors[i];
50973- unsigned int length = le16_to_cpu(config->wTotalLength);
50974+ size_t length = le16_to_cpu(config->wTotalLength);
50975
50976 if (*ppos < pos + length) {
50977
50978 /* The descriptor may claim to be longer than it
50979 * really is. Here is the actual allocated length. */
50980- unsigned alloclen =
50981+ size_t alloclen =
50982 le16_to_cpu(dev->config[i].desc.wTotalLength);
50983
50984- len = length - (*ppos - pos);
50985+ len = length + pos - *ppos;
50986 if (len > nbytes)
50987 len = nbytes;
50988
50989 /* Simply don't write (skip over) unallocated parts */
50990 if (alloclen > (*ppos - pos)) {
50991- alloclen -= (*ppos - pos);
50992+ alloclen = alloclen + pos - *ppos;
50993 if (copy_to_user(buf,
50994 dev->rawdescriptors[i] + (*ppos - pos),
50995 min(len, alloclen))) {
50996diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
50997index 6bffb8c..b404e8b 100644
50998--- a/drivers/usb/core/hcd.c
50999+++ b/drivers/usb/core/hcd.c
51000@@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51001 */
51002 usb_get_urb(urb);
51003 atomic_inc(&urb->use_count);
51004- atomic_inc(&urb->dev->urbnum);
51005+ atomic_inc_unchecked(&urb->dev->urbnum);
51006 usbmon_urb_submit(&hcd->self, urb);
51007
51008 /* NOTE requirements on root-hub callers (usbfs and the hub
51009@@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51010 urb->hcpriv = NULL;
51011 INIT_LIST_HEAD(&urb->urb_list);
51012 atomic_dec(&urb->use_count);
51013- atomic_dec(&urb->dev->urbnum);
51014+ atomic_dec_unchecked(&urb->dev->urbnum);
51015 if (atomic_read(&urb->reject))
51016 wake_up(&usb_kill_urb_queue);
51017 usb_put_urb(urb);
51018diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
51019index 07e6654..6420edf 100644
51020--- a/drivers/usb/core/hub.c
51021+++ b/drivers/usb/core/hub.c
51022@@ -27,6 +27,7 @@
51023 #include <linux/freezer.h>
51024 #include <linux/random.h>
51025 #include <linux/pm_qos.h>
51026+#include <linux/grsecurity.h>
51027
51028 #include <asm/uaccess.h>
51029 #include <asm/byteorder.h>
51030@@ -4442,6 +4443,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
51031 goto done;
51032 return;
51033 }
51034+
51035+ if (gr_handle_new_usb())
51036+ goto done;
51037+
51038 if (hub_is_superspeed(hub->hdev))
51039 unit_load = 150;
51040 else
51041diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
51042index bb31597..6c5ef8b 100644
51043--- a/drivers/usb/core/message.c
51044+++ b/drivers/usb/core/message.c
51045@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
51046 * Return: If successful, the number of bytes transferred. Otherwise, a negative
51047 * error number.
51048 */
51049-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51050+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51051 __u8 requesttype, __u16 value, __u16 index, void *data,
51052 __u16 size, int timeout)
51053 {
51054@@ -181,7 +181,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
51055 * If successful, 0. Otherwise a negative error number. The number of actual
51056 * bytes transferred will be stored in the @actual_length paramater.
51057 */
51058-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51059+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51060 void *data, int len, int *actual_length, int timeout)
51061 {
51062 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
51063@@ -221,7 +221,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
51064 * bytes transferred will be stored in the @actual_length paramater.
51065 *
51066 */
51067-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51068+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51069 void *data, int len, int *actual_length, int timeout)
51070 {
51071 struct urb *urb;
51072diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
51073index 52a97ad..e73330f 100644
51074--- a/drivers/usb/core/sysfs.c
51075+++ b/drivers/usb/core/sysfs.c
51076@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
51077 struct usb_device *udev;
51078
51079 udev = to_usb_device(dev);
51080- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
51081+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
51082 }
51083 static DEVICE_ATTR_RO(urbnum);
51084
51085diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
51086index 4d11449..f4ccabf 100644
51087--- a/drivers/usb/core/usb.c
51088+++ b/drivers/usb/core/usb.c
51089@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
51090 set_dev_node(&dev->dev, dev_to_node(bus->controller));
51091 dev->state = USB_STATE_ATTACHED;
51092 dev->lpm_disable_count = 1;
51093- atomic_set(&dev->urbnum, 0);
51094+ atomic_set_unchecked(&dev->urbnum, 0);
51095
51096 INIT_LIST_HEAD(&dev->ep0.urb_list);
51097 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
51098diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
51099index 02e44fc..3c4fe64 100644
51100--- a/drivers/usb/dwc3/gadget.c
51101+++ b/drivers/usb/dwc3/gadget.c
51102@@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
51103 if (!usb_endpoint_xfer_isoc(desc))
51104 return 0;
51105
51106- memset(&trb_link, 0, sizeof(trb_link));
51107-
51108 /* Link TRB for ISOC. The HWO bit is never reset */
51109 trb_st_hw = &dep->trb_pool[0];
51110
51111diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
51112index 8cfc319..4868255 100644
51113--- a/drivers/usb/early/ehci-dbgp.c
51114+++ b/drivers/usb/early/ehci-dbgp.c
51115@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
51116
51117 #ifdef CONFIG_KGDB
51118 static struct kgdb_io kgdbdbgp_io_ops;
51119-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
51120+static struct kgdb_io kgdbdbgp_io_ops_console;
51121+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
51122 #else
51123 #define dbgp_kgdb_mode (0)
51124 #endif
51125@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
51126 .write_char = kgdbdbgp_write_char,
51127 };
51128
51129+static struct kgdb_io kgdbdbgp_io_ops_console = {
51130+ .name = "kgdbdbgp",
51131+ .read_char = kgdbdbgp_read_char,
51132+ .write_char = kgdbdbgp_write_char,
51133+ .is_console = 1
51134+};
51135+
51136 static int kgdbdbgp_wait_time;
51137
51138 static int __init kgdbdbgp_parse_config(char *str)
51139@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
51140 ptr++;
51141 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
51142 }
51143- kgdb_register_io_module(&kgdbdbgp_io_ops);
51144- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
51145+ if (early_dbgp_console.index != -1)
51146+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
51147+ else
51148+ kgdb_register_io_module(&kgdbdbgp_io_ops);
51149
51150 return 0;
51151 }
51152diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
51153index b369292..9f3ba40 100644
51154--- a/drivers/usb/gadget/u_serial.c
51155+++ b/drivers/usb/gadget/u_serial.c
51156@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
51157 spin_lock_irq(&port->port_lock);
51158
51159 /* already open? Great. */
51160- if (port->port.count) {
51161+ if (atomic_read(&port->port.count)) {
51162 status = 0;
51163- port->port.count++;
51164+ atomic_inc(&port->port.count);
51165
51166 /* currently opening/closing? wait ... */
51167 } else if (port->openclose) {
51168@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
51169 tty->driver_data = port;
51170 port->port.tty = tty;
51171
51172- port->port.count = 1;
51173+ atomic_set(&port->port.count, 1);
51174 port->openclose = false;
51175
51176 /* if connected, start the I/O stream */
51177@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
51178
51179 spin_lock_irq(&port->port_lock);
51180
51181- if (port->port.count != 1) {
51182- if (port->port.count == 0)
51183+ if (atomic_read(&port->port.count) != 1) {
51184+ if (atomic_read(&port->port.count) == 0)
51185 WARN_ON(1);
51186 else
51187- --port->port.count;
51188+ atomic_dec(&port->port.count);
51189 goto exit;
51190 }
51191
51192@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
51193 * and sleep if necessary
51194 */
51195 port->openclose = true;
51196- port->port.count = 0;
51197+ atomic_set(&port->port.count, 0);
51198
51199 gser = port->port_usb;
51200 if (gser && gser->disconnect)
51201@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
51202 int cond;
51203
51204 spin_lock_irq(&port->port_lock);
51205- cond = (port->port.count == 0) && !port->openclose;
51206+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
51207 spin_unlock_irq(&port->port_lock);
51208 return cond;
51209 }
51210@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
51211 /* if it's already open, start I/O ... and notify the serial
51212 * protocol about open/close status (connect/disconnect).
51213 */
51214- if (port->port.count) {
51215+ if (atomic_read(&port->port.count)) {
51216 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
51217 gs_start_io(port);
51218 if (gser->connect)
51219@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
51220
51221 port->port_usb = NULL;
51222 gser->ioport = NULL;
51223- if (port->port.count > 0 || port->openclose) {
51224+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
51225 wake_up_interruptible(&port->drain_wait);
51226 if (port->port.tty)
51227 tty_hangup(port->port.tty);
51228@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
51229
51230 /* finally, free any unused/unusable I/O buffers */
51231 spin_lock_irqsave(&port->port_lock, flags);
51232- if (port->port.count == 0 && !port->openclose)
51233+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
51234 gs_buf_free(&port->port_write_buf);
51235 gs_free_requests(gser->out, &port->read_pool, NULL);
51236 gs_free_requests(gser->out, &port->read_queue, NULL);
51237diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
51238index 835fc08..f8b22bf 100644
51239--- a/drivers/usb/host/ehci-hub.c
51240+++ b/drivers/usb/host/ehci-hub.c
51241@@ -762,7 +762,7 @@ static struct urb *request_single_step_set_feature_urb(
51242 urb->transfer_flags = URB_DIR_IN;
51243 usb_get_urb(urb);
51244 atomic_inc(&urb->use_count);
51245- atomic_inc(&urb->dev->urbnum);
51246+ atomic_inc_unchecked(&urb->dev->urbnum);
51247 urb->setup_dma = dma_map_single(
51248 hcd->self.controller,
51249 urb->setup_packet,
51250@@ -829,7 +829,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
51251 urb->status = -EINPROGRESS;
51252 usb_get_urb(urb);
51253 atomic_inc(&urb->use_count);
51254- atomic_inc(&urb->dev->urbnum);
51255+ atomic_inc_unchecked(&urb->dev->urbnum);
51256 retval = submit_single_step_set_feature(hcd, urb, 0);
51257 if (!retval && !wait_for_completion_timeout(&done,
51258 msecs_to_jiffies(2000))) {
51259diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
51260index ba6a5d6..f88f7f3 100644
51261--- a/drivers/usb/misc/appledisplay.c
51262+++ b/drivers/usb/misc/appledisplay.c
51263@@ -83,7 +83,7 @@ struct appledisplay {
51264 spinlock_t lock;
51265 };
51266
51267-static atomic_t count_displays = ATOMIC_INIT(0);
51268+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
51269 static struct workqueue_struct *wq;
51270
51271 static void appledisplay_complete(struct urb *urb)
51272@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
51273
51274 /* Register backlight device */
51275 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
51276- atomic_inc_return(&count_displays) - 1);
51277+ atomic_inc_return_unchecked(&count_displays) - 1);
51278 memset(&props, 0, sizeof(struct backlight_properties));
51279 props.type = BACKLIGHT_RAW;
51280 props.max_brightness = 0xff;
51281diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
51282index c69bb50..215ef37 100644
51283--- a/drivers/usb/serial/console.c
51284+++ b/drivers/usb/serial/console.c
51285@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
51286
51287 info->port = port;
51288
51289- ++port->port.count;
51290+ atomic_inc(&port->port.count);
51291 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
51292 if (serial->type->set_termios) {
51293 /*
51294@@ -170,7 +170,7 @@ static int usb_console_setup(struct console *co, char *options)
51295 }
51296 /* Now that any required fake tty operations are completed restore
51297 * the tty port count */
51298- --port->port.count;
51299+ atomic_dec(&port->port.count);
51300 /* The console is special in terms of closing the device so
51301 * indicate this port is now acting as a system console. */
51302 port->port.console = 1;
51303@@ -183,7 +183,7 @@ static int usb_console_setup(struct console *co, char *options)
51304 free_tty:
51305 kfree(tty);
51306 reset_open_count:
51307- port->port.count = 0;
51308+ atomic_set(&port->port.count, 0);
51309 usb_autopm_put_interface(serial->interface);
51310 error_get_interface:
51311 usb_serial_put(serial);
51312@@ -194,7 +194,7 @@ static int usb_console_setup(struct console *co, char *options)
51313 static void usb_console_write(struct console *co,
51314 const char *buf, unsigned count)
51315 {
51316- static struct usbcons_info *info = &usbcons_info;
51317+ struct usbcons_info *info = &usbcons_info;
51318 struct usb_serial_port *port = info->port;
51319 struct usb_serial *serial;
51320 int retval = -ENODEV;
51321diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
51322index 75f70f0..d467e1a 100644
51323--- a/drivers/usb/storage/usb.h
51324+++ b/drivers/usb/storage/usb.h
51325@@ -63,7 +63,7 @@ struct us_unusual_dev {
51326 __u8 useProtocol;
51327 __u8 useTransport;
51328 int (*initFunction)(struct us_data *);
51329-};
51330+} __do_const;
51331
51332
51333 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
51334diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
51335index e614f02..3fd60e2 100644
51336--- a/drivers/usb/wusbcore/wa-hc.h
51337+++ b/drivers/usb/wusbcore/wa-hc.h
51338@@ -225,7 +225,7 @@ struct wahc {
51339 spinlock_t xfer_list_lock;
51340 struct work_struct xfer_enqueue_work;
51341 struct work_struct xfer_error_work;
51342- atomic_t xfer_id_count;
51343+ atomic_unchecked_t xfer_id_count;
51344
51345 kernel_ulong_t quirks;
51346 };
51347@@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
51348 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
51349 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
51350 wa->dto_in_use = 0;
51351- atomic_set(&wa->xfer_id_count, 1);
51352+ atomic_set_unchecked(&wa->xfer_id_count, 1);
51353 }
51354
51355 /**
51356diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
51357index ed5abe8..7036400 100644
51358--- a/drivers/usb/wusbcore/wa-xfer.c
51359+++ b/drivers/usb/wusbcore/wa-xfer.c
51360@@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
51361 */
51362 static void wa_xfer_id_init(struct wa_xfer *xfer)
51363 {
51364- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
51365+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
51366 }
51367
51368 /* Return the xfer's ID. */
51369diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
51370index 1eab4ac..e21efc9 100644
51371--- a/drivers/vfio/vfio.c
51372+++ b/drivers/vfio/vfio.c
51373@@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
51374 return 0;
51375
51376 /* TODO Prevent device auto probing */
51377- WARN("Device %s added to live group %d!\n", dev_name(dev),
51378+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
51379 iommu_group_id(group->iommu_group));
51380
51381 return 0;
51382diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
51383index 5174eba..451e6bc 100644
51384--- a/drivers/vhost/vringh.c
51385+++ b/drivers/vhost/vringh.c
51386@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
51387 /* Userspace access helpers: in this case, addresses are really userspace. */
51388 static inline int getu16_user(u16 *val, const u16 *p)
51389 {
51390- return get_user(*val, (__force u16 __user *)p);
51391+ return get_user(*val, (u16 __force_user *)p);
51392 }
51393
51394 static inline int putu16_user(u16 *p, u16 val)
51395 {
51396- return put_user(val, (__force u16 __user *)p);
51397+ return put_user(val, (u16 __force_user *)p);
51398 }
51399
51400 static inline int copydesc_user(void *dst, const void *src, size_t len)
51401 {
51402- return copy_from_user(dst, (__force void __user *)src, len) ?
51403+ return copy_from_user(dst, (void __force_user *)src, len) ?
51404 -EFAULT : 0;
51405 }
51406
51407@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
51408 const struct vring_used_elem *src,
51409 unsigned int num)
51410 {
51411- return copy_to_user((__force void __user *)dst, src,
51412+ return copy_to_user((void __force_user *)dst, src,
51413 sizeof(*dst) * num) ? -EFAULT : 0;
51414 }
51415
51416 static inline int xfer_from_user(void *src, void *dst, size_t len)
51417 {
51418- return copy_from_user(dst, (__force void __user *)src, len) ?
51419+ return copy_from_user(dst, (void __force_user *)src, len) ?
51420 -EFAULT : 0;
51421 }
51422
51423 static inline int xfer_to_user(void *dst, void *src, size_t len)
51424 {
51425- return copy_to_user((__force void __user *)dst, src, len) ?
51426+ return copy_to_user((void __force_user *)dst, src, len) ?
51427 -EFAULT : 0;
51428 }
51429
51430@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
51431 vrh->last_used_idx = 0;
51432 vrh->vring.num = num;
51433 /* vring expects kernel addresses, but only used via accessors. */
51434- vrh->vring.desc = (__force struct vring_desc *)desc;
51435- vrh->vring.avail = (__force struct vring_avail *)avail;
51436- vrh->vring.used = (__force struct vring_used *)used;
51437+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
51438+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
51439+ vrh->vring.used = (__force_kernel struct vring_used *)used;
51440 return 0;
51441 }
51442 EXPORT_SYMBOL(vringh_init_user);
51443@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
51444
51445 static inline int putu16_kern(u16 *p, u16 val)
51446 {
51447- ACCESS_ONCE(*p) = val;
51448+ ACCESS_ONCE_RW(*p) = val;
51449 return 0;
51450 }
51451
51452diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
51453index 1b0b233..6f34c2c 100644
51454--- a/drivers/video/arcfb.c
51455+++ b/drivers/video/arcfb.c
51456@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
51457 return -ENOSPC;
51458
51459 err = 0;
51460- if ((count + p) > fbmemlength) {
51461+ if (count > (fbmemlength - p)) {
51462 count = fbmemlength - p;
51463 err = -ENOSPC;
51464 }
51465diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
51466index 12ca031..84a8a74 100644
51467--- a/drivers/video/aty/aty128fb.c
51468+++ b/drivers/video/aty/aty128fb.c
51469@@ -149,7 +149,7 @@ enum {
51470 };
51471
51472 /* Must match above enum */
51473-static char * const r128_family[] = {
51474+static const char * const r128_family[] = {
51475 "AGP",
51476 "PCI",
51477 "PRO AGP",
51478diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
51479index 28fafbf..ae91651 100644
51480--- a/drivers/video/aty/atyfb_base.c
51481+++ b/drivers/video/aty/atyfb_base.c
51482@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
51483 par->accel_flags = var->accel_flags; /* hack */
51484
51485 if (var->accel_flags) {
51486- info->fbops->fb_sync = atyfb_sync;
51487+ pax_open_kernel();
51488+ *(void **)&info->fbops->fb_sync = atyfb_sync;
51489+ pax_close_kernel();
51490 info->flags &= ~FBINFO_HWACCEL_DISABLED;
51491 } else {
51492- info->fbops->fb_sync = NULL;
51493+ pax_open_kernel();
51494+ *(void **)&info->fbops->fb_sync = NULL;
51495+ pax_close_kernel();
51496 info->flags |= FBINFO_HWACCEL_DISABLED;
51497 }
51498
51499diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
51500index 95ec042..e6affdd 100644
51501--- a/drivers/video/aty/mach64_cursor.c
51502+++ b/drivers/video/aty/mach64_cursor.c
51503@@ -7,6 +7,7 @@
51504 #include <linux/string.h>
51505
51506 #include <asm/io.h>
51507+#include <asm/pgtable.h>
51508
51509 #ifdef __sparc__
51510 #include <asm/fbio.h>
51511@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
51512 info->sprite.buf_align = 16; /* and 64 lines tall. */
51513 info->sprite.flags = FB_PIXMAP_IO;
51514
51515- info->fbops->fb_cursor = atyfb_cursor;
51516+ pax_open_kernel();
51517+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
51518+ pax_close_kernel();
51519
51520 return 0;
51521 }
51522diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
51523index 7592cc2..92feb56 100644
51524--- a/drivers/video/backlight/kb3886_bl.c
51525+++ b/drivers/video/backlight/kb3886_bl.c
51526@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
51527 static unsigned long kb3886bl_flags;
51528 #define KB3886BL_SUSPENDED 0x01
51529
51530-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
51531+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
51532 {
51533 .ident = "Sahara Touch-iT",
51534 .matches = {
51535diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
51536index 900aa4e..6d49418 100644
51537--- a/drivers/video/fb_defio.c
51538+++ b/drivers/video/fb_defio.c
51539@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
51540
51541 BUG_ON(!fbdefio);
51542 mutex_init(&fbdefio->lock);
51543- info->fbops->fb_mmap = fb_deferred_io_mmap;
51544+ pax_open_kernel();
51545+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
51546+ pax_close_kernel();
51547 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
51548 INIT_LIST_HEAD(&fbdefio->pagelist);
51549 if (fbdefio->delay == 0) /* set a default of 1 s */
51550@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
51551 page->mapping = NULL;
51552 }
51553
51554- info->fbops->fb_mmap = NULL;
51555+ *(void **)&info->fbops->fb_mmap = NULL;
51556 mutex_destroy(&fbdefio->lock);
51557 }
51558 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
51559diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
51560index 010d191..7b8235a 100644
51561--- a/drivers/video/fbmem.c
51562+++ b/drivers/video/fbmem.c
51563@@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
51564 image->dx += image->width + 8;
51565 }
51566 } else if (rotate == FB_ROTATE_UD) {
51567- for (x = 0; x < num && image->dx >= 0; x++) {
51568+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
51569 info->fbops->fb_imageblit(info, image);
51570 image->dx -= image->width + 8;
51571 }
51572@@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
51573 image->dy += image->height + 8;
51574 }
51575 } else if (rotate == FB_ROTATE_CCW) {
51576- for (x = 0; x < num && image->dy >= 0; x++) {
51577+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
51578 info->fbops->fb_imageblit(info, image);
51579 image->dy -= image->height + 8;
51580 }
51581@@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
51582 return -EFAULT;
51583 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
51584 return -EINVAL;
51585- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
51586+ if (con2fb.framebuffer >= FB_MAX)
51587 return -EINVAL;
51588 if (!registered_fb[con2fb.framebuffer])
51589 request_module("fb%d", con2fb.framebuffer);
51590@@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
51591 __u32 data;
51592 int err;
51593
51594- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
51595+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
51596
51597 data = (__u32) (unsigned long) fix->smem_start;
51598 err |= put_user(data, &fix32->smem_start);
51599diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
51600index 130708f..cdac1a9 100644
51601--- a/drivers/video/hyperv_fb.c
51602+++ b/drivers/video/hyperv_fb.c
51603@@ -233,7 +233,7 @@ static uint screen_fb_size;
51604 static inline int synthvid_send(struct hv_device *hdev,
51605 struct synthvid_msg *msg)
51606 {
51607- static atomic64_t request_id = ATOMIC64_INIT(0);
51608+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
51609 int ret;
51610
51611 msg->pipe_hdr.type = PIPE_MSG_DATA;
51612@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
51613
51614 ret = vmbus_sendpacket(hdev->channel, msg,
51615 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
51616- atomic64_inc_return(&request_id),
51617+ atomic64_inc_return_unchecked(&request_id),
51618 VM_PKT_DATA_INBAND, 0);
51619
51620 if (ret)
51621diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
51622index 7672d2e..b56437f 100644
51623--- a/drivers/video/i810/i810_accel.c
51624+++ b/drivers/video/i810/i810_accel.c
51625@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
51626 }
51627 }
51628 printk("ringbuffer lockup!!!\n");
51629+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
51630 i810_report_error(mmio);
51631 par->dev_flags |= LOCKUP;
51632 info->pixmap.scan_align = 1;
51633diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
51634index 3c14e43..2630570 100644
51635--- a/drivers/video/logo/logo_linux_clut224.ppm
51636+++ b/drivers/video/logo/logo_linux_clut224.ppm
51637@@ -2,1603 +2,1123 @@ P3
51638 # Standard 224-color Linux logo
51639 80 80
51640 255
51641- 0 0 0 0 0 0 0 0 0 0 0 0
51642- 0 0 0 0 0 0 0 0 0 0 0 0
51643- 0 0 0 0 0 0 0 0 0 0 0 0
51644- 0 0 0 0 0 0 0 0 0 0 0 0
51645- 0 0 0 0 0 0 0 0 0 0 0 0
51646- 0 0 0 0 0 0 0 0 0 0 0 0
51647- 0 0 0 0 0 0 0 0 0 0 0 0
51648- 0 0 0 0 0 0 0 0 0 0 0 0
51649- 0 0 0 0 0 0 0 0 0 0 0 0
51650- 6 6 6 6 6 6 10 10 10 10 10 10
51651- 10 10 10 6 6 6 6 6 6 6 6 6
51652- 0 0 0 0 0 0 0 0 0 0 0 0
51653- 0 0 0 0 0 0 0 0 0 0 0 0
51654- 0 0 0 0 0 0 0 0 0 0 0 0
51655- 0 0 0 0 0 0 0 0 0 0 0 0
51656- 0 0 0 0 0 0 0 0 0 0 0 0
51657- 0 0 0 0 0 0 0 0 0 0 0 0
51658- 0 0 0 0 0 0 0 0 0 0 0 0
51659- 0 0 0 0 0 0 0 0 0 0 0 0
51660- 0 0 0 0 0 0 0 0 0 0 0 0
51661- 0 0 0 0 0 0 0 0 0 0 0 0
51662- 0 0 0 0 0 0 0 0 0 0 0 0
51663- 0 0 0 0 0 0 0 0 0 0 0 0
51664- 0 0 0 0 0 0 0 0 0 0 0 0
51665- 0 0 0 0 0 0 0 0 0 0 0 0
51666- 0 0 0 0 0 0 0 0 0 0 0 0
51667- 0 0 0 0 0 0 0 0 0 0 0 0
51668- 0 0 0 0 0 0 0 0 0 0 0 0
51669- 0 0 0 6 6 6 10 10 10 14 14 14
51670- 22 22 22 26 26 26 30 30 30 34 34 34
51671- 30 30 30 30 30 30 26 26 26 18 18 18
51672- 14 14 14 10 10 10 6 6 6 0 0 0
51673- 0 0 0 0 0 0 0 0 0 0 0 0
51674- 0 0 0 0 0 0 0 0 0 0 0 0
51675- 0 0 0 0 0 0 0 0 0 0 0 0
51676- 0 0 0 0 0 0 0 0 0 0 0 0
51677- 0 0 0 0 0 0 0 0 0 0 0 0
51678- 0 0 0 0 0 0 0 0 0 0 0 0
51679- 0 0 0 0 0 0 0 0 0 0 0 0
51680- 0 0 0 0 0 0 0 0 0 0 0 0
51681- 0 0 0 0 0 0 0 0 0 0 0 0
51682- 0 0 0 0 0 1 0 0 1 0 0 0
51683- 0 0 0 0 0 0 0 0 0 0 0 0
51684- 0 0 0 0 0 0 0 0 0 0 0 0
51685- 0 0 0 0 0 0 0 0 0 0 0 0
51686- 0 0 0 0 0 0 0 0 0 0 0 0
51687- 0 0 0 0 0 0 0 0 0 0 0 0
51688- 0 0 0 0 0 0 0 0 0 0 0 0
51689- 6 6 6 14 14 14 26 26 26 42 42 42
51690- 54 54 54 66 66 66 78 78 78 78 78 78
51691- 78 78 78 74 74 74 66 66 66 54 54 54
51692- 42 42 42 26 26 26 18 18 18 10 10 10
51693- 6 6 6 0 0 0 0 0 0 0 0 0
51694- 0 0 0 0 0 0 0 0 0 0 0 0
51695- 0 0 0 0 0 0 0 0 0 0 0 0
51696- 0 0 0 0 0 0 0 0 0 0 0 0
51697- 0 0 0 0 0 0 0 0 0 0 0 0
51698- 0 0 0 0 0 0 0 0 0 0 0 0
51699- 0 0 0 0 0 0 0 0 0 0 0 0
51700- 0 0 0 0 0 0 0 0 0 0 0 0
51701- 0 0 0 0 0 0 0 0 0 0 0 0
51702- 0 0 1 0 0 0 0 0 0 0 0 0
51703- 0 0 0 0 0 0 0 0 0 0 0 0
51704- 0 0 0 0 0 0 0 0 0 0 0 0
51705- 0 0 0 0 0 0 0 0 0 0 0 0
51706- 0 0 0 0 0 0 0 0 0 0 0 0
51707- 0 0 0 0 0 0 0 0 0 0 0 0
51708- 0 0 0 0 0 0 0 0 0 10 10 10
51709- 22 22 22 42 42 42 66 66 66 86 86 86
51710- 66 66 66 38 38 38 38 38 38 22 22 22
51711- 26 26 26 34 34 34 54 54 54 66 66 66
51712- 86 86 86 70 70 70 46 46 46 26 26 26
51713- 14 14 14 6 6 6 0 0 0 0 0 0
51714- 0 0 0 0 0 0 0 0 0 0 0 0
51715- 0 0 0 0 0 0 0 0 0 0 0 0
51716- 0 0 0 0 0 0 0 0 0 0 0 0
51717- 0 0 0 0 0 0 0 0 0 0 0 0
51718- 0 0 0 0 0 0 0 0 0 0 0 0
51719- 0 0 0 0 0 0 0 0 0 0 0 0
51720- 0 0 0 0 0 0 0 0 0 0 0 0
51721- 0 0 0 0 0 0 0 0 0 0 0 0
51722- 0 0 1 0 0 1 0 0 1 0 0 0
51723- 0 0 0 0 0 0 0 0 0 0 0 0
51724- 0 0 0 0 0 0 0 0 0 0 0 0
51725- 0 0 0 0 0 0 0 0 0 0 0 0
51726- 0 0 0 0 0 0 0 0 0 0 0 0
51727- 0 0 0 0 0 0 0 0 0 0 0 0
51728- 0 0 0 0 0 0 10 10 10 26 26 26
51729- 50 50 50 82 82 82 58 58 58 6 6 6
51730- 2 2 6 2 2 6 2 2 6 2 2 6
51731- 2 2 6 2 2 6 2 2 6 2 2 6
51732- 6 6 6 54 54 54 86 86 86 66 66 66
51733- 38 38 38 18 18 18 6 6 6 0 0 0
51734- 0 0 0 0 0 0 0 0 0 0 0 0
51735- 0 0 0 0 0 0 0 0 0 0 0 0
51736- 0 0 0 0 0 0 0 0 0 0 0 0
51737- 0 0 0 0 0 0 0 0 0 0 0 0
51738- 0 0 0 0 0 0 0 0 0 0 0 0
51739- 0 0 0 0 0 0 0 0 0 0 0 0
51740- 0 0 0 0 0 0 0 0 0 0 0 0
51741- 0 0 0 0 0 0 0 0 0 0 0 0
51742- 0 0 0 0 0 0 0 0 0 0 0 0
51743- 0 0 0 0 0 0 0 0 0 0 0 0
51744- 0 0 0 0 0 0 0 0 0 0 0 0
51745- 0 0 0 0 0 0 0 0 0 0 0 0
51746- 0 0 0 0 0 0 0 0 0 0 0 0
51747- 0 0 0 0 0 0 0 0 0 0 0 0
51748- 0 0 0 6 6 6 22 22 22 50 50 50
51749- 78 78 78 34 34 34 2 2 6 2 2 6
51750- 2 2 6 2 2 6 2 2 6 2 2 6
51751- 2 2 6 2 2 6 2 2 6 2 2 6
51752- 2 2 6 2 2 6 6 6 6 70 70 70
51753- 78 78 78 46 46 46 22 22 22 6 6 6
51754- 0 0 0 0 0 0 0 0 0 0 0 0
51755- 0 0 0 0 0 0 0 0 0 0 0 0
51756- 0 0 0 0 0 0 0 0 0 0 0 0
51757- 0 0 0 0 0 0 0 0 0 0 0 0
51758- 0 0 0 0 0 0 0 0 0 0 0 0
51759- 0 0 0 0 0 0 0 0 0 0 0 0
51760- 0 0 0 0 0 0 0 0 0 0 0 0
51761- 0 0 0 0 0 0 0 0 0 0 0 0
51762- 0 0 1 0 0 1 0 0 1 0 0 0
51763- 0 0 0 0 0 0 0 0 0 0 0 0
51764- 0 0 0 0 0 0 0 0 0 0 0 0
51765- 0 0 0 0 0 0 0 0 0 0 0 0
51766- 0 0 0 0 0 0 0 0 0 0 0 0
51767- 0 0 0 0 0 0 0 0 0 0 0 0
51768- 6 6 6 18 18 18 42 42 42 82 82 82
51769- 26 26 26 2 2 6 2 2 6 2 2 6
51770- 2 2 6 2 2 6 2 2 6 2 2 6
51771- 2 2 6 2 2 6 2 2 6 14 14 14
51772- 46 46 46 34 34 34 6 6 6 2 2 6
51773- 42 42 42 78 78 78 42 42 42 18 18 18
51774- 6 6 6 0 0 0 0 0 0 0 0 0
51775- 0 0 0 0 0 0 0 0 0 0 0 0
51776- 0 0 0 0 0 0 0 0 0 0 0 0
51777- 0 0 0 0 0 0 0 0 0 0 0 0
51778- 0 0 0 0 0 0 0 0 0 0 0 0
51779- 0 0 0 0 0 0 0 0 0 0 0 0
51780- 0 0 0 0 0 0 0 0 0 0 0 0
51781- 0 0 0 0 0 0 0 0 0 0 0 0
51782- 0 0 1 0 0 0 0 0 1 0 0 0
51783- 0 0 0 0 0 0 0 0 0 0 0 0
51784- 0 0 0 0 0 0 0 0 0 0 0 0
51785- 0 0 0 0 0 0 0 0 0 0 0 0
51786- 0 0 0 0 0 0 0 0 0 0 0 0
51787- 0 0 0 0 0 0 0 0 0 0 0 0
51788- 10 10 10 30 30 30 66 66 66 58 58 58
51789- 2 2 6 2 2 6 2 2 6 2 2 6
51790- 2 2 6 2 2 6 2 2 6 2 2 6
51791- 2 2 6 2 2 6 2 2 6 26 26 26
51792- 86 86 86 101 101 101 46 46 46 10 10 10
51793- 2 2 6 58 58 58 70 70 70 34 34 34
51794- 10 10 10 0 0 0 0 0 0 0 0 0
51795- 0 0 0 0 0 0 0 0 0 0 0 0
51796- 0 0 0 0 0 0 0 0 0 0 0 0
51797- 0 0 0 0 0 0 0 0 0 0 0 0
51798- 0 0 0 0 0 0 0 0 0 0 0 0
51799- 0 0 0 0 0 0 0 0 0 0 0 0
51800- 0 0 0 0 0 0 0 0 0 0 0 0
51801- 0 0 0 0 0 0 0 0 0 0 0 0
51802- 0 0 1 0 0 1 0 0 1 0 0 0
51803- 0 0 0 0 0 0 0 0 0 0 0 0
51804- 0 0 0 0 0 0 0 0 0 0 0 0
51805- 0 0 0 0 0 0 0 0 0 0 0 0
51806- 0 0 0 0 0 0 0 0 0 0 0 0
51807- 0 0 0 0 0 0 0 0 0 0 0 0
51808- 14 14 14 42 42 42 86 86 86 10 10 10
51809- 2 2 6 2 2 6 2 2 6 2 2 6
51810- 2 2 6 2 2 6 2 2 6 2 2 6
51811- 2 2 6 2 2 6 2 2 6 30 30 30
51812- 94 94 94 94 94 94 58 58 58 26 26 26
51813- 2 2 6 6 6 6 78 78 78 54 54 54
51814- 22 22 22 6 6 6 0 0 0 0 0 0
51815- 0 0 0 0 0 0 0 0 0 0 0 0
51816- 0 0 0 0 0 0 0 0 0 0 0 0
51817- 0 0 0 0 0 0 0 0 0 0 0 0
51818- 0 0 0 0 0 0 0 0 0 0 0 0
51819- 0 0 0 0 0 0 0 0 0 0 0 0
51820- 0 0 0 0 0 0 0 0 0 0 0 0
51821- 0 0 0 0 0 0 0 0 0 0 0 0
51822- 0 0 0 0 0 0 0 0 0 0 0 0
51823- 0 0 0 0 0 0 0 0 0 0 0 0
51824- 0 0 0 0 0 0 0 0 0 0 0 0
51825- 0 0 0 0 0 0 0 0 0 0 0 0
51826- 0 0 0 0 0 0 0 0 0 0 0 0
51827- 0 0 0 0 0 0 0 0 0 6 6 6
51828- 22 22 22 62 62 62 62 62 62 2 2 6
51829- 2 2 6 2 2 6 2 2 6 2 2 6
51830- 2 2 6 2 2 6 2 2 6 2 2 6
51831- 2 2 6 2 2 6 2 2 6 26 26 26
51832- 54 54 54 38 38 38 18 18 18 10 10 10
51833- 2 2 6 2 2 6 34 34 34 82 82 82
51834- 38 38 38 14 14 14 0 0 0 0 0 0
51835- 0 0 0 0 0 0 0 0 0 0 0 0
51836- 0 0 0 0 0 0 0 0 0 0 0 0
51837- 0 0 0 0 0 0 0 0 0 0 0 0
51838- 0 0 0 0 0 0 0 0 0 0 0 0
51839- 0 0 0 0 0 0 0 0 0 0 0 0
51840- 0 0 0 0 0 0 0 0 0 0 0 0
51841- 0 0 0 0 0 0 0 0 0 0 0 0
51842- 0 0 0 0 0 1 0 0 1 0 0 0
51843- 0 0 0 0 0 0 0 0 0 0 0 0
51844- 0 0 0 0 0 0 0 0 0 0 0 0
51845- 0 0 0 0 0 0 0 0 0 0 0 0
51846- 0 0 0 0 0 0 0 0 0 0 0 0
51847- 0 0 0 0 0 0 0 0 0 6 6 6
51848- 30 30 30 78 78 78 30 30 30 2 2 6
51849- 2 2 6 2 2 6 2 2 6 2 2 6
51850- 2 2 6 2 2 6 2 2 6 2 2 6
51851- 2 2 6 2 2 6 2 2 6 10 10 10
51852- 10 10 10 2 2 6 2 2 6 2 2 6
51853- 2 2 6 2 2 6 2 2 6 78 78 78
51854- 50 50 50 18 18 18 6 6 6 0 0 0
51855- 0 0 0 0 0 0 0 0 0 0 0 0
51856- 0 0 0 0 0 0 0 0 0 0 0 0
51857- 0 0 0 0 0 0 0 0 0 0 0 0
51858- 0 0 0 0 0 0 0 0 0 0 0 0
51859- 0 0 0 0 0 0 0 0 0 0 0 0
51860- 0 0 0 0 0 0 0 0 0 0 0 0
51861- 0 0 0 0 0 0 0 0 0 0 0 0
51862- 0 0 1 0 0 0 0 0 0 0 0 0
51863- 0 0 0 0 0 0 0 0 0 0 0 0
51864- 0 0 0 0 0 0 0 0 0 0 0 0
51865- 0 0 0 0 0 0 0 0 0 0 0 0
51866- 0 0 0 0 0 0 0 0 0 0 0 0
51867- 0 0 0 0 0 0 0 0 0 10 10 10
51868- 38 38 38 86 86 86 14 14 14 2 2 6
51869- 2 2 6 2 2 6 2 2 6 2 2 6
51870- 2 2 6 2 2 6 2 2 6 2 2 6
51871- 2 2 6 2 2 6 2 2 6 2 2 6
51872- 2 2 6 2 2 6 2 2 6 2 2 6
51873- 2 2 6 2 2 6 2 2 6 54 54 54
51874- 66 66 66 26 26 26 6 6 6 0 0 0
51875- 0 0 0 0 0 0 0 0 0 0 0 0
51876- 0 0 0 0 0 0 0 0 0 0 0 0
51877- 0 0 0 0 0 0 0 0 0 0 0 0
51878- 0 0 0 0 0 0 0 0 0 0 0 0
51879- 0 0 0 0 0 0 0 0 0 0 0 0
51880- 0 0 0 0 0 0 0 0 0 0 0 0
51881- 0 0 0 0 0 0 0 0 0 0 0 0
51882- 0 0 0 0 0 1 0 0 1 0 0 0
51883- 0 0 0 0 0 0 0 0 0 0 0 0
51884- 0 0 0 0 0 0 0 0 0 0 0 0
51885- 0 0 0 0 0 0 0 0 0 0 0 0
51886- 0 0 0 0 0 0 0 0 0 0 0 0
51887- 0 0 0 0 0 0 0 0 0 14 14 14
51888- 42 42 42 82 82 82 2 2 6 2 2 6
51889- 2 2 6 6 6 6 10 10 10 2 2 6
51890- 2 2 6 2 2 6 2 2 6 2 2 6
51891- 2 2 6 2 2 6 2 2 6 6 6 6
51892- 14 14 14 10 10 10 2 2 6 2 2 6
51893- 2 2 6 2 2 6 2 2 6 18 18 18
51894- 82 82 82 34 34 34 10 10 10 0 0 0
51895- 0 0 0 0 0 0 0 0 0 0 0 0
51896- 0 0 0 0 0 0 0 0 0 0 0 0
51897- 0 0 0 0 0 0 0 0 0 0 0 0
51898- 0 0 0 0 0 0 0 0 0 0 0 0
51899- 0 0 0 0 0 0 0 0 0 0 0 0
51900- 0 0 0 0 0 0 0 0 0 0 0 0
51901- 0 0 0 0 0 0 0 0 0 0 0 0
51902- 0 0 1 0 0 0 0 0 0 0 0 0
51903- 0 0 0 0 0 0 0 0 0 0 0 0
51904- 0 0 0 0 0 0 0 0 0 0 0 0
51905- 0 0 0 0 0 0 0 0 0 0 0 0
51906- 0 0 0 0 0 0 0 0 0 0 0 0
51907- 0 0 0 0 0 0 0 0 0 14 14 14
51908- 46 46 46 86 86 86 2 2 6 2 2 6
51909- 6 6 6 6 6 6 22 22 22 34 34 34
51910- 6 6 6 2 2 6 2 2 6 2 2 6
51911- 2 2 6 2 2 6 18 18 18 34 34 34
51912- 10 10 10 50 50 50 22 22 22 2 2 6
51913- 2 2 6 2 2 6 2 2 6 10 10 10
51914- 86 86 86 42 42 42 14 14 14 0 0 0
51915- 0 0 0 0 0 0 0 0 0 0 0 0
51916- 0 0 0 0 0 0 0 0 0 0 0 0
51917- 0 0 0 0 0 0 0 0 0 0 0 0
51918- 0 0 0 0 0 0 0 0 0 0 0 0
51919- 0 0 0 0 0 0 0 0 0 0 0 0
51920- 0 0 0 0 0 0 0 0 0 0 0 0
51921- 0 0 0 0 0 0 0 0 0 0 0 0
51922- 0 0 1 0 0 1 0 0 1 0 0 0
51923- 0 0 0 0 0 0 0 0 0 0 0 0
51924- 0 0 0 0 0 0 0 0 0 0 0 0
51925- 0 0 0 0 0 0 0 0 0 0 0 0
51926- 0 0 0 0 0 0 0 0 0 0 0 0
51927- 0 0 0 0 0 0 0 0 0 14 14 14
51928- 46 46 46 86 86 86 2 2 6 2 2 6
51929- 38 38 38 116 116 116 94 94 94 22 22 22
51930- 22 22 22 2 2 6 2 2 6 2 2 6
51931- 14 14 14 86 86 86 138 138 138 162 162 162
51932-154 154 154 38 38 38 26 26 26 6 6 6
51933- 2 2 6 2 2 6 2 2 6 2 2 6
51934- 86 86 86 46 46 46 14 14 14 0 0 0
51935- 0 0 0 0 0 0 0 0 0 0 0 0
51936- 0 0 0 0 0 0 0 0 0 0 0 0
51937- 0 0 0 0 0 0 0 0 0 0 0 0
51938- 0 0 0 0 0 0 0 0 0 0 0 0
51939- 0 0 0 0 0 0 0 0 0 0 0 0
51940- 0 0 0 0 0 0 0 0 0 0 0 0
51941- 0 0 0 0 0 0 0 0 0 0 0 0
51942- 0 0 0 0 0 0 0 0 0 0 0 0
51943- 0 0 0 0 0 0 0 0 0 0 0 0
51944- 0 0 0 0 0 0 0 0 0 0 0 0
51945- 0 0 0 0 0 0 0 0 0 0 0 0
51946- 0 0 0 0 0 0 0 0 0 0 0 0
51947- 0 0 0 0 0 0 0 0 0 14 14 14
51948- 46 46 46 86 86 86 2 2 6 14 14 14
51949-134 134 134 198 198 198 195 195 195 116 116 116
51950- 10 10 10 2 2 6 2 2 6 6 6 6
51951-101 98 89 187 187 187 210 210 210 218 218 218
51952-214 214 214 134 134 134 14 14 14 6 6 6
51953- 2 2 6 2 2 6 2 2 6 2 2 6
51954- 86 86 86 50 50 50 18 18 18 6 6 6
51955- 0 0 0 0 0 0 0 0 0 0 0 0
51956- 0 0 0 0 0 0 0 0 0 0 0 0
51957- 0 0 0 0 0 0 0 0 0 0 0 0
51958- 0 0 0 0 0 0 0 0 0 0 0 0
51959- 0 0 0 0 0 0 0 0 0 0 0 0
51960- 0 0 0 0 0 0 0 0 0 0 0 0
51961- 0 0 0 0 0 0 0 0 1 0 0 0
51962- 0 0 1 0 0 1 0 0 1 0 0 0
51963- 0 0 0 0 0 0 0 0 0 0 0 0
51964- 0 0 0 0 0 0 0 0 0 0 0 0
51965- 0 0 0 0 0 0 0 0 0 0 0 0
51966- 0 0 0 0 0 0 0 0 0 0 0 0
51967- 0 0 0 0 0 0 0 0 0 14 14 14
51968- 46 46 46 86 86 86 2 2 6 54 54 54
51969-218 218 218 195 195 195 226 226 226 246 246 246
51970- 58 58 58 2 2 6 2 2 6 30 30 30
51971-210 210 210 253 253 253 174 174 174 123 123 123
51972-221 221 221 234 234 234 74 74 74 2 2 6
51973- 2 2 6 2 2 6 2 2 6 2 2 6
51974- 70 70 70 58 58 58 22 22 22 6 6 6
51975- 0 0 0 0 0 0 0 0 0 0 0 0
51976- 0 0 0 0 0 0 0 0 0 0 0 0
51977- 0 0 0 0 0 0 0 0 0 0 0 0
51978- 0 0 0 0 0 0 0 0 0 0 0 0
51979- 0 0 0 0 0 0 0 0 0 0 0 0
51980- 0 0 0 0 0 0 0 0 0 0 0 0
51981- 0 0 0 0 0 0 0 0 0 0 0 0
51982- 0 0 0 0 0 0 0 0 0 0 0 0
51983- 0 0 0 0 0 0 0 0 0 0 0 0
51984- 0 0 0 0 0 0 0 0 0 0 0 0
51985- 0 0 0 0 0 0 0 0 0 0 0 0
51986- 0 0 0 0 0 0 0 0 0 0 0 0
51987- 0 0 0 0 0 0 0 0 0 14 14 14
51988- 46 46 46 82 82 82 2 2 6 106 106 106
51989-170 170 170 26 26 26 86 86 86 226 226 226
51990-123 123 123 10 10 10 14 14 14 46 46 46
51991-231 231 231 190 190 190 6 6 6 70 70 70
51992- 90 90 90 238 238 238 158 158 158 2 2 6
51993- 2 2 6 2 2 6 2 2 6 2 2 6
51994- 70 70 70 58 58 58 22 22 22 6 6 6
51995- 0 0 0 0 0 0 0 0 0 0 0 0
51996- 0 0 0 0 0 0 0 0 0 0 0 0
51997- 0 0 0 0 0 0 0 0 0 0 0 0
51998- 0 0 0 0 0 0 0 0 0 0 0 0
51999- 0 0 0 0 0 0 0 0 0 0 0 0
52000- 0 0 0 0 0 0 0 0 0 0 0 0
52001- 0 0 0 0 0 0 0 0 1 0 0 0
52002- 0 0 1 0 0 1 0 0 1 0 0 0
52003- 0 0 0 0 0 0 0 0 0 0 0 0
52004- 0 0 0 0 0 0 0 0 0 0 0 0
52005- 0 0 0 0 0 0 0 0 0 0 0 0
52006- 0 0 0 0 0 0 0 0 0 0 0 0
52007- 0 0 0 0 0 0 0 0 0 14 14 14
52008- 42 42 42 86 86 86 6 6 6 116 116 116
52009-106 106 106 6 6 6 70 70 70 149 149 149
52010-128 128 128 18 18 18 38 38 38 54 54 54
52011-221 221 221 106 106 106 2 2 6 14 14 14
52012- 46 46 46 190 190 190 198 198 198 2 2 6
52013- 2 2 6 2 2 6 2 2 6 2 2 6
52014- 74 74 74 62 62 62 22 22 22 6 6 6
52015- 0 0 0 0 0 0 0 0 0 0 0 0
52016- 0 0 0 0 0 0 0 0 0 0 0 0
52017- 0 0 0 0 0 0 0 0 0 0 0 0
52018- 0 0 0 0 0 0 0 0 0 0 0 0
52019- 0 0 0 0 0 0 0 0 0 0 0 0
52020- 0 0 0 0 0 0 0 0 0 0 0 0
52021- 0 0 0 0 0 0 0 0 1 0 0 0
52022- 0 0 1 0 0 0 0 0 1 0 0 0
52023- 0 0 0 0 0 0 0 0 0 0 0 0
52024- 0 0 0 0 0 0 0 0 0 0 0 0
52025- 0 0 0 0 0 0 0 0 0 0 0 0
52026- 0 0 0 0 0 0 0 0 0 0 0 0
52027- 0 0 0 0 0 0 0 0 0 14 14 14
52028- 42 42 42 94 94 94 14 14 14 101 101 101
52029-128 128 128 2 2 6 18 18 18 116 116 116
52030-118 98 46 121 92 8 121 92 8 98 78 10
52031-162 162 162 106 106 106 2 2 6 2 2 6
52032- 2 2 6 195 195 195 195 195 195 6 6 6
52033- 2 2 6 2 2 6 2 2 6 2 2 6
52034- 74 74 74 62 62 62 22 22 22 6 6 6
52035- 0 0 0 0 0 0 0 0 0 0 0 0
52036- 0 0 0 0 0 0 0 0 0 0 0 0
52037- 0 0 0 0 0 0 0 0 0 0 0 0
52038- 0 0 0 0 0 0 0 0 0 0 0 0
52039- 0 0 0 0 0 0 0 0 0 0 0 0
52040- 0 0 0 0 0 0 0 0 0 0 0 0
52041- 0 0 0 0 0 0 0 0 1 0 0 1
52042- 0 0 1 0 0 0 0 0 1 0 0 0
52043- 0 0 0 0 0 0 0 0 0 0 0 0
52044- 0 0 0 0 0 0 0 0 0 0 0 0
52045- 0 0 0 0 0 0 0 0 0 0 0 0
52046- 0 0 0 0 0 0 0 0 0 0 0 0
52047- 0 0 0 0 0 0 0 0 0 10 10 10
52048- 38 38 38 90 90 90 14 14 14 58 58 58
52049-210 210 210 26 26 26 54 38 6 154 114 10
52050-226 170 11 236 186 11 225 175 15 184 144 12
52051-215 174 15 175 146 61 37 26 9 2 2 6
52052- 70 70 70 246 246 246 138 138 138 2 2 6
52053- 2 2 6 2 2 6 2 2 6 2 2 6
52054- 70 70 70 66 66 66 26 26 26 6 6 6
52055- 0 0 0 0 0 0 0 0 0 0 0 0
52056- 0 0 0 0 0 0 0 0 0 0 0 0
52057- 0 0 0 0 0 0 0 0 0 0 0 0
52058- 0 0 0 0 0 0 0 0 0 0 0 0
52059- 0 0 0 0 0 0 0 0 0 0 0 0
52060- 0 0 0 0 0 0 0 0 0 0 0 0
52061- 0 0 0 0 0 0 0 0 0 0 0 0
52062- 0 0 0 0 0 0 0 0 0 0 0 0
52063- 0 0 0 0 0 0 0 0 0 0 0 0
52064- 0 0 0 0 0 0 0 0 0 0 0 0
52065- 0 0 0 0 0 0 0 0 0 0 0 0
52066- 0 0 0 0 0 0 0 0 0 0 0 0
52067- 0 0 0 0 0 0 0 0 0 10 10 10
52068- 38 38 38 86 86 86 14 14 14 10 10 10
52069-195 195 195 188 164 115 192 133 9 225 175 15
52070-239 182 13 234 190 10 232 195 16 232 200 30
52071-245 207 45 241 208 19 232 195 16 184 144 12
52072-218 194 134 211 206 186 42 42 42 2 2 6
52073- 2 2 6 2 2 6 2 2 6 2 2 6
52074- 50 50 50 74 74 74 30 30 30 6 6 6
52075- 0 0 0 0 0 0 0 0 0 0 0 0
52076- 0 0 0 0 0 0 0 0 0 0 0 0
52077- 0 0 0 0 0 0 0 0 0 0 0 0
52078- 0 0 0 0 0 0 0 0 0 0 0 0
52079- 0 0 0 0 0 0 0 0 0 0 0 0
52080- 0 0 0 0 0 0 0 0 0 0 0 0
52081- 0 0 0 0 0 0 0 0 0 0 0 0
52082- 0 0 0 0 0 0 0 0 0 0 0 0
52083- 0 0 0 0 0 0 0 0 0 0 0 0
52084- 0 0 0 0 0 0 0 0 0 0 0 0
52085- 0 0 0 0 0 0 0 0 0 0 0 0
52086- 0 0 0 0 0 0 0 0 0 0 0 0
52087- 0 0 0 0 0 0 0 0 0 10 10 10
52088- 34 34 34 86 86 86 14 14 14 2 2 6
52089-121 87 25 192 133 9 219 162 10 239 182 13
52090-236 186 11 232 195 16 241 208 19 244 214 54
52091-246 218 60 246 218 38 246 215 20 241 208 19
52092-241 208 19 226 184 13 121 87 25 2 2 6
52093- 2 2 6 2 2 6 2 2 6 2 2 6
52094- 50 50 50 82 82 82 34 34 34 10 10 10
52095- 0 0 0 0 0 0 0 0 0 0 0 0
52096- 0 0 0 0 0 0 0 0 0 0 0 0
52097- 0 0 0 0 0 0 0 0 0 0 0 0
52098- 0 0 0 0 0 0 0 0 0 0 0 0
52099- 0 0 0 0 0 0 0 0 0 0 0 0
52100- 0 0 0 0 0 0 0 0 0 0 0 0
52101- 0 0 0 0 0 0 0 0 0 0 0 0
52102- 0 0 0 0 0 0 0 0 0 0 0 0
52103- 0 0 0 0 0 0 0 0 0 0 0 0
52104- 0 0 0 0 0 0 0 0 0 0 0 0
52105- 0 0 0 0 0 0 0 0 0 0 0 0
52106- 0 0 0 0 0 0 0 0 0 0 0 0
52107- 0 0 0 0 0 0 0 0 0 10 10 10
52108- 34 34 34 82 82 82 30 30 30 61 42 6
52109-180 123 7 206 145 10 230 174 11 239 182 13
52110-234 190 10 238 202 15 241 208 19 246 218 74
52111-246 218 38 246 215 20 246 215 20 246 215 20
52112-226 184 13 215 174 15 184 144 12 6 6 6
52113- 2 2 6 2 2 6 2 2 6 2 2 6
52114- 26 26 26 94 94 94 42 42 42 14 14 14
52115- 0 0 0 0 0 0 0 0 0 0 0 0
52116- 0 0 0 0 0 0 0 0 0 0 0 0
52117- 0 0 0 0 0 0 0 0 0 0 0 0
52118- 0 0 0 0 0 0 0 0 0 0 0 0
52119- 0 0 0 0 0 0 0 0 0 0 0 0
52120- 0 0 0 0 0 0 0 0 0 0 0 0
52121- 0 0 0 0 0 0 0 0 0 0 0 0
52122- 0 0 0 0 0 0 0 0 0 0 0 0
52123- 0 0 0 0 0 0 0 0 0 0 0 0
52124- 0 0 0 0 0 0 0 0 0 0 0 0
52125- 0 0 0 0 0 0 0 0 0 0 0 0
52126- 0 0 0 0 0 0 0 0 0 0 0 0
52127- 0 0 0 0 0 0 0 0 0 10 10 10
52128- 30 30 30 78 78 78 50 50 50 104 69 6
52129-192 133 9 216 158 10 236 178 12 236 186 11
52130-232 195 16 241 208 19 244 214 54 245 215 43
52131-246 215 20 246 215 20 241 208 19 198 155 10
52132-200 144 11 216 158 10 156 118 10 2 2 6
52133- 2 2 6 2 2 6 2 2 6 2 2 6
52134- 6 6 6 90 90 90 54 54 54 18 18 18
52135- 6 6 6 0 0 0 0 0 0 0 0 0
52136- 0 0 0 0 0 0 0 0 0 0 0 0
52137- 0 0 0 0 0 0 0 0 0 0 0 0
52138- 0 0 0 0 0 0 0 0 0 0 0 0
52139- 0 0 0 0 0 0 0 0 0 0 0 0
52140- 0 0 0 0 0 0 0 0 0 0 0 0
52141- 0 0 0 0 0 0 0 0 0 0 0 0
52142- 0 0 0 0 0 0 0 0 0 0 0 0
52143- 0 0 0 0 0 0 0 0 0 0 0 0
52144- 0 0 0 0 0 0 0 0 0 0 0 0
52145- 0 0 0 0 0 0 0 0 0 0 0 0
52146- 0 0 0 0 0 0 0 0 0 0 0 0
52147- 0 0 0 0 0 0 0 0 0 10 10 10
52148- 30 30 30 78 78 78 46 46 46 22 22 22
52149-137 92 6 210 162 10 239 182 13 238 190 10
52150-238 202 15 241 208 19 246 215 20 246 215 20
52151-241 208 19 203 166 17 185 133 11 210 150 10
52152-216 158 10 210 150 10 102 78 10 2 2 6
52153- 6 6 6 54 54 54 14 14 14 2 2 6
52154- 2 2 6 62 62 62 74 74 74 30 30 30
52155- 10 10 10 0 0 0 0 0 0 0 0 0
52156- 0 0 0 0 0 0 0 0 0 0 0 0
52157- 0 0 0 0 0 0 0 0 0 0 0 0
52158- 0 0 0 0 0 0 0 0 0 0 0 0
52159- 0 0 0 0 0 0 0 0 0 0 0 0
52160- 0 0 0 0 0 0 0 0 0 0 0 0
52161- 0 0 0 0 0 0 0 0 0 0 0 0
52162- 0 0 0 0 0 0 0 0 0 0 0 0
52163- 0 0 0 0 0 0 0 0 0 0 0 0
52164- 0 0 0 0 0 0 0 0 0 0 0 0
52165- 0 0 0 0 0 0 0 0 0 0 0 0
52166- 0 0 0 0 0 0 0 0 0 0 0 0
52167- 0 0 0 0 0 0 0 0 0 10 10 10
52168- 34 34 34 78 78 78 50 50 50 6 6 6
52169- 94 70 30 139 102 15 190 146 13 226 184 13
52170-232 200 30 232 195 16 215 174 15 190 146 13
52171-168 122 10 192 133 9 210 150 10 213 154 11
52172-202 150 34 182 157 106 101 98 89 2 2 6
52173- 2 2 6 78 78 78 116 116 116 58 58 58
52174- 2 2 6 22 22 22 90 90 90 46 46 46
52175- 18 18 18 6 6 6 0 0 0 0 0 0
52176- 0 0 0 0 0 0 0 0 0 0 0 0
52177- 0 0 0 0 0 0 0 0 0 0 0 0
52178- 0 0 0 0 0 0 0 0 0 0 0 0
52179- 0 0 0 0 0 0 0 0 0 0 0 0
52180- 0 0 0 0 0 0 0 0 0 0 0 0
52181- 0 0 0 0 0 0 0 0 0 0 0 0
52182- 0 0 0 0 0 0 0 0 0 0 0 0
52183- 0 0 0 0 0 0 0 0 0 0 0 0
52184- 0 0 0 0 0 0 0 0 0 0 0 0
52185- 0 0 0 0 0 0 0 0 0 0 0 0
52186- 0 0 0 0 0 0 0 0 0 0 0 0
52187- 0 0 0 0 0 0 0 0 0 10 10 10
52188- 38 38 38 86 86 86 50 50 50 6 6 6
52189-128 128 128 174 154 114 156 107 11 168 122 10
52190-198 155 10 184 144 12 197 138 11 200 144 11
52191-206 145 10 206 145 10 197 138 11 188 164 115
52192-195 195 195 198 198 198 174 174 174 14 14 14
52193- 2 2 6 22 22 22 116 116 116 116 116 116
52194- 22 22 22 2 2 6 74 74 74 70 70 70
52195- 30 30 30 10 10 10 0 0 0 0 0 0
52196- 0 0 0 0 0 0 0 0 0 0 0 0
52197- 0 0 0 0 0 0 0 0 0 0 0 0
52198- 0 0 0 0 0 0 0 0 0 0 0 0
52199- 0 0 0 0 0 0 0 0 0 0 0 0
52200- 0 0 0 0 0 0 0 0 0 0 0 0
52201- 0 0 0 0 0 0 0 0 0 0 0 0
52202- 0 0 0 0 0 0 0 0 0 0 0 0
52203- 0 0 0 0 0 0 0 0 0 0 0 0
52204- 0 0 0 0 0 0 0 0 0 0 0 0
52205- 0 0 0 0 0 0 0 0 0 0 0 0
52206- 0 0 0 0 0 0 0 0 0 0 0 0
52207- 0 0 0 0 0 0 6 6 6 18 18 18
52208- 50 50 50 101 101 101 26 26 26 10 10 10
52209-138 138 138 190 190 190 174 154 114 156 107 11
52210-197 138 11 200 144 11 197 138 11 192 133 9
52211-180 123 7 190 142 34 190 178 144 187 187 187
52212-202 202 202 221 221 221 214 214 214 66 66 66
52213- 2 2 6 2 2 6 50 50 50 62 62 62
52214- 6 6 6 2 2 6 10 10 10 90 90 90
52215- 50 50 50 18 18 18 6 6 6 0 0 0
52216- 0 0 0 0 0 0 0 0 0 0 0 0
52217- 0 0 0 0 0 0 0 0 0 0 0 0
52218- 0 0 0 0 0 0 0 0 0 0 0 0
52219- 0 0 0 0 0 0 0 0 0 0 0 0
52220- 0 0 0 0 0 0 0 0 0 0 0 0
52221- 0 0 0 0 0 0 0 0 0 0 0 0
52222- 0 0 0 0 0 0 0 0 0 0 0 0
52223- 0 0 0 0 0 0 0 0 0 0 0 0
52224- 0 0 0 0 0 0 0 0 0 0 0 0
52225- 0 0 0 0 0 0 0 0 0 0 0 0
52226- 0 0 0 0 0 0 0 0 0 0 0 0
52227- 0 0 0 0 0 0 10 10 10 34 34 34
52228- 74 74 74 74 74 74 2 2 6 6 6 6
52229-144 144 144 198 198 198 190 190 190 178 166 146
52230-154 121 60 156 107 11 156 107 11 168 124 44
52231-174 154 114 187 187 187 190 190 190 210 210 210
52232-246 246 246 253 253 253 253 253 253 182 182 182
52233- 6 6 6 2 2 6 2 2 6 2 2 6
52234- 2 2 6 2 2 6 2 2 6 62 62 62
52235- 74 74 74 34 34 34 14 14 14 0 0 0
52236- 0 0 0 0 0 0 0 0 0 0 0 0
52237- 0 0 0 0 0 0 0 0 0 0 0 0
52238- 0 0 0 0 0 0 0 0 0 0 0 0
52239- 0 0 0 0 0 0 0 0 0 0 0 0
52240- 0 0 0 0 0 0 0 0 0 0 0 0
52241- 0 0 0 0 0 0 0 0 0 0 0 0
52242- 0 0 0 0 0 0 0 0 0 0 0 0
52243- 0 0 0 0 0 0 0 0 0 0 0 0
52244- 0 0 0 0 0 0 0 0 0 0 0 0
52245- 0 0 0 0 0 0 0 0 0 0 0 0
52246- 0 0 0 0 0 0 0 0 0 0 0 0
52247- 0 0 0 10 10 10 22 22 22 54 54 54
52248- 94 94 94 18 18 18 2 2 6 46 46 46
52249-234 234 234 221 221 221 190 190 190 190 190 190
52250-190 190 190 187 187 187 187 187 187 190 190 190
52251-190 190 190 195 195 195 214 214 214 242 242 242
52252-253 253 253 253 253 253 253 253 253 253 253 253
52253- 82 82 82 2 2 6 2 2 6 2 2 6
52254- 2 2 6 2 2 6 2 2 6 14 14 14
52255- 86 86 86 54 54 54 22 22 22 6 6 6
52256- 0 0 0 0 0 0 0 0 0 0 0 0
52257- 0 0 0 0 0 0 0 0 0 0 0 0
52258- 0 0 0 0 0 0 0 0 0 0 0 0
52259- 0 0 0 0 0 0 0 0 0 0 0 0
52260- 0 0 0 0 0 0 0 0 0 0 0 0
52261- 0 0 0 0 0 0 0 0 0 0 0 0
52262- 0 0 0 0 0 0 0 0 0 0 0 0
52263- 0 0 0 0 0 0 0 0 0 0 0 0
52264- 0 0 0 0 0 0 0 0 0 0 0 0
52265- 0 0 0 0 0 0 0 0 0 0 0 0
52266- 0 0 0 0 0 0 0 0 0 0 0 0
52267- 6 6 6 18 18 18 46 46 46 90 90 90
52268- 46 46 46 18 18 18 6 6 6 182 182 182
52269-253 253 253 246 246 246 206 206 206 190 190 190
52270-190 190 190 190 190 190 190 190 190 190 190 190
52271-206 206 206 231 231 231 250 250 250 253 253 253
52272-253 253 253 253 253 253 253 253 253 253 253 253
52273-202 202 202 14 14 14 2 2 6 2 2 6
52274- 2 2 6 2 2 6 2 2 6 2 2 6
52275- 42 42 42 86 86 86 42 42 42 18 18 18
52276- 6 6 6 0 0 0 0 0 0 0 0 0
52277- 0 0 0 0 0 0 0 0 0 0 0 0
52278- 0 0 0 0 0 0 0 0 0 0 0 0
52279- 0 0 0 0 0 0 0 0 0 0 0 0
52280- 0 0 0 0 0 0 0 0 0 0 0 0
52281- 0 0 0 0 0 0 0 0 0 0 0 0
52282- 0 0 0 0 0 0 0 0 0 0 0 0
52283- 0 0 0 0 0 0 0 0 0 0 0 0
52284- 0 0 0 0 0 0 0 0 0 0 0 0
52285- 0 0 0 0 0 0 0 0 0 0 0 0
52286- 0 0 0 0 0 0 0 0 0 6 6 6
52287- 14 14 14 38 38 38 74 74 74 66 66 66
52288- 2 2 6 6 6 6 90 90 90 250 250 250
52289-253 253 253 253 253 253 238 238 238 198 198 198
52290-190 190 190 190 190 190 195 195 195 221 221 221
52291-246 246 246 253 253 253 253 253 253 253 253 253
52292-253 253 253 253 253 253 253 253 253 253 253 253
52293-253 253 253 82 82 82 2 2 6 2 2 6
52294- 2 2 6 2 2 6 2 2 6 2 2 6
52295- 2 2 6 78 78 78 70 70 70 34 34 34
52296- 14 14 14 6 6 6 0 0 0 0 0 0
52297- 0 0 0 0 0 0 0 0 0 0 0 0
52298- 0 0 0 0 0 0 0 0 0 0 0 0
52299- 0 0 0 0 0 0 0 0 0 0 0 0
52300- 0 0 0 0 0 0 0 0 0 0 0 0
52301- 0 0 0 0 0 0 0 0 0 0 0 0
52302- 0 0 0 0 0 0 0 0 0 0 0 0
52303- 0 0 0 0 0 0 0 0 0 0 0 0
52304- 0 0 0 0 0 0 0 0 0 0 0 0
52305- 0 0 0 0 0 0 0 0 0 0 0 0
52306- 0 0 0 0 0 0 0 0 0 14 14 14
52307- 34 34 34 66 66 66 78 78 78 6 6 6
52308- 2 2 6 18 18 18 218 218 218 253 253 253
52309-253 253 253 253 253 253 253 253 253 246 246 246
52310-226 226 226 231 231 231 246 246 246 253 253 253
52311-253 253 253 253 253 253 253 253 253 253 253 253
52312-253 253 253 253 253 253 253 253 253 253 253 253
52313-253 253 253 178 178 178 2 2 6 2 2 6
52314- 2 2 6 2 2 6 2 2 6 2 2 6
52315- 2 2 6 18 18 18 90 90 90 62 62 62
52316- 30 30 30 10 10 10 0 0 0 0 0 0
52317- 0 0 0 0 0 0 0 0 0 0 0 0
52318- 0 0 0 0 0 0 0 0 0 0 0 0
52319- 0 0 0 0 0 0 0 0 0 0 0 0
52320- 0 0 0 0 0 0 0 0 0 0 0 0
52321- 0 0 0 0 0 0 0 0 0 0 0 0
52322- 0 0 0 0 0 0 0 0 0 0 0 0
52323- 0 0 0 0 0 0 0 0 0 0 0 0
52324- 0 0 0 0 0 0 0 0 0 0 0 0
52325- 0 0 0 0 0 0 0 0 0 0 0 0
52326- 0 0 0 0 0 0 10 10 10 26 26 26
52327- 58 58 58 90 90 90 18 18 18 2 2 6
52328- 2 2 6 110 110 110 253 253 253 253 253 253
52329-253 253 253 253 253 253 253 253 253 253 253 253
52330-250 250 250 253 253 253 253 253 253 253 253 253
52331-253 253 253 253 253 253 253 253 253 253 253 253
52332-253 253 253 253 253 253 253 253 253 253 253 253
52333-253 253 253 231 231 231 18 18 18 2 2 6
52334- 2 2 6 2 2 6 2 2 6 2 2 6
52335- 2 2 6 2 2 6 18 18 18 94 94 94
52336- 54 54 54 26 26 26 10 10 10 0 0 0
52337- 0 0 0 0 0 0 0 0 0 0 0 0
52338- 0 0 0 0 0 0 0 0 0 0 0 0
52339- 0 0 0 0 0 0 0 0 0 0 0 0
52340- 0 0 0 0 0 0 0 0 0 0 0 0
52341- 0 0 0 0 0 0 0 0 0 0 0 0
52342- 0 0 0 0 0 0 0 0 0 0 0 0
52343- 0 0 0 0 0 0 0 0 0 0 0 0
52344- 0 0 0 0 0 0 0 0 0 0 0 0
52345- 0 0 0 0 0 0 0 0 0 0 0 0
52346- 0 0 0 6 6 6 22 22 22 50 50 50
52347- 90 90 90 26 26 26 2 2 6 2 2 6
52348- 14 14 14 195 195 195 250 250 250 253 253 253
52349-253 253 253 253 253 253 253 253 253 253 253 253
52350-253 253 253 253 253 253 253 253 253 253 253 253
52351-253 253 253 253 253 253 253 253 253 253 253 253
52352-253 253 253 253 253 253 253 253 253 253 253 253
52353-250 250 250 242 242 242 54 54 54 2 2 6
52354- 2 2 6 2 2 6 2 2 6 2 2 6
52355- 2 2 6 2 2 6 2 2 6 38 38 38
52356- 86 86 86 50 50 50 22 22 22 6 6 6
52357- 0 0 0 0 0 0 0 0 0 0 0 0
52358- 0 0 0 0 0 0 0 0 0 0 0 0
52359- 0 0 0 0 0 0 0 0 0 0 0 0
52360- 0 0 0 0 0 0 0 0 0 0 0 0
52361- 0 0 0 0 0 0 0 0 0 0 0 0
52362- 0 0 0 0 0 0 0 0 0 0 0 0
52363- 0 0 0 0 0 0 0 0 0 0 0 0
52364- 0 0 0 0 0 0 0 0 0 0 0 0
52365- 0 0 0 0 0 0 0 0 0 0 0 0
52366- 6 6 6 14 14 14 38 38 38 82 82 82
52367- 34 34 34 2 2 6 2 2 6 2 2 6
52368- 42 42 42 195 195 195 246 246 246 253 253 253
52369-253 253 253 253 253 253 253 253 253 250 250 250
52370-242 242 242 242 242 242 250 250 250 253 253 253
52371-253 253 253 253 253 253 253 253 253 253 253 253
52372-253 253 253 250 250 250 246 246 246 238 238 238
52373-226 226 226 231 231 231 101 101 101 6 6 6
52374- 2 2 6 2 2 6 2 2 6 2 2 6
52375- 2 2 6 2 2 6 2 2 6 2 2 6
52376- 38 38 38 82 82 82 42 42 42 14 14 14
52377- 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
52381- 0 0 0 0 0 0 0 0 0 0 0 0
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- 10 10 10 26 26 26 62 62 62 66 66 66
52387- 2 2 6 2 2 6 2 2 6 6 6 6
52388- 70 70 70 170 170 170 206 206 206 234 234 234
52389-246 246 246 250 250 250 250 250 250 238 238 238
52390-226 226 226 231 231 231 238 238 238 250 250 250
52391-250 250 250 250 250 250 246 246 246 231 231 231
52392-214 214 214 206 206 206 202 202 202 202 202 202
52393-198 198 198 202 202 202 182 182 182 18 18 18
52394- 2 2 6 2 2 6 2 2 6 2 2 6
52395- 2 2 6 2 2 6 2 2 6 2 2 6
52396- 2 2 6 62 62 62 66 66 66 30 30 30
52397- 10 10 10 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 0 0 0 0 0 0 0 0 0
52400- 0 0 0 0 0 0 0 0 0 0 0 0
52401- 0 0 0 0 0 0 0 0 0 0 0 0
52402- 0 0 0 0 0 0 0 0 0 0 0 0
52403- 0 0 0 0 0 0 0 0 0 0 0 0
52404- 0 0 0 0 0 0 0 0 0 0 0 0
52405- 0 0 0 0 0 0 0 0 0 0 0 0
52406- 14 14 14 42 42 42 82 82 82 18 18 18
52407- 2 2 6 2 2 6 2 2 6 10 10 10
52408- 94 94 94 182 182 182 218 218 218 242 242 242
52409-250 250 250 253 253 253 253 253 253 250 250 250
52410-234 234 234 253 253 253 253 253 253 253 253 253
52411-253 253 253 253 253 253 253 253 253 246 246 246
52412-238 238 238 226 226 226 210 210 210 202 202 202
52413-195 195 195 195 195 195 210 210 210 158 158 158
52414- 6 6 6 14 14 14 50 50 50 14 14 14
52415- 2 2 6 2 2 6 2 2 6 2 2 6
52416- 2 2 6 6 6 6 86 86 86 46 46 46
52417- 18 18 18 6 6 6 0 0 0 0 0 0
52418- 0 0 0 0 0 0 0 0 0 0 0 0
52419- 0 0 0 0 0 0 0 0 0 0 0 0
52420- 0 0 0 0 0 0 0 0 0 0 0 0
52421- 0 0 0 0 0 0 0 0 0 0 0 0
52422- 0 0 0 0 0 0 0 0 0 0 0 0
52423- 0 0 0 0 0 0 0 0 0 0 0 0
52424- 0 0 0 0 0 0 0 0 0 0 0 0
52425- 0 0 0 0 0 0 0 0 0 6 6 6
52426- 22 22 22 54 54 54 70 70 70 2 2 6
52427- 2 2 6 10 10 10 2 2 6 22 22 22
52428-166 166 166 231 231 231 250 250 250 253 253 253
52429-253 253 253 253 253 253 253 253 253 250 250 250
52430-242 242 242 253 253 253 253 253 253 253 253 253
52431-253 253 253 253 253 253 253 253 253 253 253 253
52432-253 253 253 253 253 253 253 253 253 246 246 246
52433-231 231 231 206 206 206 198 198 198 226 226 226
52434- 94 94 94 2 2 6 6 6 6 38 38 38
52435- 30 30 30 2 2 6 2 2 6 2 2 6
52436- 2 2 6 2 2 6 62 62 62 66 66 66
52437- 26 26 26 10 10 10 0 0 0 0 0 0
52438- 0 0 0 0 0 0 0 0 0 0 0 0
52439- 0 0 0 0 0 0 0 0 0 0 0 0
52440- 0 0 0 0 0 0 0 0 0 0 0 0
52441- 0 0 0 0 0 0 0 0 0 0 0 0
52442- 0 0 0 0 0 0 0 0 0 0 0 0
52443- 0 0 0 0 0 0 0 0 0 0 0 0
52444- 0 0 0 0 0 0 0 0 0 0 0 0
52445- 0 0 0 0 0 0 0 0 0 10 10 10
52446- 30 30 30 74 74 74 50 50 50 2 2 6
52447- 26 26 26 26 26 26 2 2 6 106 106 106
52448-238 238 238 253 253 253 253 253 253 253 253 253
52449-253 253 253 253 253 253 253 253 253 253 253 253
52450-253 253 253 253 253 253 253 253 253 253 253 253
52451-253 253 253 253 253 253 253 253 253 253 253 253
52452-253 253 253 253 253 253 253 253 253 253 253 253
52453-253 253 253 246 246 246 218 218 218 202 202 202
52454-210 210 210 14 14 14 2 2 6 2 2 6
52455- 30 30 30 22 22 22 2 2 6 2 2 6
52456- 2 2 6 2 2 6 18 18 18 86 86 86
52457- 42 42 42 14 14 14 0 0 0 0 0 0
52458- 0 0 0 0 0 0 0 0 0 0 0 0
52459- 0 0 0 0 0 0 0 0 0 0 0 0
52460- 0 0 0 0 0 0 0 0 0 0 0 0
52461- 0 0 0 0 0 0 0 0 0 0 0 0
52462- 0 0 0 0 0 0 0 0 0 0 0 0
52463- 0 0 0 0 0 0 0 0 0 0 0 0
52464- 0 0 0 0 0 0 0 0 0 0 0 0
52465- 0 0 0 0 0 0 0 0 0 14 14 14
52466- 42 42 42 90 90 90 22 22 22 2 2 6
52467- 42 42 42 2 2 6 18 18 18 218 218 218
52468-253 253 253 253 253 253 253 253 253 253 253 253
52469-253 253 253 253 253 253 253 253 253 253 253 253
52470-253 253 253 253 253 253 253 253 253 253 253 253
52471-253 253 253 253 253 253 253 253 253 253 253 253
52472-253 253 253 253 253 253 253 253 253 253 253 253
52473-253 253 253 253 253 253 250 250 250 221 221 221
52474-218 218 218 101 101 101 2 2 6 14 14 14
52475- 18 18 18 38 38 38 10 10 10 2 2 6
52476- 2 2 6 2 2 6 2 2 6 78 78 78
52477- 58 58 58 22 22 22 6 6 6 0 0 0
52478- 0 0 0 0 0 0 0 0 0 0 0 0
52479- 0 0 0 0 0 0 0 0 0 0 0 0
52480- 0 0 0 0 0 0 0 0 0 0 0 0
52481- 0 0 0 0 0 0 0 0 0 0 0 0
52482- 0 0 0 0 0 0 0 0 0 0 0 0
52483- 0 0 0 0 0 0 0 0 0 0 0 0
52484- 0 0 0 0 0 0 0 0 0 0 0 0
52485- 0 0 0 0 0 0 6 6 6 18 18 18
52486- 54 54 54 82 82 82 2 2 6 26 26 26
52487- 22 22 22 2 2 6 123 123 123 253 253 253
52488-253 253 253 253 253 253 253 253 253 253 253 253
52489-253 253 253 253 253 253 253 253 253 253 253 253
52490-253 253 253 253 253 253 253 253 253 253 253 253
52491-253 253 253 253 253 253 253 253 253 253 253 253
52492-253 253 253 253 253 253 253 253 253 253 253 253
52493-253 253 253 253 253 253 253 253 253 250 250 250
52494-238 238 238 198 198 198 6 6 6 38 38 38
52495- 58 58 58 26 26 26 38 38 38 2 2 6
52496- 2 2 6 2 2 6 2 2 6 46 46 46
52497- 78 78 78 30 30 30 10 10 10 0 0 0
52498- 0 0 0 0 0 0 0 0 0 0 0 0
52499- 0 0 0 0 0 0 0 0 0 0 0 0
52500- 0 0 0 0 0 0 0 0 0 0 0 0
52501- 0 0 0 0 0 0 0 0 0 0 0 0
52502- 0 0 0 0 0 0 0 0 0 0 0 0
52503- 0 0 0 0 0 0 0 0 0 0 0 0
52504- 0 0 0 0 0 0 0 0 0 0 0 0
52505- 0 0 0 0 0 0 10 10 10 30 30 30
52506- 74 74 74 58 58 58 2 2 6 42 42 42
52507- 2 2 6 22 22 22 231 231 231 253 253 253
52508-253 253 253 253 253 253 253 253 253 253 253 253
52509-253 253 253 253 253 253 253 253 253 250 250 250
52510-253 253 253 253 253 253 253 253 253 253 253 253
52511-253 253 253 253 253 253 253 253 253 253 253 253
52512-253 253 253 253 253 253 253 253 253 253 253 253
52513-253 253 253 253 253 253 253 253 253 253 253 253
52514-253 253 253 246 246 246 46 46 46 38 38 38
52515- 42 42 42 14 14 14 38 38 38 14 14 14
52516- 2 2 6 2 2 6 2 2 6 6 6 6
52517- 86 86 86 46 46 46 14 14 14 0 0 0
52518- 0 0 0 0 0 0 0 0 0 0 0 0
52519- 0 0 0 0 0 0 0 0 0 0 0 0
52520- 0 0 0 0 0 0 0 0 0 0 0 0
52521- 0 0 0 0 0 0 0 0 0 0 0 0
52522- 0 0 0 0 0 0 0 0 0 0 0 0
52523- 0 0 0 0 0 0 0 0 0 0 0 0
52524- 0 0 0 0 0 0 0 0 0 0 0 0
52525- 0 0 0 6 6 6 14 14 14 42 42 42
52526- 90 90 90 18 18 18 18 18 18 26 26 26
52527- 2 2 6 116 116 116 253 253 253 253 253 253
52528-253 253 253 253 253 253 253 253 253 253 253 253
52529-253 253 253 253 253 253 250 250 250 238 238 238
52530-253 253 253 253 253 253 253 253 253 253 253 253
52531-253 253 253 253 253 253 253 253 253 253 253 253
52532-253 253 253 253 253 253 253 253 253 253 253 253
52533-253 253 253 253 253 253 253 253 253 253 253 253
52534-253 253 253 253 253 253 94 94 94 6 6 6
52535- 2 2 6 2 2 6 10 10 10 34 34 34
52536- 2 2 6 2 2 6 2 2 6 2 2 6
52537- 74 74 74 58 58 58 22 22 22 6 6 6
52538- 0 0 0 0 0 0 0 0 0 0 0 0
52539- 0 0 0 0 0 0 0 0 0 0 0 0
52540- 0 0 0 0 0 0 0 0 0 0 0 0
52541- 0 0 0 0 0 0 0 0 0 0 0 0
52542- 0 0 0 0 0 0 0 0 0 0 0 0
52543- 0 0 0 0 0 0 0 0 0 0 0 0
52544- 0 0 0 0 0 0 0 0 0 0 0 0
52545- 0 0 0 10 10 10 26 26 26 66 66 66
52546- 82 82 82 2 2 6 38 38 38 6 6 6
52547- 14 14 14 210 210 210 253 253 253 253 253 253
52548-253 253 253 253 253 253 253 253 253 253 253 253
52549-253 253 253 253 253 253 246 246 246 242 242 242
52550-253 253 253 253 253 253 253 253 253 253 253 253
52551-253 253 253 253 253 253 253 253 253 253 253 253
52552-253 253 253 253 253 253 253 253 253 253 253 253
52553-253 253 253 253 253 253 253 253 253 253 253 253
52554-253 253 253 253 253 253 144 144 144 2 2 6
52555- 2 2 6 2 2 6 2 2 6 46 46 46
52556- 2 2 6 2 2 6 2 2 6 2 2 6
52557- 42 42 42 74 74 74 30 30 30 10 10 10
52558- 0 0 0 0 0 0 0 0 0 0 0 0
52559- 0 0 0 0 0 0 0 0 0 0 0 0
52560- 0 0 0 0 0 0 0 0 0 0 0 0
52561- 0 0 0 0 0 0 0 0 0 0 0 0
52562- 0 0 0 0 0 0 0 0 0 0 0 0
52563- 0 0 0 0 0 0 0 0 0 0 0 0
52564- 0 0 0 0 0 0 0 0 0 0 0 0
52565- 6 6 6 14 14 14 42 42 42 90 90 90
52566- 26 26 26 6 6 6 42 42 42 2 2 6
52567- 74 74 74 250 250 250 253 253 253 253 253 253
52568-253 253 253 253 253 253 253 253 253 253 253 253
52569-253 253 253 253 253 253 242 242 242 242 242 242
52570-253 253 253 253 253 253 253 253 253 253 253 253
52571-253 253 253 253 253 253 253 253 253 253 253 253
52572-253 253 253 253 253 253 253 253 253 253 253 253
52573-253 253 253 253 253 253 253 253 253 253 253 253
52574-253 253 253 253 253 253 182 182 182 2 2 6
52575- 2 2 6 2 2 6 2 2 6 46 46 46
52576- 2 2 6 2 2 6 2 2 6 2 2 6
52577- 10 10 10 86 86 86 38 38 38 10 10 10
52578- 0 0 0 0 0 0 0 0 0 0 0 0
52579- 0 0 0 0 0 0 0 0 0 0 0 0
52580- 0 0 0 0 0 0 0 0 0 0 0 0
52581- 0 0 0 0 0 0 0 0 0 0 0 0
52582- 0 0 0 0 0 0 0 0 0 0 0 0
52583- 0 0 0 0 0 0 0 0 0 0 0 0
52584- 0 0 0 0 0 0 0 0 0 0 0 0
52585- 10 10 10 26 26 26 66 66 66 82 82 82
52586- 2 2 6 22 22 22 18 18 18 2 2 6
52587-149 149 149 253 253 253 253 253 253 253 253 253
52588-253 253 253 253 253 253 253 253 253 253 253 253
52589-253 253 253 253 253 253 234 234 234 242 242 242
52590-253 253 253 253 253 253 253 253 253 253 253 253
52591-253 253 253 253 253 253 253 253 253 253 253 253
52592-253 253 253 253 253 253 253 253 253 253 253 253
52593-253 253 253 253 253 253 253 253 253 253 253 253
52594-253 253 253 253 253 253 206 206 206 2 2 6
52595- 2 2 6 2 2 6 2 2 6 38 38 38
52596- 2 2 6 2 2 6 2 2 6 2 2 6
52597- 6 6 6 86 86 86 46 46 46 14 14 14
52598- 0 0 0 0 0 0 0 0 0 0 0 0
52599- 0 0 0 0 0 0 0 0 0 0 0 0
52600- 0 0 0 0 0 0 0 0 0 0 0 0
52601- 0 0 0 0 0 0 0 0 0 0 0 0
52602- 0 0 0 0 0 0 0 0 0 0 0 0
52603- 0 0 0 0 0 0 0 0 0 0 0 0
52604- 0 0 0 0 0 0 0 0 0 6 6 6
52605- 18 18 18 46 46 46 86 86 86 18 18 18
52606- 2 2 6 34 34 34 10 10 10 6 6 6
52607-210 210 210 253 253 253 253 253 253 253 253 253
52608-253 253 253 253 253 253 253 253 253 253 253 253
52609-253 253 253 253 253 253 234 234 234 242 242 242
52610-253 253 253 253 253 253 253 253 253 253 253 253
52611-253 253 253 253 253 253 253 253 253 253 253 253
52612-253 253 253 253 253 253 253 253 253 253 253 253
52613-253 253 253 253 253 253 253 253 253 253 253 253
52614-253 253 253 253 253 253 221 221 221 6 6 6
52615- 2 2 6 2 2 6 6 6 6 30 30 30
52616- 2 2 6 2 2 6 2 2 6 2 2 6
52617- 2 2 6 82 82 82 54 54 54 18 18 18
52618- 6 6 6 0 0 0 0 0 0 0 0 0
52619- 0 0 0 0 0 0 0 0 0 0 0 0
52620- 0 0 0 0 0 0 0 0 0 0 0 0
52621- 0 0 0 0 0 0 0 0 0 0 0 0
52622- 0 0 0 0 0 0 0 0 0 0 0 0
52623- 0 0 0 0 0 0 0 0 0 0 0 0
52624- 0 0 0 0 0 0 0 0 0 10 10 10
52625- 26 26 26 66 66 66 62 62 62 2 2 6
52626- 2 2 6 38 38 38 10 10 10 26 26 26
52627-238 238 238 253 253 253 253 253 253 253 253 253
52628-253 253 253 253 253 253 253 253 253 253 253 253
52629-253 253 253 253 253 253 231 231 231 238 238 238
52630-253 253 253 253 253 253 253 253 253 253 253 253
52631-253 253 253 253 253 253 253 253 253 253 253 253
52632-253 253 253 253 253 253 253 253 253 253 253 253
52633-253 253 253 253 253 253 253 253 253 253 253 253
52634-253 253 253 253 253 253 231 231 231 6 6 6
52635- 2 2 6 2 2 6 10 10 10 30 30 30
52636- 2 2 6 2 2 6 2 2 6 2 2 6
52637- 2 2 6 66 66 66 58 58 58 22 22 22
52638- 6 6 6 0 0 0 0 0 0 0 0 0
52639- 0 0 0 0 0 0 0 0 0 0 0 0
52640- 0 0 0 0 0 0 0 0 0 0 0 0
52641- 0 0 0 0 0 0 0 0 0 0 0 0
52642- 0 0 0 0 0 0 0 0 0 0 0 0
52643- 0 0 0 0 0 0 0 0 0 0 0 0
52644- 0 0 0 0 0 0 0 0 0 10 10 10
52645- 38 38 38 78 78 78 6 6 6 2 2 6
52646- 2 2 6 46 46 46 14 14 14 42 42 42
52647-246 246 246 253 253 253 253 253 253 253 253 253
52648-253 253 253 253 253 253 253 253 253 253 253 253
52649-253 253 253 253 253 253 231 231 231 242 242 242
52650-253 253 253 253 253 253 253 253 253 253 253 253
52651-253 253 253 253 253 253 253 253 253 253 253 253
52652-253 253 253 253 253 253 253 253 253 253 253 253
52653-253 253 253 253 253 253 253 253 253 253 253 253
52654-253 253 253 253 253 253 234 234 234 10 10 10
52655- 2 2 6 2 2 6 22 22 22 14 14 14
52656- 2 2 6 2 2 6 2 2 6 2 2 6
52657- 2 2 6 66 66 66 62 62 62 22 22 22
52658- 6 6 6 0 0 0 0 0 0 0 0 0
52659- 0 0 0 0 0 0 0 0 0 0 0 0
52660- 0 0 0 0 0 0 0 0 0 0 0 0
52661- 0 0 0 0 0 0 0 0 0 0 0 0
52662- 0 0 0 0 0 0 0 0 0 0 0 0
52663- 0 0 0 0 0 0 0 0 0 0 0 0
52664- 0 0 0 0 0 0 6 6 6 18 18 18
52665- 50 50 50 74 74 74 2 2 6 2 2 6
52666- 14 14 14 70 70 70 34 34 34 62 62 62
52667-250 250 250 253 253 253 253 253 253 253 253 253
52668-253 253 253 253 253 253 253 253 253 253 253 253
52669-253 253 253 253 253 253 231 231 231 246 246 246
52670-253 253 253 253 253 253 253 253 253 253 253 253
52671-253 253 253 253 253 253 253 253 253 253 253 253
52672-253 253 253 253 253 253 253 253 253 253 253 253
52673-253 253 253 253 253 253 253 253 253 253 253 253
52674-253 253 253 253 253 253 234 234 234 14 14 14
52675- 2 2 6 2 2 6 30 30 30 2 2 6
52676- 2 2 6 2 2 6 2 2 6 2 2 6
52677- 2 2 6 66 66 66 62 62 62 22 22 22
52678- 6 6 6 0 0 0 0 0 0 0 0 0
52679- 0 0 0 0 0 0 0 0 0 0 0 0
52680- 0 0 0 0 0 0 0 0 0 0 0 0
52681- 0 0 0 0 0 0 0 0 0 0 0 0
52682- 0 0 0 0 0 0 0 0 0 0 0 0
52683- 0 0 0 0 0 0 0 0 0 0 0 0
52684- 0 0 0 0 0 0 6 6 6 18 18 18
52685- 54 54 54 62 62 62 2 2 6 2 2 6
52686- 2 2 6 30 30 30 46 46 46 70 70 70
52687-250 250 250 253 253 253 253 253 253 253 253 253
52688-253 253 253 253 253 253 253 253 253 253 253 253
52689-253 253 253 253 253 253 231 231 231 246 246 246
52690-253 253 253 253 253 253 253 253 253 253 253 253
52691-253 253 253 253 253 253 253 253 253 253 253 253
52692-253 253 253 253 253 253 253 253 253 253 253 253
52693-253 253 253 253 253 253 253 253 253 253 253 253
52694-253 253 253 253 253 253 226 226 226 10 10 10
52695- 2 2 6 6 6 6 30 30 30 2 2 6
52696- 2 2 6 2 2 6 2 2 6 2 2 6
52697- 2 2 6 66 66 66 58 58 58 22 22 22
52698- 6 6 6 0 0 0 0 0 0 0 0 0
52699- 0 0 0 0 0 0 0 0 0 0 0 0
52700- 0 0 0 0 0 0 0 0 0 0 0 0
52701- 0 0 0 0 0 0 0 0 0 0 0 0
52702- 0 0 0 0 0 0 0 0 0 0 0 0
52703- 0 0 0 0 0 0 0 0 0 0 0 0
52704- 0 0 0 0 0 0 6 6 6 22 22 22
52705- 58 58 58 62 62 62 2 2 6 2 2 6
52706- 2 2 6 2 2 6 30 30 30 78 78 78
52707-250 250 250 253 253 253 253 253 253 253 253 253
52708-253 253 253 253 253 253 253 253 253 253 253 253
52709-253 253 253 253 253 253 231 231 231 246 246 246
52710-253 253 253 253 253 253 253 253 253 253 253 253
52711-253 253 253 253 253 253 253 253 253 253 253 253
52712-253 253 253 253 253 253 253 253 253 253 253 253
52713-253 253 253 253 253 253 253 253 253 253 253 253
52714-253 253 253 253 253 253 206 206 206 2 2 6
52715- 22 22 22 34 34 34 18 14 6 22 22 22
52716- 26 26 26 18 18 18 6 6 6 2 2 6
52717- 2 2 6 82 82 82 54 54 54 18 18 18
52718- 6 6 6 0 0 0 0 0 0 0 0 0
52719- 0 0 0 0 0 0 0 0 0 0 0 0
52720- 0 0 0 0 0 0 0 0 0 0 0 0
52721- 0 0 0 0 0 0 0 0 0 0 0 0
52722- 0 0 0 0 0 0 0 0 0 0 0 0
52723- 0 0 0 0 0 0 0 0 0 0 0 0
52724- 0 0 0 0 0 0 6 6 6 26 26 26
52725- 62 62 62 106 106 106 74 54 14 185 133 11
52726-210 162 10 121 92 8 6 6 6 62 62 62
52727-238 238 238 253 253 253 253 253 253 253 253 253
52728-253 253 253 253 253 253 253 253 253 253 253 253
52729-253 253 253 253 253 253 231 231 231 246 246 246
52730-253 253 253 253 253 253 253 253 253 253 253 253
52731-253 253 253 253 253 253 253 253 253 253 253 253
52732-253 253 253 253 253 253 253 253 253 253 253 253
52733-253 253 253 253 253 253 253 253 253 253 253 253
52734-253 253 253 253 253 253 158 158 158 18 18 18
52735- 14 14 14 2 2 6 2 2 6 2 2 6
52736- 6 6 6 18 18 18 66 66 66 38 38 38
52737- 6 6 6 94 94 94 50 50 50 18 18 18
52738- 6 6 6 0 0 0 0 0 0 0 0 0
52739- 0 0 0 0 0 0 0 0 0 0 0 0
52740- 0 0 0 0 0 0 0 0 0 0 0 0
52741- 0 0 0 0 0 0 0 0 0 0 0 0
52742- 0 0 0 0 0 0 0 0 0 0 0 0
52743- 0 0 0 0 0 0 0 0 0 6 6 6
52744- 10 10 10 10 10 10 18 18 18 38 38 38
52745- 78 78 78 142 134 106 216 158 10 242 186 14
52746-246 190 14 246 190 14 156 118 10 10 10 10
52747- 90 90 90 238 238 238 253 253 253 253 253 253
52748-253 253 253 253 253 253 253 253 253 253 253 253
52749-253 253 253 253 253 253 231 231 231 250 250 250
52750-253 253 253 253 253 253 253 253 253 253 253 253
52751-253 253 253 253 253 253 253 253 253 253 253 253
52752-253 253 253 253 253 253 253 253 253 253 253 253
52753-253 253 253 253 253 253 253 253 253 246 230 190
52754-238 204 91 238 204 91 181 142 44 37 26 9
52755- 2 2 6 2 2 6 2 2 6 2 2 6
52756- 2 2 6 2 2 6 38 38 38 46 46 46
52757- 26 26 26 106 106 106 54 54 54 18 18 18
52758- 6 6 6 0 0 0 0 0 0 0 0 0
52759- 0 0 0 0 0 0 0 0 0 0 0 0
52760- 0 0 0 0 0 0 0 0 0 0 0 0
52761- 0 0 0 0 0 0 0 0 0 0 0 0
52762- 0 0 0 0 0 0 0 0 0 0 0 0
52763- 0 0 0 6 6 6 14 14 14 22 22 22
52764- 30 30 30 38 38 38 50 50 50 70 70 70
52765-106 106 106 190 142 34 226 170 11 242 186 14
52766-246 190 14 246 190 14 246 190 14 154 114 10
52767- 6 6 6 74 74 74 226 226 226 253 253 253
52768-253 253 253 253 253 253 253 253 253 253 253 253
52769-253 253 253 253 253 253 231 231 231 250 250 250
52770-253 253 253 253 253 253 253 253 253 253 253 253
52771-253 253 253 253 253 253 253 253 253 253 253 253
52772-253 253 253 253 253 253 253 253 253 253 253 253
52773-253 253 253 253 253 253 253 253 253 228 184 62
52774-241 196 14 241 208 19 232 195 16 38 30 10
52775- 2 2 6 2 2 6 2 2 6 2 2 6
52776- 2 2 6 6 6 6 30 30 30 26 26 26
52777-203 166 17 154 142 90 66 66 66 26 26 26
52778- 6 6 6 0 0 0 0 0 0 0 0 0
52779- 0 0 0 0 0 0 0 0 0 0 0 0
52780- 0 0 0 0 0 0 0 0 0 0 0 0
52781- 0 0 0 0 0 0 0 0 0 0 0 0
52782- 0 0 0 0 0 0 0 0 0 0 0 0
52783- 6 6 6 18 18 18 38 38 38 58 58 58
52784- 78 78 78 86 86 86 101 101 101 123 123 123
52785-175 146 61 210 150 10 234 174 13 246 186 14
52786-246 190 14 246 190 14 246 190 14 238 190 10
52787-102 78 10 2 2 6 46 46 46 198 198 198
52788-253 253 253 253 253 253 253 253 253 253 253 253
52789-253 253 253 253 253 253 234 234 234 242 242 242
52790-253 253 253 253 253 253 253 253 253 253 253 253
52791-253 253 253 253 253 253 253 253 253 253 253 253
52792-253 253 253 253 253 253 253 253 253 253 253 253
52793-253 253 253 253 253 253 253 253 253 224 178 62
52794-242 186 14 241 196 14 210 166 10 22 18 6
52795- 2 2 6 2 2 6 2 2 6 2 2 6
52796- 2 2 6 2 2 6 6 6 6 121 92 8
52797-238 202 15 232 195 16 82 82 82 34 34 34
52798- 10 10 10 0 0 0 0 0 0 0 0 0
52799- 0 0 0 0 0 0 0 0 0 0 0 0
52800- 0 0 0 0 0 0 0 0 0 0 0 0
52801- 0 0 0 0 0 0 0 0 0 0 0 0
52802- 0 0 0 0 0 0 0 0 0 0 0 0
52803- 14 14 14 38 38 38 70 70 70 154 122 46
52804-190 142 34 200 144 11 197 138 11 197 138 11
52805-213 154 11 226 170 11 242 186 14 246 190 14
52806-246 190 14 246 190 14 246 190 14 246 190 14
52807-225 175 15 46 32 6 2 2 6 22 22 22
52808-158 158 158 250 250 250 253 253 253 253 253 253
52809-253 253 253 253 253 253 253 253 253 253 253 253
52810-253 253 253 253 253 253 253 253 253 253 253 253
52811-253 253 253 253 253 253 253 253 253 253 253 253
52812-253 253 253 253 253 253 253 253 253 253 253 253
52813-253 253 253 250 250 250 242 242 242 224 178 62
52814-239 182 13 236 186 11 213 154 11 46 32 6
52815- 2 2 6 2 2 6 2 2 6 2 2 6
52816- 2 2 6 2 2 6 61 42 6 225 175 15
52817-238 190 10 236 186 11 112 100 78 42 42 42
52818- 14 14 14 0 0 0 0 0 0 0 0 0
52819- 0 0 0 0 0 0 0 0 0 0 0 0
52820- 0 0 0 0 0 0 0 0 0 0 0 0
52821- 0 0 0 0 0 0 0 0 0 0 0 0
52822- 0 0 0 0 0 0 0 0 0 6 6 6
52823- 22 22 22 54 54 54 154 122 46 213 154 11
52824-226 170 11 230 174 11 226 170 11 226 170 11
52825-236 178 12 242 186 14 246 190 14 246 190 14
52826-246 190 14 246 190 14 246 190 14 246 190 14
52827-241 196 14 184 144 12 10 10 10 2 2 6
52828- 6 6 6 116 116 116 242 242 242 253 253 253
52829-253 253 253 253 253 253 253 253 253 253 253 253
52830-253 253 253 253 253 253 253 253 253 253 253 253
52831-253 253 253 253 253 253 253 253 253 253 253 253
52832-253 253 253 253 253 253 253 253 253 253 253 253
52833-253 253 253 231 231 231 198 198 198 214 170 54
52834-236 178 12 236 178 12 210 150 10 137 92 6
52835- 18 14 6 2 2 6 2 2 6 2 2 6
52836- 6 6 6 70 47 6 200 144 11 236 178 12
52837-239 182 13 239 182 13 124 112 88 58 58 58
52838- 22 22 22 6 6 6 0 0 0 0 0 0
52839- 0 0 0 0 0 0 0 0 0 0 0 0
52840- 0 0 0 0 0 0 0 0 0 0 0 0
52841- 0 0 0 0 0 0 0 0 0 0 0 0
52842- 0 0 0 0 0 0 0 0 0 10 10 10
52843- 30 30 30 70 70 70 180 133 36 226 170 11
52844-239 182 13 242 186 14 242 186 14 246 186 14
52845-246 190 14 246 190 14 246 190 14 246 190 14
52846-246 190 14 246 190 14 246 190 14 246 190 14
52847-246 190 14 232 195 16 98 70 6 2 2 6
52848- 2 2 6 2 2 6 66 66 66 221 221 221
52849-253 253 253 253 253 253 253 253 253 253 253 253
52850-253 253 253 253 253 253 253 253 253 253 253 253
52851-253 253 253 253 253 253 253 253 253 253 253 253
52852-253 253 253 253 253 253 253 253 253 253 253 253
52853-253 253 253 206 206 206 198 198 198 214 166 58
52854-230 174 11 230 174 11 216 158 10 192 133 9
52855-163 110 8 116 81 8 102 78 10 116 81 8
52856-167 114 7 197 138 11 226 170 11 239 182 13
52857-242 186 14 242 186 14 162 146 94 78 78 78
52858- 34 34 34 14 14 14 6 6 6 0 0 0
52859- 0 0 0 0 0 0 0 0 0 0 0 0
52860- 0 0 0 0 0 0 0 0 0 0 0 0
52861- 0 0 0 0 0 0 0 0 0 0 0 0
52862- 0 0 0 0 0 0 0 0 0 6 6 6
52863- 30 30 30 78 78 78 190 142 34 226 170 11
52864-239 182 13 246 190 14 246 190 14 246 190 14
52865-246 190 14 246 190 14 246 190 14 246 190 14
52866-246 190 14 246 190 14 246 190 14 246 190 14
52867-246 190 14 241 196 14 203 166 17 22 18 6
52868- 2 2 6 2 2 6 2 2 6 38 38 38
52869-218 218 218 253 253 253 253 253 253 253 253 253
52870-253 253 253 253 253 253 253 253 253 253 253 253
52871-253 253 253 253 253 253 253 253 253 253 253 253
52872-253 253 253 253 253 253 253 253 253 253 253 253
52873-250 250 250 206 206 206 198 198 198 202 162 69
52874-226 170 11 236 178 12 224 166 10 210 150 10
52875-200 144 11 197 138 11 192 133 9 197 138 11
52876-210 150 10 226 170 11 242 186 14 246 190 14
52877-246 190 14 246 186 14 225 175 15 124 112 88
52878- 62 62 62 30 30 30 14 14 14 6 6 6
52879- 0 0 0 0 0 0 0 0 0 0 0 0
52880- 0 0 0 0 0 0 0 0 0 0 0 0
52881- 0 0 0 0 0 0 0 0 0 0 0 0
52882- 0 0 0 0 0 0 0 0 0 10 10 10
52883- 30 30 30 78 78 78 174 135 50 224 166 10
52884-239 182 13 246 190 14 246 190 14 246 190 14
52885-246 190 14 246 190 14 246 190 14 246 190 14
52886-246 190 14 246 190 14 246 190 14 246 190 14
52887-246 190 14 246 190 14 241 196 14 139 102 15
52888- 2 2 6 2 2 6 2 2 6 2 2 6
52889- 78 78 78 250 250 250 253 253 253 253 253 253
52890-253 253 253 253 253 253 253 253 253 253 253 253
52891-253 253 253 253 253 253 253 253 253 253 253 253
52892-253 253 253 253 253 253 253 253 253 253 253 253
52893-250 250 250 214 214 214 198 198 198 190 150 46
52894-219 162 10 236 178 12 234 174 13 224 166 10
52895-216 158 10 213 154 11 213 154 11 216 158 10
52896-226 170 11 239 182 13 246 190 14 246 190 14
52897-246 190 14 246 190 14 242 186 14 206 162 42
52898-101 101 101 58 58 58 30 30 30 14 14 14
52899- 6 6 6 0 0 0 0 0 0 0 0 0
52900- 0 0 0 0 0 0 0 0 0 0 0 0
52901- 0 0 0 0 0 0 0 0 0 0 0 0
52902- 0 0 0 0 0 0 0 0 0 10 10 10
52903- 30 30 30 74 74 74 174 135 50 216 158 10
52904-236 178 12 246 190 14 246 190 14 246 190 14
52905-246 190 14 246 190 14 246 190 14 246 190 14
52906-246 190 14 246 190 14 246 190 14 246 190 14
52907-246 190 14 246 190 14 241 196 14 226 184 13
52908- 61 42 6 2 2 6 2 2 6 2 2 6
52909- 22 22 22 238 238 238 253 253 253 253 253 253
52910-253 253 253 253 253 253 253 253 253 253 253 253
52911-253 253 253 253 253 253 253 253 253 253 253 253
52912-253 253 253 253 253 253 253 253 253 253 253 253
52913-253 253 253 226 226 226 187 187 187 180 133 36
52914-216 158 10 236 178 12 239 182 13 236 178 12
52915-230 174 11 226 170 11 226 170 11 230 174 11
52916-236 178 12 242 186 14 246 190 14 246 190 14
52917-246 190 14 246 190 14 246 186 14 239 182 13
52918-206 162 42 106 106 106 66 66 66 34 34 34
52919- 14 14 14 6 6 6 0 0 0 0 0 0
52920- 0 0 0 0 0 0 0 0 0 0 0 0
52921- 0 0 0 0 0 0 0 0 0 0 0 0
52922- 0 0 0 0 0 0 0 0 0 6 6 6
52923- 26 26 26 70 70 70 163 133 67 213 154 11
52924-236 178 12 246 190 14 246 190 14 246 190 14
52925-246 190 14 246 190 14 246 190 14 246 190 14
52926-246 190 14 246 190 14 246 190 14 246 190 14
52927-246 190 14 246 190 14 246 190 14 241 196 14
52928-190 146 13 18 14 6 2 2 6 2 2 6
52929- 46 46 46 246 246 246 253 253 253 253 253 253
52930-253 253 253 253 253 253 253 253 253 253 253 253
52931-253 253 253 253 253 253 253 253 253 253 253 253
52932-253 253 253 253 253 253 253 253 253 253 253 253
52933-253 253 253 221 221 221 86 86 86 156 107 11
52934-216 158 10 236 178 12 242 186 14 246 186 14
52935-242 186 14 239 182 13 239 182 13 242 186 14
52936-242 186 14 246 186 14 246 190 14 246 190 14
52937-246 190 14 246 190 14 246 190 14 246 190 14
52938-242 186 14 225 175 15 142 122 72 66 66 66
52939- 30 30 30 10 10 10 0 0 0 0 0 0
52940- 0 0 0 0 0 0 0 0 0 0 0 0
52941- 0 0 0 0 0 0 0 0 0 0 0 0
52942- 0 0 0 0 0 0 0 0 0 6 6 6
52943- 26 26 26 70 70 70 163 133 67 210 150 10
52944-236 178 12 246 190 14 246 190 14 246 190 14
52945-246 190 14 246 190 14 246 190 14 246 190 14
52946-246 190 14 246 190 14 246 190 14 246 190 14
52947-246 190 14 246 190 14 246 190 14 246 190 14
52948-232 195 16 121 92 8 34 34 34 106 106 106
52949-221 221 221 253 253 253 253 253 253 253 253 253
52950-253 253 253 253 253 253 253 253 253 253 253 253
52951-253 253 253 253 253 253 253 253 253 253 253 253
52952-253 253 253 253 253 253 253 253 253 253 253 253
52953-242 242 242 82 82 82 18 14 6 163 110 8
52954-216 158 10 236 178 12 242 186 14 246 190 14
52955-246 190 14 246 190 14 246 190 14 246 190 14
52956-246 190 14 246 190 14 246 190 14 246 190 14
52957-246 190 14 246 190 14 246 190 14 246 190 14
52958-246 190 14 246 190 14 242 186 14 163 133 67
52959- 46 46 46 18 18 18 6 6 6 0 0 0
52960- 0 0 0 0 0 0 0 0 0 0 0 0
52961- 0 0 0 0 0 0 0 0 0 0 0 0
52962- 0 0 0 0 0 0 0 0 0 10 10 10
52963- 30 30 30 78 78 78 163 133 67 210 150 10
52964-236 178 12 246 186 14 246 190 14 246 190 14
52965-246 190 14 246 190 14 246 190 14 246 190 14
52966-246 190 14 246 190 14 246 190 14 246 190 14
52967-246 190 14 246 190 14 246 190 14 246 190 14
52968-241 196 14 215 174 15 190 178 144 253 253 253
52969-253 253 253 253 253 253 253 253 253 253 253 253
52970-253 253 253 253 253 253 253 253 253 253 253 253
52971-253 253 253 253 253 253 253 253 253 253 253 253
52972-253 253 253 253 253 253 253 253 253 218 218 218
52973- 58 58 58 2 2 6 22 18 6 167 114 7
52974-216 158 10 236 178 12 246 186 14 246 190 14
52975-246 190 14 246 190 14 246 190 14 246 190 14
52976-246 190 14 246 190 14 246 190 14 246 190 14
52977-246 190 14 246 190 14 246 190 14 246 190 14
52978-246 190 14 246 186 14 242 186 14 190 150 46
52979- 54 54 54 22 22 22 6 6 6 0 0 0
52980- 0 0 0 0 0 0 0 0 0 0 0 0
52981- 0 0 0 0 0 0 0 0 0 0 0 0
52982- 0 0 0 0 0 0 0 0 0 14 14 14
52983- 38 38 38 86 86 86 180 133 36 213 154 11
52984-236 178 12 246 186 14 246 190 14 246 190 14
52985-246 190 14 246 190 14 246 190 14 246 190 14
52986-246 190 14 246 190 14 246 190 14 246 190 14
52987-246 190 14 246 190 14 246 190 14 246 190 14
52988-246 190 14 232 195 16 190 146 13 214 214 214
52989-253 253 253 253 253 253 253 253 253 253 253 253
52990-253 253 253 253 253 253 253 253 253 253 253 253
52991-253 253 253 253 253 253 253 253 253 253 253 253
52992-253 253 253 250 250 250 170 170 170 26 26 26
52993- 2 2 6 2 2 6 37 26 9 163 110 8
52994-219 162 10 239 182 13 246 186 14 246 190 14
52995-246 190 14 246 190 14 246 190 14 246 190 14
52996-246 190 14 246 190 14 246 190 14 246 190 14
52997-246 190 14 246 190 14 246 190 14 246 190 14
52998-246 186 14 236 178 12 224 166 10 142 122 72
52999- 46 46 46 18 18 18 6 6 6 0 0 0
53000- 0 0 0 0 0 0 0 0 0 0 0 0
53001- 0 0 0 0 0 0 0 0 0 0 0 0
53002- 0 0 0 0 0 0 6 6 6 18 18 18
53003- 50 50 50 109 106 95 192 133 9 224 166 10
53004-242 186 14 246 190 14 246 190 14 246 190 14
53005-246 190 14 246 190 14 246 190 14 246 190 14
53006-246 190 14 246 190 14 246 190 14 246 190 14
53007-246 190 14 246 190 14 246 190 14 246 190 14
53008-242 186 14 226 184 13 210 162 10 142 110 46
53009-226 226 226 253 253 253 253 253 253 253 253 253
53010-253 253 253 253 253 253 253 253 253 253 253 253
53011-253 253 253 253 253 253 253 253 253 253 253 253
53012-198 198 198 66 66 66 2 2 6 2 2 6
53013- 2 2 6 2 2 6 50 34 6 156 107 11
53014-219 162 10 239 182 13 246 186 14 246 190 14
53015-246 190 14 246 190 14 246 190 14 246 190 14
53016-246 190 14 246 190 14 246 190 14 246 190 14
53017-246 190 14 246 190 14 246 190 14 242 186 14
53018-234 174 13 213 154 11 154 122 46 66 66 66
53019- 30 30 30 10 10 10 0 0 0 0 0 0
53020- 0 0 0 0 0 0 0 0 0 0 0 0
53021- 0 0 0 0 0 0 0 0 0 0 0 0
53022- 0 0 0 0 0 0 6 6 6 22 22 22
53023- 58 58 58 154 121 60 206 145 10 234 174 13
53024-242 186 14 246 186 14 246 190 14 246 190 14
53025-246 190 14 246 190 14 246 190 14 246 190 14
53026-246 190 14 246 190 14 246 190 14 246 190 14
53027-246 190 14 246 190 14 246 190 14 246 190 14
53028-246 186 14 236 178 12 210 162 10 163 110 8
53029- 61 42 6 138 138 138 218 218 218 250 250 250
53030-253 253 253 253 253 253 253 253 253 250 250 250
53031-242 242 242 210 210 210 144 144 144 66 66 66
53032- 6 6 6 2 2 6 2 2 6 2 2 6
53033- 2 2 6 2 2 6 61 42 6 163 110 8
53034-216 158 10 236 178 12 246 190 14 246 190 14
53035-246 190 14 246 190 14 246 190 14 246 190 14
53036-246 190 14 246 190 14 246 190 14 246 190 14
53037-246 190 14 239 182 13 230 174 11 216 158 10
53038-190 142 34 124 112 88 70 70 70 38 38 38
53039- 18 18 18 6 6 6 0 0 0 0 0 0
53040- 0 0 0 0 0 0 0 0 0 0 0 0
53041- 0 0 0 0 0 0 0 0 0 0 0 0
53042- 0 0 0 0 0 0 6 6 6 22 22 22
53043- 62 62 62 168 124 44 206 145 10 224 166 10
53044-236 178 12 239 182 13 242 186 14 242 186 14
53045-246 186 14 246 190 14 246 190 14 246 190 14
53046-246 190 14 246 190 14 246 190 14 246 190 14
53047-246 190 14 246 190 14 246 190 14 246 190 14
53048-246 190 14 236 178 12 216 158 10 175 118 6
53049- 80 54 7 2 2 6 6 6 6 30 30 30
53050- 54 54 54 62 62 62 50 50 50 38 38 38
53051- 14 14 14 2 2 6 2 2 6 2 2 6
53052- 2 2 6 2 2 6 2 2 6 2 2 6
53053- 2 2 6 6 6 6 80 54 7 167 114 7
53054-213 154 11 236 178 12 246 190 14 246 190 14
53055-246 190 14 246 190 14 246 190 14 246 190 14
53056-246 190 14 242 186 14 239 182 13 239 182 13
53057-230 174 11 210 150 10 174 135 50 124 112 88
53058- 82 82 82 54 54 54 34 34 34 18 18 18
53059- 6 6 6 0 0 0 0 0 0 0 0 0
53060- 0 0 0 0 0 0 0 0 0 0 0 0
53061- 0 0 0 0 0 0 0 0 0 0 0 0
53062- 0 0 0 0 0 0 6 6 6 18 18 18
53063- 50 50 50 158 118 36 192 133 9 200 144 11
53064-216 158 10 219 162 10 224 166 10 226 170 11
53065-230 174 11 236 178 12 239 182 13 239 182 13
53066-242 186 14 246 186 14 246 190 14 246 190 14
53067-246 190 14 246 190 14 246 190 14 246 190 14
53068-246 186 14 230 174 11 210 150 10 163 110 8
53069-104 69 6 10 10 10 2 2 6 2 2 6
53070- 2 2 6 2 2 6 2 2 6 2 2 6
53071- 2 2 6 2 2 6 2 2 6 2 2 6
53072- 2 2 6 2 2 6 2 2 6 2 2 6
53073- 2 2 6 6 6 6 91 60 6 167 114 7
53074-206 145 10 230 174 11 242 186 14 246 190 14
53075-246 190 14 246 190 14 246 186 14 242 186 14
53076-239 182 13 230 174 11 224 166 10 213 154 11
53077-180 133 36 124 112 88 86 86 86 58 58 58
53078- 38 38 38 22 22 22 10 10 10 6 6 6
53079- 0 0 0 0 0 0 0 0 0 0 0 0
53080- 0 0 0 0 0 0 0 0 0 0 0 0
53081- 0 0 0 0 0 0 0 0 0 0 0 0
53082- 0 0 0 0 0 0 0 0 0 14 14 14
53083- 34 34 34 70 70 70 138 110 50 158 118 36
53084-167 114 7 180 123 7 192 133 9 197 138 11
53085-200 144 11 206 145 10 213 154 11 219 162 10
53086-224 166 10 230 174 11 239 182 13 242 186 14
53087-246 186 14 246 186 14 246 186 14 246 186 14
53088-239 182 13 216 158 10 185 133 11 152 99 6
53089-104 69 6 18 14 6 2 2 6 2 2 6
53090- 2 2 6 2 2 6 2 2 6 2 2 6
53091- 2 2 6 2 2 6 2 2 6 2 2 6
53092- 2 2 6 2 2 6 2 2 6 2 2 6
53093- 2 2 6 6 6 6 80 54 7 152 99 6
53094-192 133 9 219 162 10 236 178 12 239 182 13
53095-246 186 14 242 186 14 239 182 13 236 178 12
53096-224 166 10 206 145 10 192 133 9 154 121 60
53097- 94 94 94 62 62 62 42 42 42 22 22 22
53098- 14 14 14 6 6 6 0 0 0 0 0 0
53099- 0 0 0 0 0 0 0 0 0 0 0 0
53100- 0 0 0 0 0 0 0 0 0 0 0 0
53101- 0 0 0 0 0 0 0 0 0 0 0 0
53102- 0 0 0 0 0 0 0 0 0 6 6 6
53103- 18 18 18 34 34 34 58 58 58 78 78 78
53104-101 98 89 124 112 88 142 110 46 156 107 11
53105-163 110 8 167 114 7 175 118 6 180 123 7
53106-185 133 11 197 138 11 210 150 10 219 162 10
53107-226 170 11 236 178 12 236 178 12 234 174 13
53108-219 162 10 197 138 11 163 110 8 130 83 6
53109- 91 60 6 10 10 10 2 2 6 2 2 6
53110- 18 18 18 38 38 38 38 38 38 38 38 38
53111- 38 38 38 38 38 38 38 38 38 38 38 38
53112- 38 38 38 38 38 38 26 26 26 2 2 6
53113- 2 2 6 6 6 6 70 47 6 137 92 6
53114-175 118 6 200 144 11 219 162 10 230 174 11
53115-234 174 13 230 174 11 219 162 10 210 150 10
53116-192 133 9 163 110 8 124 112 88 82 82 82
53117- 50 50 50 30 30 30 14 14 14 6 6 6
53118- 0 0 0 0 0 0 0 0 0 0 0 0
53119- 0 0 0 0 0 0 0 0 0 0 0 0
53120- 0 0 0 0 0 0 0 0 0 0 0 0
53121- 0 0 0 0 0 0 0 0 0 0 0 0
53122- 0 0 0 0 0 0 0 0 0 0 0 0
53123- 6 6 6 14 14 14 22 22 22 34 34 34
53124- 42 42 42 58 58 58 74 74 74 86 86 86
53125-101 98 89 122 102 70 130 98 46 121 87 25
53126-137 92 6 152 99 6 163 110 8 180 123 7
53127-185 133 11 197 138 11 206 145 10 200 144 11
53128-180 123 7 156 107 11 130 83 6 104 69 6
53129- 50 34 6 54 54 54 110 110 110 101 98 89
53130- 86 86 86 82 82 82 78 78 78 78 78 78
53131- 78 78 78 78 78 78 78 78 78 78 78 78
53132- 78 78 78 82 82 82 86 86 86 94 94 94
53133-106 106 106 101 101 101 86 66 34 124 80 6
53134-156 107 11 180 123 7 192 133 9 200 144 11
53135-206 145 10 200 144 11 192 133 9 175 118 6
53136-139 102 15 109 106 95 70 70 70 42 42 42
53137- 22 22 22 10 10 10 0 0 0 0 0 0
53138- 0 0 0 0 0 0 0 0 0 0 0 0
53139- 0 0 0 0 0 0 0 0 0 0 0 0
53140- 0 0 0 0 0 0 0 0 0 0 0 0
53141- 0 0 0 0 0 0 0 0 0 0 0 0
53142- 0 0 0 0 0 0 0 0 0 0 0 0
53143- 0 0 0 0 0 0 6 6 6 10 10 10
53144- 14 14 14 22 22 22 30 30 30 38 38 38
53145- 50 50 50 62 62 62 74 74 74 90 90 90
53146-101 98 89 112 100 78 121 87 25 124 80 6
53147-137 92 6 152 99 6 152 99 6 152 99 6
53148-138 86 6 124 80 6 98 70 6 86 66 30
53149-101 98 89 82 82 82 58 58 58 46 46 46
53150- 38 38 38 34 34 34 34 34 34 34 34 34
53151- 34 34 34 34 34 34 34 34 34 34 34 34
53152- 34 34 34 34 34 34 38 38 38 42 42 42
53153- 54 54 54 82 82 82 94 86 76 91 60 6
53154-134 86 6 156 107 11 167 114 7 175 118 6
53155-175 118 6 167 114 7 152 99 6 121 87 25
53156-101 98 89 62 62 62 34 34 34 18 18 18
53157- 6 6 6 0 0 0 0 0 0 0 0 0
53158- 0 0 0 0 0 0 0 0 0 0 0 0
53159- 0 0 0 0 0 0 0 0 0 0 0 0
53160- 0 0 0 0 0 0 0 0 0 0 0 0
53161- 0 0 0 0 0 0 0 0 0 0 0 0
53162- 0 0 0 0 0 0 0 0 0 0 0 0
53163- 0 0 0 0 0 0 0 0 0 0 0 0
53164- 0 0 0 6 6 6 6 6 6 10 10 10
53165- 18 18 18 22 22 22 30 30 30 42 42 42
53166- 50 50 50 66 66 66 86 86 86 101 98 89
53167-106 86 58 98 70 6 104 69 6 104 69 6
53168-104 69 6 91 60 6 82 62 34 90 90 90
53169- 62 62 62 38 38 38 22 22 22 14 14 14
53170- 10 10 10 10 10 10 10 10 10 10 10 10
53171- 10 10 10 10 10 10 6 6 6 10 10 10
53172- 10 10 10 10 10 10 10 10 10 14 14 14
53173- 22 22 22 42 42 42 70 70 70 89 81 66
53174- 80 54 7 104 69 6 124 80 6 137 92 6
53175-134 86 6 116 81 8 100 82 52 86 86 86
53176- 58 58 58 30 30 30 14 14 14 6 6 6
53177- 0 0 0 0 0 0 0 0 0 0 0 0
53178- 0 0 0 0 0 0 0 0 0 0 0 0
53179- 0 0 0 0 0 0 0 0 0 0 0 0
53180- 0 0 0 0 0 0 0 0 0 0 0 0
53181- 0 0 0 0 0 0 0 0 0 0 0 0
53182- 0 0 0 0 0 0 0 0 0 0 0 0
53183- 0 0 0 0 0 0 0 0 0 0 0 0
53184- 0 0 0 0 0 0 0 0 0 0 0 0
53185- 0 0 0 6 6 6 10 10 10 14 14 14
53186- 18 18 18 26 26 26 38 38 38 54 54 54
53187- 70 70 70 86 86 86 94 86 76 89 81 66
53188- 89 81 66 86 86 86 74 74 74 50 50 50
53189- 30 30 30 14 14 14 6 6 6 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- 6 6 6 18 18 18 34 34 34 58 58 58
53194- 82 82 82 89 81 66 89 81 66 89 81 66
53195- 94 86 66 94 86 76 74 74 74 50 50 50
53196- 26 26 26 14 14 14 6 6 6 0 0 0
53197- 0 0 0 0 0 0 0 0 0 0 0 0
53198- 0 0 0 0 0 0 0 0 0 0 0 0
53199- 0 0 0 0 0 0 0 0 0 0 0 0
53200- 0 0 0 0 0 0 0 0 0 0 0 0
53201- 0 0 0 0 0 0 0 0 0 0 0 0
53202- 0 0 0 0 0 0 0 0 0 0 0 0
53203- 0 0 0 0 0 0 0 0 0 0 0 0
53204- 0 0 0 0 0 0 0 0 0 0 0 0
53205- 0 0 0 0 0 0 0 0 0 0 0 0
53206- 6 6 6 6 6 6 14 14 14 18 18 18
53207- 30 30 30 38 38 38 46 46 46 54 54 54
53208- 50 50 50 42 42 42 30 30 30 18 18 18
53209- 10 10 10 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 6 6 6 14 14 14 26 26 26
53214- 38 38 38 50 50 50 58 58 58 58 58 58
53215- 54 54 54 42 42 42 30 30 30 18 18 18
53216- 10 10 10 0 0 0 0 0 0 0 0 0
53217- 0 0 0 0 0 0 0 0 0 0 0 0
53218- 0 0 0 0 0 0 0 0 0 0 0 0
53219- 0 0 0 0 0 0 0 0 0 0 0 0
53220- 0 0 0 0 0 0 0 0 0 0 0 0
53221- 0 0 0 0 0 0 0 0 0 0 0 0
53222- 0 0 0 0 0 0 0 0 0 0 0 0
53223- 0 0 0 0 0 0 0 0 0 0 0 0
53224- 0 0 0 0 0 0 0 0 0 0 0 0
53225- 0 0 0 0 0 0 0 0 0 0 0 0
53226- 0 0 0 0 0 0 0 0 0 6 6 6
53227- 6 6 6 10 10 10 14 14 14 18 18 18
53228- 18 18 18 14 14 14 10 10 10 6 6 6
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 6 6 6
53234- 14 14 14 18 18 18 22 22 22 22 22 22
53235- 18 18 18 14 14 14 10 10 10 6 6 6
53236- 0 0 0 0 0 0 0 0 0 0 0 0
53237- 0 0 0 0 0 0 0 0 0 0 0 0
53238- 0 0 0 0 0 0 0 0 0 0 0 0
53239- 0 0 0 0 0 0 0 0 0 0 0 0
53240- 0 0 0 0 0 0 0 0 0 0 0 0
53241+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53242+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53243+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53244+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53245+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53246+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53247+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53248+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53251+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53252+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53253+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53254+4 4 4 4 4 4
53255+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53256+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53257+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53258+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53259+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53260+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53261+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53262+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53265+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53266+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53267+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53268+4 4 4 4 4 4
53269+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53270+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53271+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53272+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53273+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53274+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53275+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53276+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53279+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53280+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53281+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53282+4 4 4 4 4 4
53283+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53284+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53285+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53286+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53287+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53288+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53290+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53293+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53294+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53296+4 4 4 4 4 4
53297+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53298+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53299+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53300+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53301+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53302+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53304+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53307+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53308+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53309+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53310+4 4 4 4 4 4
53311+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53312+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53313+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53314+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53315+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53316+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53318+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53321+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53322+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53323+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53324+4 4 4 4 4 4
53325+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53326+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53327+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53329+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
53330+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
53331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53332+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53334+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
53335+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
53336+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
53337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53338+4 4 4 4 4 4
53339+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53340+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53341+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53343+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
53344+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
53345+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53346+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53348+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
53349+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
53350+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
53351+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53352+4 4 4 4 4 4
53353+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53354+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53355+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53357+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
53358+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
53359+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
53360+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53362+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
53363+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
53364+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
53365+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
53366+4 4 4 4 4 4
53367+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53368+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53369+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53370+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
53371+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
53372+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
53373+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
53374+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53375+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
53376+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
53377+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
53378+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
53379+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
53380+4 4 4 4 4 4
53381+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53382+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53383+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53384+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
53385+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
53386+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
53387+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
53388+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
53389+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
53390+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
53391+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
53392+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
53393+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
53394+4 4 4 4 4 4
53395+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53396+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53397+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
53398+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
53399+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
53400+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
53401+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
53402+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
53403+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
53404+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
53405+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
53406+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
53407+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
53408+4 4 4 4 4 4
53409+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53410+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53411+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
53412+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
53413+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
53414+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
53415+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
53416+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
53417+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
53418+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
53419+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
53420+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
53421+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
53422+4 4 4 4 4 4
53423+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53424+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53425+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
53426+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
53427+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
53428+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
53429+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
53430+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
53431+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
53432+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
53433+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
53434+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
53435+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
53436+4 4 4 4 4 4
53437+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53438+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53439+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
53440+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
53441+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
53442+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
53443+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
53444+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
53445+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
53446+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
53447+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
53448+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
53449+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
53450+4 4 4 4 4 4
53451+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53452+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53453+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
53454+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
53455+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
53456+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
53457+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
53458+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
53459+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
53460+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
53461+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
53462+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
53463+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
53464+4 4 4 4 4 4
53465+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53466+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
53467+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
53468+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
53469+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
53470+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
53471+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
53472+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
53473+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
53474+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
53475+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
53476+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
53477+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
53478+4 4 4 4 4 4
53479+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53480+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
53481+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
53482+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
53483+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
53484+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
53485+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
53486+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
53487+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
53488+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
53489+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
53490+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
53491+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
53492+0 0 0 4 4 4
53493+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
53494+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
53495+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
53496+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
53497+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
53498+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
53499+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
53500+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
53501+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
53502+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
53503+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
53504+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
53505+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
53506+2 0 0 0 0 0
53507+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
53508+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
53509+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
53510+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
53511+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
53512+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
53513+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
53514+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
53515+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
53516+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
53517+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
53518+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
53519+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
53520+37 38 37 0 0 0
53521+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
53522+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
53523+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
53524+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
53525+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
53526+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
53527+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
53528+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
53529+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
53530+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
53531+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
53532+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
53533+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
53534+85 115 134 4 0 0
53535+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
53536+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
53537+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
53538+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
53539+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
53540+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
53541+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
53542+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
53543+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
53544+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
53545+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
53546+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
53547+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
53548+60 73 81 4 0 0
53549+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
53550+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
53551+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
53552+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
53553+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
53554+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
53555+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
53556+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
53557+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
53558+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
53559+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
53560+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
53561+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
53562+16 19 21 4 0 0
53563+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
53564+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
53565+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
53566+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
53567+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
53568+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
53569+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
53570+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
53571+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
53572+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
53573+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
53574+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
53575+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
53576+4 0 0 4 3 3
53577+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
53578+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
53579+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
53580+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
53581+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
53582+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
53583+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
53584+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
53585+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
53586+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
53587+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
53588+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
53589+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
53590+3 2 2 4 4 4
53591+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
53592+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
53593+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
53594+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
53595+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
53596+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
53597+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
53598+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
53599+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
53600+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
53601+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
53602+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
53603+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
53604+4 4 4 4 4 4
53605+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
53606+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
53607+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
53608+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
53609+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
53610+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
53611+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
53612+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
53613+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
53614+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
53615+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
53616+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
53617+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
53618+4 4 4 4 4 4
53619+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
53620+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
53621+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
53622+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
53623+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
53624+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
53625+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
53626+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
53627+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
53628+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
53629+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
53630+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
53631+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
53632+5 5 5 5 5 5
53633+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
53634+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
53635+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
53636+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
53637+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
53638+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53639+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
53640+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
53641+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
53642+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
53643+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
53644+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
53645+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
53646+5 5 5 4 4 4
53647+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
53648+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
53649+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
53650+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
53651+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
53652+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
53653+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
53654+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
53655+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
53656+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
53657+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
53658+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
53659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53660+4 4 4 4 4 4
53661+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
53662+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
53663+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
53664+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
53665+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
53666+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53667+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53668+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
53669+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
53670+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
53671+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
53672+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
53673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53674+4 4 4 4 4 4
53675+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
53676+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
53677+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
53678+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
53679+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
53680+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
53681+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
53682+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
53683+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
53684+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
53685+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
53686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53688+4 4 4 4 4 4
53689+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
53690+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
53691+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
53692+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
53693+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
53694+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53695+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53696+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
53697+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
53698+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
53699+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
53700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53702+4 4 4 4 4 4
53703+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
53704+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
53705+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
53706+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
53707+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
53708+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
53709+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
53710+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
53711+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
53712+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
53713+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53716+4 4 4 4 4 4
53717+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
53718+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
53719+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
53720+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
53721+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
53722+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
53723+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
53724+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
53725+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
53726+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
53727+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
53728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53730+4 4 4 4 4 4
53731+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
53732+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
53733+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
53734+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
53735+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
53736+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
53737+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
53738+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
53739+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
53740+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
53741+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
53742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53744+4 4 4 4 4 4
53745+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
53746+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
53747+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
53748+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
53749+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
53750+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
53751+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
53752+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
53753+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
53754+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
53755+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53758+4 4 4 4 4 4
53759+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
53760+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
53761+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
53762+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
53763+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53764+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
53765+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
53766+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
53767+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
53768+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
53769+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53772+4 4 4 4 4 4
53773+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
53774+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
53775+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
53776+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
53777+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53778+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
53779+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
53780+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
53781+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
53782+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
53783+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53786+4 4 4 4 4 4
53787+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
53788+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
53789+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
53790+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
53791+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53792+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
53793+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
53794+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
53795+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
53796+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53797+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53800+4 4 4 4 4 4
53801+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
53802+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
53803+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
53804+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
53805+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
53806+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
53807+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
53808+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
53809+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53810+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53811+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53814+4 4 4 4 4 4
53815+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
53816+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
53817+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
53818+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
53819+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53820+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
53821+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
53822+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
53823+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
53824+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53825+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53828+4 4 4 4 4 4
53829+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
53830+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
53831+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
53832+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
53833+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
53834+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
53835+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
53836+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
53837+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53838+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53839+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53842+4 4 4 4 4 4
53843+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
53844+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
53845+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
53846+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
53847+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
53848+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
53849+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
53850+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
53851+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
53852+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53853+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53854+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53856+4 4 4 4 4 4
53857+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
53858+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
53859+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
53860+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
53861+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
53862+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
53863+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
53864+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
53865+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53866+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53867+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53868+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53870+4 4 4 4 4 4
53871+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
53872+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
53873+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
53874+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
53875+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
53876+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
53877+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
53878+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
53879+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
53880+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53881+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53882+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53884+4 4 4 4 4 4
53885+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
53886+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
53887+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
53888+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
53889+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
53890+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
53891+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
53892+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
53893+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53894+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53895+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53896+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53897+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53898+4 4 4 4 4 4
53899+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
53900+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
53901+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
53902+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
53903+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
53904+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
53905+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
53906+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
53907+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
53908+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53909+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53910+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53911+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53912+4 4 4 4 4 4
53913+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
53914+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
53915+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
53916+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
53917+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
53918+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
53919+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53920+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
53921+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53922+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53923+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53924+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53925+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53926+4 4 4 4 4 4
53927+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
53928+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
53929+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
53930+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
53931+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
53932+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
53933+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53934+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
53935+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
53936+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53937+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53938+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53939+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53940+4 4 4 4 4 4
53941+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
53942+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
53943+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
53944+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
53945+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
53946+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
53947+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
53948+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
53949+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
53950+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53951+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53952+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53953+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53954+4 4 4 4 4 4
53955+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
53956+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
53957+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
53958+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
53959+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
53960+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
53961+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
53962+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
53963+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
53964+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53965+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53966+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53967+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53968+4 4 4 4 4 4
53969+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
53970+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
53971+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
53972+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
53973+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
53974+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
53975+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
53976+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
53977+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
53978+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53979+0 0 0 3 3 3 5 5 5 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
53983+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
53984+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
53985+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
53986+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
53987+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
53988+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
53989+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
53990+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
53991+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
53992+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53993+0 0 0 3 3 3 5 5 5 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
53997+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
53998+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
53999+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
54000+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
54001+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
54002+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
54003+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
54004+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
54005+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
54006+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
54007+0 0 0 3 3 3 5 5 5 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
54011+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
54012+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54013+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
54014+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
54015+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
54016+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
54017+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
54018+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
54019+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
54020+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
54021+0 0 0 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
54025+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
54026+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54027+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
54028+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
54029+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
54030+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
54031+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54032+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
54033+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
54034+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
54035+4 3 3 5 5 5 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
54039+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
54040+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
54041+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
54042+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
54043+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
54044+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
54045+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
54046+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
54047+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
54048+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
54049+5 5 5 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
54053+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
54054+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
54055+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54056+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
54057+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
54058+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
54059+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
54060+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
54061+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
54062+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
54063+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54064+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54065+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54066+4 4 4 4 4 4
54067+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54068+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
54069+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
54070+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
54071+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
54072+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
54073+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
54074+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
54075+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
54076+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
54077+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54078+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54079+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54080+4 4 4 4 4 4
54081+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
54082+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
54083+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
54084+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
54085+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
54086+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
54087+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
54088+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
54089+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
54090+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
54091+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54092+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54093+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54094+4 4 4 4 4 4
54095+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
54096+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
54097+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
54098+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
54099+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
54100+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
54101+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
54102+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
54103+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54104+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54105+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54106+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54107+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54108+4 4 4 4 4 4
54109+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
54110+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54111+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
54112+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54113+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
54114+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
54115+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
54116+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
54117+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
54118+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54119+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54120+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54121+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54122+4 4 4 4 4 4
54123+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
54124+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
54125+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
54126+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
54127+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
54128+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
54129+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
54130+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
54131+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
54132+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54133+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54134+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54136+4 4 4 4 4 4
54137+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
54138+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
54139+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
54140+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
54141+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
54142+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
54143+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
54144+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
54145+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54146+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54147+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54148+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54150+4 4 4 4 4 4
54151+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
54152+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
54153+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
54154+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
54155+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
54156+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
54157+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
54158+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
54159+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54161+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54162+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54164+4 4 4 4 4 4
54165+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
54166+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
54167+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
54168+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
54169+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
54170+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
54171+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
54172+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
54173+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54175+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54176+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54178+4 4 4 4 4 4
54179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54180+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
54181+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54182+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
54183+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
54184+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
54185+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
54186+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
54187+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54188+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54189+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54190+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54192+4 4 4 4 4 4
54193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54194+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
54195+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
54196+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
54197+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
54198+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
54199+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
54200+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
54201+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54202+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54203+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54204+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54206+4 4 4 4 4 4
54207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54208+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
54209+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
54210+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
54211+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
54212+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
54213+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
54214+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54215+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54216+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54217+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54220+4 4 4 4 4 4
54221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54223+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
54224+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
54225+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
54226+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
54227+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
54228+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54229+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54230+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54231+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54232+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54233+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54234+4 4 4 4 4 4
54235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54237+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54238+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54239+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
54240+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
54241+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
54242+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54243+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54244+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54245+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54246+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54247+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54248+4 4 4 4 4 4
54249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54251+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54252+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
54253+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
54254+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
54255+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
54256+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54257+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54258+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54259+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54260+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54261+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54262+4 4 4 4 4 4
54263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54265+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54266+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
54267+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54268+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
54269+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
54270+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54271+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54272+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54273+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54274+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54275+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54276+4 4 4 4 4 4
54277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54279+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54280+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
54281+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
54282+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
54283+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
54284+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54285+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54286+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54287+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54288+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54290+4 4 4 4 4 4
54291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54293+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54294+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54295+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
54296+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54297+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54298+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54299+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54300+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54301+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54302+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54304+4 4 4 4 4 4
54305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54307+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54308+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54309+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
54310+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
54311+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54312+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54313+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54314+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54315+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54316+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54318+4 4 4 4 4 4
54319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54321+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54322+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54323+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
54324+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
54325+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54326+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54327+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54329+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54330+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54332+4 4 4 4 4 4
54333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54335+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54336+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54337+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
54338+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
54339+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54340+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54341+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54343+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54344+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54345+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54346+4 4 4 4 4 4
54347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54349+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54350+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54351+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
54352+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
54353+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54354+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54355+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54357+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54358+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54359+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54360+4 4 4 4 4 4
54361diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
54362index a01147f..5d896f8 100644
54363--- a/drivers/video/matrox/matroxfb_DAC1064.c
54364+++ b/drivers/video/matrox/matroxfb_DAC1064.c
54365@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
54366
54367 #ifdef CONFIG_FB_MATROX_MYSTIQUE
54368 struct matrox_switch matrox_mystique = {
54369- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
54370+ .preinit = MGA1064_preinit,
54371+ .reset = MGA1064_reset,
54372+ .init = MGA1064_init,
54373+ .restore = MGA1064_restore,
54374 };
54375 EXPORT_SYMBOL(matrox_mystique);
54376 #endif
54377
54378 #ifdef CONFIG_FB_MATROX_G
54379 struct matrox_switch matrox_G100 = {
54380- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
54381+ .preinit = MGAG100_preinit,
54382+ .reset = MGAG100_reset,
54383+ .init = MGAG100_init,
54384+ .restore = MGAG100_restore,
54385 };
54386 EXPORT_SYMBOL(matrox_G100);
54387 #endif
54388diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
54389index 195ad7c..09743fc 100644
54390--- a/drivers/video/matrox/matroxfb_Ti3026.c
54391+++ b/drivers/video/matrox/matroxfb_Ti3026.c
54392@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
54393 }
54394
54395 struct matrox_switch matrox_millennium = {
54396- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
54397+ .preinit = Ti3026_preinit,
54398+ .reset = Ti3026_reset,
54399+ .init = Ti3026_init,
54400+ .restore = Ti3026_restore
54401 };
54402 EXPORT_SYMBOL(matrox_millennium);
54403 #endif
54404diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
54405index fe92eed..106e085 100644
54406--- a/drivers/video/mb862xx/mb862xxfb_accel.c
54407+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
54408@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
54409 struct mb862xxfb_par *par = info->par;
54410
54411 if (info->var.bits_per_pixel == 32) {
54412- info->fbops->fb_fillrect = cfb_fillrect;
54413- info->fbops->fb_copyarea = cfb_copyarea;
54414- info->fbops->fb_imageblit = cfb_imageblit;
54415+ pax_open_kernel();
54416+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
54417+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
54418+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
54419+ pax_close_kernel();
54420 } else {
54421 outreg(disp, GC_L0EM, 3);
54422- info->fbops->fb_fillrect = mb86290fb_fillrect;
54423- info->fbops->fb_copyarea = mb86290fb_copyarea;
54424- info->fbops->fb_imageblit = mb86290fb_imageblit;
54425+ pax_open_kernel();
54426+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
54427+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
54428+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
54429+ pax_close_kernel();
54430 }
54431 outreg(draw, GDC_REG_DRAW_BASE, 0);
54432 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
54433diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
54434index ff22871..b129bed 100644
54435--- a/drivers/video/nvidia/nvidia.c
54436+++ b/drivers/video/nvidia/nvidia.c
54437@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
54438 info->fix.line_length = (info->var.xres_virtual *
54439 info->var.bits_per_pixel) >> 3;
54440 if (info->var.accel_flags) {
54441- info->fbops->fb_imageblit = nvidiafb_imageblit;
54442- info->fbops->fb_fillrect = nvidiafb_fillrect;
54443- info->fbops->fb_copyarea = nvidiafb_copyarea;
54444- info->fbops->fb_sync = nvidiafb_sync;
54445+ pax_open_kernel();
54446+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
54447+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
54448+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
54449+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
54450+ pax_close_kernel();
54451 info->pixmap.scan_align = 4;
54452 info->flags &= ~FBINFO_HWACCEL_DISABLED;
54453 info->flags |= FBINFO_READS_FAST;
54454 NVResetGraphics(info);
54455 } else {
54456- info->fbops->fb_imageblit = cfb_imageblit;
54457- info->fbops->fb_fillrect = cfb_fillrect;
54458- info->fbops->fb_copyarea = cfb_copyarea;
54459- info->fbops->fb_sync = NULL;
54460+ pax_open_kernel();
54461+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
54462+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
54463+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
54464+ *(void **)&info->fbops->fb_sync = NULL;
54465+ pax_close_kernel();
54466 info->pixmap.scan_align = 1;
54467 info->flags |= FBINFO_HWACCEL_DISABLED;
54468 info->flags &= ~FBINFO_READS_FAST;
54469@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
54470 info->pixmap.size = 8 * 1024;
54471 info->pixmap.flags = FB_PIXMAP_SYSTEM;
54472
54473- if (!hwcur)
54474- info->fbops->fb_cursor = NULL;
54475+ if (!hwcur) {
54476+ pax_open_kernel();
54477+ *(void **)&info->fbops->fb_cursor = NULL;
54478+ pax_close_kernel();
54479+ }
54480
54481 info->var.accel_flags = (!noaccel);
54482
54483diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
54484index 669a81f..e216d76 100644
54485--- a/drivers/video/omap2/dss/display.c
54486+++ b/drivers/video/omap2/dss/display.c
54487@@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
54488 snprintf(dssdev->alias, sizeof(dssdev->alias),
54489 "display%d", disp_num_counter++);
54490
54491+ pax_open_kernel();
54492 if (drv && drv->get_resolution == NULL)
54493- drv->get_resolution = omapdss_default_get_resolution;
54494+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
54495 if (drv && drv->get_recommended_bpp == NULL)
54496- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
54497+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
54498 if (drv && drv->get_timings == NULL)
54499- drv->get_timings = omapdss_default_get_timings;
54500+ *(void **)&drv->get_timings = omapdss_default_get_timings;
54501+ pax_close_kernel();
54502
54503 mutex_lock(&panel_list_mutex);
54504 list_add_tail(&dssdev->panel_list, &panel_list);
54505diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
54506index 83433cb..71e9b98 100644
54507--- a/drivers/video/s1d13xxxfb.c
54508+++ b/drivers/video/s1d13xxxfb.c
54509@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
54510
54511 switch(prod_id) {
54512 case S1D13506_PROD_ID: /* activate acceleration */
54513- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
54514- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
54515+ pax_open_kernel();
54516+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
54517+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
54518+ pax_close_kernel();
54519 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
54520 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
54521 break;
54522diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
54523index d513ed6..90b0de9 100644
54524--- a/drivers/video/smscufx.c
54525+++ b/drivers/video/smscufx.c
54526@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
54527 fb_deferred_io_cleanup(info);
54528 kfree(info->fbdefio);
54529 info->fbdefio = NULL;
54530- info->fbops->fb_mmap = ufx_ops_mmap;
54531+ pax_open_kernel();
54532+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
54533+ pax_close_kernel();
54534 }
54535
54536 pr_debug("released /dev/fb%d user=%d count=%d",
54537diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
54538index 025f14e..20eb4db 100644
54539--- a/drivers/video/udlfb.c
54540+++ b/drivers/video/udlfb.c
54541@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
54542 dlfb_urb_completion(urb);
54543
54544 error:
54545- atomic_add(bytes_sent, &dev->bytes_sent);
54546- atomic_add(bytes_identical, &dev->bytes_identical);
54547- atomic_add(width*height*2, &dev->bytes_rendered);
54548+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
54549+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
54550+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
54551 end_cycles = get_cycles();
54552- atomic_add(((unsigned int) ((end_cycles - start_cycles)
54553+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
54554 >> 10)), /* Kcycles */
54555 &dev->cpu_kcycles_used);
54556
54557@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
54558 dlfb_urb_completion(urb);
54559
54560 error:
54561- atomic_add(bytes_sent, &dev->bytes_sent);
54562- atomic_add(bytes_identical, &dev->bytes_identical);
54563- atomic_add(bytes_rendered, &dev->bytes_rendered);
54564+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
54565+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
54566+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
54567 end_cycles = get_cycles();
54568- atomic_add(((unsigned int) ((end_cycles - start_cycles)
54569+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
54570 >> 10)), /* Kcycles */
54571 &dev->cpu_kcycles_used);
54572 }
54573@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
54574 fb_deferred_io_cleanup(info);
54575 kfree(info->fbdefio);
54576 info->fbdefio = NULL;
54577- info->fbops->fb_mmap = dlfb_ops_mmap;
54578+ pax_open_kernel();
54579+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
54580+ pax_close_kernel();
54581 }
54582
54583 pr_warn("released /dev/fb%d user=%d count=%d\n",
54584@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
54585 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54586 struct dlfb_data *dev = fb_info->par;
54587 return snprintf(buf, PAGE_SIZE, "%u\n",
54588- atomic_read(&dev->bytes_rendered));
54589+ atomic_read_unchecked(&dev->bytes_rendered));
54590 }
54591
54592 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
54593@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
54594 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54595 struct dlfb_data *dev = fb_info->par;
54596 return snprintf(buf, PAGE_SIZE, "%u\n",
54597- atomic_read(&dev->bytes_identical));
54598+ atomic_read_unchecked(&dev->bytes_identical));
54599 }
54600
54601 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
54602@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
54603 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54604 struct dlfb_data *dev = fb_info->par;
54605 return snprintf(buf, PAGE_SIZE, "%u\n",
54606- atomic_read(&dev->bytes_sent));
54607+ atomic_read_unchecked(&dev->bytes_sent));
54608 }
54609
54610 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
54611@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
54612 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54613 struct dlfb_data *dev = fb_info->par;
54614 return snprintf(buf, PAGE_SIZE, "%u\n",
54615- atomic_read(&dev->cpu_kcycles_used));
54616+ atomic_read_unchecked(&dev->cpu_kcycles_used));
54617 }
54618
54619 static ssize_t edid_show(
54620@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
54621 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54622 struct dlfb_data *dev = fb_info->par;
54623
54624- atomic_set(&dev->bytes_rendered, 0);
54625- atomic_set(&dev->bytes_identical, 0);
54626- atomic_set(&dev->bytes_sent, 0);
54627- atomic_set(&dev->cpu_kcycles_used, 0);
54628+ atomic_set_unchecked(&dev->bytes_rendered, 0);
54629+ atomic_set_unchecked(&dev->bytes_identical, 0);
54630+ atomic_set_unchecked(&dev->bytes_sent, 0);
54631+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
54632
54633 return count;
54634 }
54635diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
54636index 256fba7..6e75516 100644
54637--- a/drivers/video/uvesafb.c
54638+++ b/drivers/video/uvesafb.c
54639@@ -19,6 +19,7 @@
54640 #include <linux/io.h>
54641 #include <linux/mutex.h>
54642 #include <linux/slab.h>
54643+#include <linux/moduleloader.h>
54644 #include <video/edid.h>
54645 #include <video/uvesafb.h>
54646 #ifdef CONFIG_X86
54647@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
54648 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
54649 par->pmi_setpal = par->ypan = 0;
54650 } else {
54651+
54652+#ifdef CONFIG_PAX_KERNEXEC
54653+#ifdef CONFIG_MODULES
54654+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
54655+#endif
54656+ if (!par->pmi_code) {
54657+ par->pmi_setpal = par->ypan = 0;
54658+ return 0;
54659+ }
54660+#endif
54661+
54662 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
54663 + task->t.regs.edi);
54664+
54665+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54666+ pax_open_kernel();
54667+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
54668+ pax_close_kernel();
54669+
54670+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
54671+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
54672+#else
54673 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
54674 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
54675+#endif
54676+
54677 printk(KERN_INFO "uvesafb: protected mode interface info at "
54678 "%04x:%04x\n",
54679 (u16)task->t.regs.es, (u16)task->t.regs.edi);
54680@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
54681 par->ypan = ypan;
54682
54683 if (par->pmi_setpal || par->ypan) {
54684+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
54685 if (__supported_pte_mask & _PAGE_NX) {
54686 par->pmi_setpal = par->ypan = 0;
54687 printk(KERN_WARNING "uvesafb: NX protection is active, "
54688 "better not use the PMI.\n");
54689- } else {
54690+ } else
54691+#endif
54692 uvesafb_vbe_getpmi(task, par);
54693- }
54694 }
54695 #else
54696 /* The protected mode interface is not available on non-x86. */
54697@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
54698 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
54699
54700 /* Disable blanking if the user requested so. */
54701- if (!blank)
54702- info->fbops->fb_blank = NULL;
54703+ if (!blank) {
54704+ pax_open_kernel();
54705+ *(void **)&info->fbops->fb_blank = NULL;
54706+ pax_close_kernel();
54707+ }
54708
54709 /*
54710 * Find out how much IO memory is required for the mode with
54711@@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
54712 info->flags = FBINFO_FLAG_DEFAULT |
54713 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
54714
54715- if (!par->ypan)
54716- info->fbops->fb_pan_display = NULL;
54717+ if (!par->ypan) {
54718+ pax_open_kernel();
54719+ *(void **)&info->fbops->fb_pan_display = NULL;
54720+ pax_close_kernel();
54721+ }
54722 }
54723
54724 static void uvesafb_init_mtrr(struct fb_info *info)
54725@@ -1792,6 +1822,11 @@ out_mode:
54726 out:
54727 kfree(par->vbe_modes);
54728
54729+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54730+ if (par->pmi_code)
54731+ module_free_exec(NULL, par->pmi_code);
54732+#endif
54733+
54734 framebuffer_release(info);
54735 return err;
54736 }
54737@@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
54738 kfree(par->vbe_modes);
54739 kfree(par->vbe_state_orig);
54740 kfree(par->vbe_state_saved);
54741+
54742+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54743+ if (par->pmi_code)
54744+ module_free_exec(NULL, par->pmi_code);
54745+#endif
54746+
54747 }
54748
54749 framebuffer_release(info);
54750diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
54751index 1c7da3b..56ea0bd 100644
54752--- a/drivers/video/vesafb.c
54753+++ b/drivers/video/vesafb.c
54754@@ -9,6 +9,7 @@
54755 */
54756
54757 #include <linux/module.h>
54758+#include <linux/moduleloader.h>
54759 #include <linux/kernel.h>
54760 #include <linux/errno.h>
54761 #include <linux/string.h>
54762@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
54763 static int vram_total; /* Set total amount of memory */
54764 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
54765 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
54766-static void (*pmi_start)(void) __read_mostly;
54767-static void (*pmi_pal) (void) __read_mostly;
54768+static void (*pmi_start)(void) __read_only;
54769+static void (*pmi_pal) (void) __read_only;
54770 static int depth __read_mostly;
54771 static int vga_compat __read_mostly;
54772 /* --------------------------------------------------------------------- */
54773@@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
54774 unsigned int size_remap;
54775 unsigned int size_total;
54776 char *option = NULL;
54777+ void *pmi_code = NULL;
54778
54779 /* ignore error return of fb_get_options */
54780 fb_get_options("vesafb", &option);
54781@@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
54782 size_remap = size_total;
54783 vesafb_fix.smem_len = size_remap;
54784
54785-#ifndef __i386__
54786- screen_info.vesapm_seg = 0;
54787-#endif
54788-
54789 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
54790 printk(KERN_WARNING
54791 "vesafb: cannot reserve video memory at 0x%lx\n",
54792@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
54793 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
54794 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
54795
54796+#ifdef __i386__
54797+
54798+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54799+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
54800+ if (!pmi_code)
54801+#elif !defined(CONFIG_PAX_KERNEXEC)
54802+ if (0)
54803+#endif
54804+
54805+#endif
54806+ screen_info.vesapm_seg = 0;
54807+
54808 if (screen_info.vesapm_seg) {
54809- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
54810- screen_info.vesapm_seg,screen_info.vesapm_off);
54811+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
54812+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
54813 }
54814
54815 if (screen_info.vesapm_seg < 0xc000)
54816@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
54817
54818 if (ypan || pmi_setpal) {
54819 unsigned short *pmi_base;
54820+
54821 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
54822- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
54823- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
54824+
54825+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54826+ pax_open_kernel();
54827+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
54828+#else
54829+ pmi_code = pmi_base;
54830+#endif
54831+
54832+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
54833+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
54834+
54835+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54836+ pmi_start = ktva_ktla(pmi_start);
54837+ pmi_pal = ktva_ktla(pmi_pal);
54838+ pax_close_kernel();
54839+#endif
54840+
54841 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
54842 if (pmi_base[3]) {
54843 printk(KERN_INFO "vesafb: pmi: ports = ");
54844@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
54845 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
54846 (ypan ? FBINFO_HWACCEL_YPAN : 0);
54847
54848- if (!ypan)
54849- info->fbops->fb_pan_display = NULL;
54850+ if (!ypan) {
54851+ pax_open_kernel();
54852+ *(void **)&info->fbops->fb_pan_display = NULL;
54853+ pax_close_kernel();
54854+ }
54855
54856 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
54857 err = -ENOMEM;
54858@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
54859 fb_info(info, "%s frame buffer device\n", info->fix.id);
54860 return 0;
54861 err:
54862+
54863+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54864+ module_free_exec(NULL, pmi_code);
54865+#endif
54866+
54867 if (info->screen_base)
54868 iounmap(info->screen_base);
54869 framebuffer_release(info);
54870diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
54871index 88714ae..16c2e11 100644
54872--- a/drivers/video/via/via_clock.h
54873+++ b/drivers/video/via/via_clock.h
54874@@ -56,7 +56,7 @@ struct via_clock {
54875
54876 void (*set_engine_pll_state)(u8 state);
54877 void (*set_engine_pll)(struct via_pll_config config);
54878-};
54879+} __no_const;
54880
54881
54882 static inline u32 get_pll_internal_frequency(u32 ref_freq,
54883diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
54884index fef20db..d28b1ab 100644
54885--- a/drivers/xen/xenfs/xenstored.c
54886+++ b/drivers/xen/xenfs/xenstored.c
54887@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
54888 static int xsd_kva_open(struct inode *inode, struct file *file)
54889 {
54890 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
54891+#ifdef CONFIG_GRKERNSEC_HIDESYM
54892+ NULL);
54893+#else
54894 xen_store_interface);
54895+#endif
54896+
54897 if (!file->private_data)
54898 return -ENOMEM;
54899 return 0;
54900diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
54901index 9ff073f..05cef23 100644
54902--- a/fs/9p/vfs_addr.c
54903+++ b/fs/9p/vfs_addr.c
54904@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
54905
54906 retval = v9fs_file_write_internal(inode,
54907 v9inode->writeback_fid,
54908- (__force const char __user *)buffer,
54909+ (const char __force_user *)buffer,
54910 len, &offset, 0);
54911 if (retval > 0)
54912 retval = 0;
54913diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
54914index 4e65aa9..043dc9a 100644
54915--- a/fs/9p/vfs_inode.c
54916+++ b/fs/9p/vfs_inode.c
54917@@ -1306,7 +1306,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
54918 void
54919 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
54920 {
54921- char *s = nd_get_link(nd);
54922+ const char *s = nd_get_link(nd);
54923
54924 p9_debug(P9_DEBUG_VFS, " %s %s\n",
54925 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
54926diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
54927index 370b24c..ff0be7b 100644
54928--- a/fs/Kconfig.binfmt
54929+++ b/fs/Kconfig.binfmt
54930@@ -103,7 +103,7 @@ config HAVE_AOUT
54931
54932 config BINFMT_AOUT
54933 tristate "Kernel support for a.out and ECOFF binaries"
54934- depends on HAVE_AOUT
54935+ depends on HAVE_AOUT && BROKEN
54936 ---help---
54937 A.out (Assembler.OUTput) is a set of formats for libraries and
54938 executables used in the earliest versions of UNIX. Linux used
54939diff --git a/fs/afs/inode.c b/fs/afs/inode.c
54940index ce25d75..dc09eeb 100644
54941--- a/fs/afs/inode.c
54942+++ b/fs/afs/inode.c
54943@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
54944 struct afs_vnode *vnode;
54945 struct super_block *sb;
54946 struct inode *inode;
54947- static atomic_t afs_autocell_ino;
54948+ static atomic_unchecked_t afs_autocell_ino;
54949
54950 _enter("{%x:%u},%*.*s,",
54951 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
54952@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
54953 data.fid.unique = 0;
54954 data.fid.vnode = 0;
54955
54956- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
54957+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
54958 afs_iget5_autocell_test, afs_iget5_set,
54959 &data);
54960 if (!inode) {
54961diff --git a/fs/aio.c b/fs/aio.c
54962index 062a5f6..e5618e0 100644
54963--- a/fs/aio.c
54964+++ b/fs/aio.c
54965@@ -374,7 +374,7 @@ static int aio_setup_ring(struct kioctx *ctx)
54966 size += sizeof(struct io_event) * nr_events;
54967
54968 nr_pages = PFN_UP(size);
54969- if (nr_pages < 0)
54970+ if (nr_pages <= 0)
54971 return -EINVAL;
54972
54973 file = aio_private_file(ctx, nr_pages);
54974diff --git a/fs/attr.c b/fs/attr.c
54975index 267968d..5dd8f96 100644
54976--- a/fs/attr.c
54977+++ b/fs/attr.c
54978@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
54979 unsigned long limit;
54980
54981 limit = rlimit(RLIMIT_FSIZE);
54982+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
54983 if (limit != RLIM_INFINITY && offset > limit)
54984 goto out_sig;
54985 if (offset > inode->i_sb->s_maxbytes)
54986diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
54987index 689e40d..515cac5 100644
54988--- a/fs/autofs4/waitq.c
54989+++ b/fs/autofs4/waitq.c
54990@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
54991 {
54992 unsigned long sigpipe, flags;
54993 mm_segment_t fs;
54994- const char *data = (const char *)addr;
54995+ const char __user *data = (const char __force_user *)addr;
54996 ssize_t wr = 0;
54997
54998 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
54999@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
55000 return 1;
55001 }
55002
55003+#ifdef CONFIG_GRKERNSEC_HIDESYM
55004+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
55005+#endif
55006+
55007 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55008 enum autofs_notify notify)
55009 {
55010@@ -373,7 +377,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55011
55012 /* If this is a direct mount request create a dummy name */
55013 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
55014+#ifdef CONFIG_GRKERNSEC_HIDESYM
55015+ /* this name does get written to userland via autofs4_write() */
55016+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
55017+#else
55018 qstr.len = sprintf(name, "%p", dentry);
55019+#endif
55020 else {
55021 qstr.len = autofs4_getpath(sbi, dentry, &name);
55022 if (!qstr.len) {
55023diff --git a/fs/befs/endian.h b/fs/befs/endian.h
55024index 2722387..56059b5 100644
55025--- a/fs/befs/endian.h
55026+++ b/fs/befs/endian.h
55027@@ -11,7 +11,7 @@
55028
55029 #include <asm/byteorder.h>
55030
55031-static inline u64
55032+static inline u64 __intentional_overflow(-1)
55033 fs64_to_cpu(const struct super_block *sb, fs64 n)
55034 {
55035 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55036@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
55037 return (__force fs64)cpu_to_be64(n);
55038 }
55039
55040-static inline u32
55041+static inline u32 __intentional_overflow(-1)
55042 fs32_to_cpu(const struct super_block *sb, fs32 n)
55043 {
55044 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55045@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
55046 return (__force fs32)cpu_to_be32(n);
55047 }
55048
55049-static inline u16
55050+static inline u16 __intentional_overflow(-1)
55051 fs16_to_cpu(const struct super_block *sb, fs16 n)
55052 {
55053 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55054diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
55055index ca0ba15..0fa3257 100644
55056--- a/fs/binfmt_aout.c
55057+++ b/fs/binfmt_aout.c
55058@@ -16,6 +16,7 @@
55059 #include <linux/string.h>
55060 #include <linux/fs.h>
55061 #include <linux/file.h>
55062+#include <linux/security.h>
55063 #include <linux/stat.h>
55064 #include <linux/fcntl.h>
55065 #include <linux/ptrace.h>
55066@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
55067 #endif
55068 # define START_STACK(u) ((void __user *)u.start_stack)
55069
55070+ memset(&dump, 0, sizeof(dump));
55071+
55072 fs = get_fs();
55073 set_fs(KERNEL_DS);
55074 has_dumped = 1;
55075@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
55076
55077 /* If the size of the dump file exceeds the rlimit, then see what would happen
55078 if we wrote the stack, but not the data area. */
55079+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
55080 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
55081 dump.u_dsize = 0;
55082
55083 /* Make sure we have enough room to write the stack and data areas. */
55084+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
55085 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
55086 dump.u_ssize = 0;
55087
55088@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
55089 rlim = rlimit(RLIMIT_DATA);
55090 if (rlim >= RLIM_INFINITY)
55091 rlim = ~0;
55092+
55093+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
55094 if (ex.a_data + ex.a_bss > rlim)
55095 return -ENOMEM;
55096
55097@@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
55098
55099 install_exec_creds(bprm);
55100
55101+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55102+ current->mm->pax_flags = 0UL;
55103+#endif
55104+
55105+#ifdef CONFIG_PAX_PAGEEXEC
55106+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
55107+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
55108+
55109+#ifdef CONFIG_PAX_EMUTRAMP
55110+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
55111+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
55112+#endif
55113+
55114+#ifdef CONFIG_PAX_MPROTECT
55115+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
55116+ current->mm->pax_flags |= MF_PAX_MPROTECT;
55117+#endif
55118+
55119+ }
55120+#endif
55121+
55122 if (N_MAGIC(ex) == OMAGIC) {
55123 unsigned long text_addr, map_size;
55124 loff_t pos;
55125@@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
55126 }
55127
55128 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
55129- PROT_READ | PROT_WRITE | PROT_EXEC,
55130+ PROT_READ | PROT_WRITE,
55131 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
55132 fd_offset + ex.a_text);
55133 if (error != N_DATADDR(ex)) {
55134diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
55135index 571a423..dbb9c6c 100644
55136--- a/fs/binfmt_elf.c
55137+++ b/fs/binfmt_elf.c
55138@@ -34,6 +34,7 @@
55139 #include <linux/utsname.h>
55140 #include <linux/coredump.h>
55141 #include <linux/sched.h>
55142+#include <linux/xattr.h>
55143 #include <asm/uaccess.h>
55144 #include <asm/param.h>
55145 #include <asm/page.h>
55146@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
55147 #define elf_core_dump NULL
55148 #endif
55149
55150+#ifdef CONFIG_PAX_MPROTECT
55151+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
55152+#endif
55153+
55154+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55155+static void elf_handle_mmap(struct file *file);
55156+#endif
55157+
55158 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
55159 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
55160 #else
55161@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
55162 .load_binary = load_elf_binary,
55163 .load_shlib = load_elf_library,
55164 .core_dump = elf_core_dump,
55165+
55166+#ifdef CONFIG_PAX_MPROTECT
55167+ .handle_mprotect= elf_handle_mprotect,
55168+#endif
55169+
55170+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55171+ .handle_mmap = elf_handle_mmap,
55172+#endif
55173+
55174 .min_coredump = ELF_EXEC_PAGESIZE,
55175 };
55176
55177@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
55178
55179 static int set_brk(unsigned long start, unsigned long end)
55180 {
55181+ unsigned long e = end;
55182+
55183 start = ELF_PAGEALIGN(start);
55184 end = ELF_PAGEALIGN(end);
55185 if (end > start) {
55186@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
55187 if (BAD_ADDR(addr))
55188 return addr;
55189 }
55190- current->mm->start_brk = current->mm->brk = end;
55191+ current->mm->start_brk = current->mm->brk = e;
55192 return 0;
55193 }
55194
55195@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55196 elf_addr_t __user *u_rand_bytes;
55197 const char *k_platform = ELF_PLATFORM;
55198 const char *k_base_platform = ELF_BASE_PLATFORM;
55199- unsigned char k_rand_bytes[16];
55200+ u32 k_rand_bytes[4];
55201 int items;
55202 elf_addr_t *elf_info;
55203 int ei_index = 0;
55204 const struct cred *cred = current_cred();
55205 struct vm_area_struct *vma;
55206+ unsigned long saved_auxv[AT_VECTOR_SIZE];
55207
55208 /*
55209 * In some cases (e.g. Hyper-Threading), we want to avoid L1
55210@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55211 * Generate 16 random bytes for userspace PRNG seeding.
55212 */
55213 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
55214- u_rand_bytes = (elf_addr_t __user *)
55215- STACK_ALLOC(p, sizeof(k_rand_bytes));
55216+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
55217+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
55218+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
55219+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
55220+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
55221+ u_rand_bytes = (elf_addr_t __user *) p;
55222 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
55223 return -EFAULT;
55224
55225@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55226 return -EFAULT;
55227 current->mm->env_end = p;
55228
55229+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
55230+
55231 /* Put the elf_info on the stack in the right place. */
55232 sp = (elf_addr_t __user *)envp + 1;
55233- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
55234+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
55235 return -EFAULT;
55236 return 0;
55237 }
55238@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
55239 an ELF header */
55240
55241 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55242- struct file *interpreter, unsigned long *interp_map_addr,
55243- unsigned long no_base)
55244+ struct file *interpreter, unsigned long no_base)
55245 {
55246 struct elf_phdr *elf_phdata;
55247 struct elf_phdr *eppnt;
55248- unsigned long load_addr = 0;
55249+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
55250 int load_addr_set = 0;
55251 unsigned long last_bss = 0, elf_bss = 0;
55252- unsigned long error = ~0UL;
55253+ unsigned long error = -EINVAL;
55254 unsigned long total_size;
55255 int retval, i, size;
55256
55257@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55258 goto out_close;
55259 }
55260
55261+#ifdef CONFIG_PAX_SEGMEXEC
55262+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
55263+ pax_task_size = SEGMEXEC_TASK_SIZE;
55264+#endif
55265+
55266 eppnt = elf_phdata;
55267 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
55268 if (eppnt->p_type == PT_LOAD) {
55269@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55270 map_addr = elf_map(interpreter, load_addr + vaddr,
55271 eppnt, elf_prot, elf_type, total_size);
55272 total_size = 0;
55273- if (!*interp_map_addr)
55274- *interp_map_addr = map_addr;
55275 error = map_addr;
55276 if (BAD_ADDR(map_addr))
55277 goto out_close;
55278@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55279 k = load_addr + eppnt->p_vaddr;
55280 if (BAD_ADDR(k) ||
55281 eppnt->p_filesz > eppnt->p_memsz ||
55282- eppnt->p_memsz > TASK_SIZE ||
55283- TASK_SIZE - eppnt->p_memsz < k) {
55284+ eppnt->p_memsz > pax_task_size ||
55285+ pax_task_size - eppnt->p_memsz < k) {
55286 error = -ENOMEM;
55287 goto out_close;
55288 }
55289@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55290 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
55291
55292 /* Map the last of the bss segment */
55293- error = vm_brk(elf_bss, last_bss - elf_bss);
55294- if (BAD_ADDR(error))
55295- goto out_close;
55296+ if (last_bss > elf_bss) {
55297+ error = vm_brk(elf_bss, last_bss - elf_bss);
55298+ if (BAD_ADDR(error))
55299+ goto out_close;
55300+ }
55301 }
55302
55303 error = load_addr;
55304@@ -538,6 +569,336 @@ out:
55305 return error;
55306 }
55307
55308+#ifdef CONFIG_PAX_PT_PAX_FLAGS
55309+#ifdef CONFIG_PAX_SOFTMODE
55310+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
55311+{
55312+ unsigned long pax_flags = 0UL;
55313+
55314+#ifdef CONFIG_PAX_PAGEEXEC
55315+ if (elf_phdata->p_flags & PF_PAGEEXEC)
55316+ pax_flags |= MF_PAX_PAGEEXEC;
55317+#endif
55318+
55319+#ifdef CONFIG_PAX_SEGMEXEC
55320+ if (elf_phdata->p_flags & PF_SEGMEXEC)
55321+ pax_flags |= MF_PAX_SEGMEXEC;
55322+#endif
55323+
55324+#ifdef CONFIG_PAX_EMUTRAMP
55325+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
55326+ pax_flags |= MF_PAX_EMUTRAMP;
55327+#endif
55328+
55329+#ifdef CONFIG_PAX_MPROTECT
55330+ if (elf_phdata->p_flags & PF_MPROTECT)
55331+ pax_flags |= MF_PAX_MPROTECT;
55332+#endif
55333+
55334+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
55335+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
55336+ pax_flags |= MF_PAX_RANDMMAP;
55337+#endif
55338+
55339+ return pax_flags;
55340+}
55341+#endif
55342+
55343+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
55344+{
55345+ unsigned long pax_flags = 0UL;
55346+
55347+#ifdef CONFIG_PAX_PAGEEXEC
55348+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
55349+ pax_flags |= MF_PAX_PAGEEXEC;
55350+#endif
55351+
55352+#ifdef CONFIG_PAX_SEGMEXEC
55353+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
55354+ pax_flags |= MF_PAX_SEGMEXEC;
55355+#endif
55356+
55357+#ifdef CONFIG_PAX_EMUTRAMP
55358+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
55359+ pax_flags |= MF_PAX_EMUTRAMP;
55360+#endif
55361+
55362+#ifdef CONFIG_PAX_MPROTECT
55363+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
55364+ pax_flags |= MF_PAX_MPROTECT;
55365+#endif
55366+
55367+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
55368+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
55369+ pax_flags |= MF_PAX_RANDMMAP;
55370+#endif
55371+
55372+ return pax_flags;
55373+}
55374+#endif
55375+
55376+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
55377+#ifdef CONFIG_PAX_SOFTMODE
55378+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
55379+{
55380+ unsigned long pax_flags = 0UL;
55381+
55382+#ifdef CONFIG_PAX_PAGEEXEC
55383+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
55384+ pax_flags |= MF_PAX_PAGEEXEC;
55385+#endif
55386+
55387+#ifdef CONFIG_PAX_SEGMEXEC
55388+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
55389+ pax_flags |= MF_PAX_SEGMEXEC;
55390+#endif
55391+
55392+#ifdef CONFIG_PAX_EMUTRAMP
55393+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
55394+ pax_flags |= MF_PAX_EMUTRAMP;
55395+#endif
55396+
55397+#ifdef CONFIG_PAX_MPROTECT
55398+ if (pax_flags_softmode & MF_PAX_MPROTECT)
55399+ pax_flags |= MF_PAX_MPROTECT;
55400+#endif
55401+
55402+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
55403+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
55404+ pax_flags |= MF_PAX_RANDMMAP;
55405+#endif
55406+
55407+ return pax_flags;
55408+}
55409+#endif
55410+
55411+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
55412+{
55413+ unsigned long pax_flags = 0UL;
55414+
55415+#ifdef CONFIG_PAX_PAGEEXEC
55416+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
55417+ pax_flags |= MF_PAX_PAGEEXEC;
55418+#endif
55419+
55420+#ifdef CONFIG_PAX_SEGMEXEC
55421+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
55422+ pax_flags |= MF_PAX_SEGMEXEC;
55423+#endif
55424+
55425+#ifdef CONFIG_PAX_EMUTRAMP
55426+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
55427+ pax_flags |= MF_PAX_EMUTRAMP;
55428+#endif
55429+
55430+#ifdef CONFIG_PAX_MPROTECT
55431+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
55432+ pax_flags |= MF_PAX_MPROTECT;
55433+#endif
55434+
55435+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
55436+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
55437+ pax_flags |= MF_PAX_RANDMMAP;
55438+#endif
55439+
55440+ return pax_flags;
55441+}
55442+#endif
55443+
55444+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55445+static unsigned long pax_parse_defaults(void)
55446+{
55447+ unsigned long pax_flags = 0UL;
55448+
55449+#ifdef CONFIG_PAX_SOFTMODE
55450+ if (pax_softmode)
55451+ return pax_flags;
55452+#endif
55453+
55454+#ifdef CONFIG_PAX_PAGEEXEC
55455+ pax_flags |= MF_PAX_PAGEEXEC;
55456+#endif
55457+
55458+#ifdef CONFIG_PAX_SEGMEXEC
55459+ pax_flags |= MF_PAX_SEGMEXEC;
55460+#endif
55461+
55462+#ifdef CONFIG_PAX_MPROTECT
55463+ pax_flags |= MF_PAX_MPROTECT;
55464+#endif
55465+
55466+#ifdef CONFIG_PAX_RANDMMAP
55467+ if (randomize_va_space)
55468+ pax_flags |= MF_PAX_RANDMMAP;
55469+#endif
55470+
55471+ return pax_flags;
55472+}
55473+
55474+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
55475+{
55476+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
55477+
55478+#ifdef CONFIG_PAX_EI_PAX
55479+
55480+#ifdef CONFIG_PAX_SOFTMODE
55481+ if (pax_softmode)
55482+ return pax_flags;
55483+#endif
55484+
55485+ pax_flags = 0UL;
55486+
55487+#ifdef CONFIG_PAX_PAGEEXEC
55488+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
55489+ pax_flags |= MF_PAX_PAGEEXEC;
55490+#endif
55491+
55492+#ifdef CONFIG_PAX_SEGMEXEC
55493+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
55494+ pax_flags |= MF_PAX_SEGMEXEC;
55495+#endif
55496+
55497+#ifdef CONFIG_PAX_EMUTRAMP
55498+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
55499+ pax_flags |= MF_PAX_EMUTRAMP;
55500+#endif
55501+
55502+#ifdef CONFIG_PAX_MPROTECT
55503+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
55504+ pax_flags |= MF_PAX_MPROTECT;
55505+#endif
55506+
55507+#ifdef CONFIG_PAX_ASLR
55508+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
55509+ pax_flags |= MF_PAX_RANDMMAP;
55510+#endif
55511+
55512+#endif
55513+
55514+ return pax_flags;
55515+
55516+}
55517+
55518+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
55519+{
55520+
55521+#ifdef CONFIG_PAX_PT_PAX_FLAGS
55522+ unsigned long i;
55523+
55524+ for (i = 0UL; i < elf_ex->e_phnum; i++)
55525+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
55526+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
55527+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
55528+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
55529+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
55530+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
55531+ return PAX_PARSE_FLAGS_FALLBACK;
55532+
55533+#ifdef CONFIG_PAX_SOFTMODE
55534+ if (pax_softmode)
55535+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
55536+ else
55537+#endif
55538+
55539+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
55540+ break;
55541+ }
55542+#endif
55543+
55544+ return PAX_PARSE_FLAGS_FALLBACK;
55545+}
55546+
55547+static unsigned long pax_parse_xattr_pax(struct file * const file)
55548+{
55549+
55550+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
55551+ ssize_t xattr_size, i;
55552+ unsigned char xattr_value[sizeof("pemrs") - 1];
55553+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
55554+
55555+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
55556+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
55557+ return PAX_PARSE_FLAGS_FALLBACK;
55558+
55559+ for (i = 0; i < xattr_size; i++)
55560+ switch (xattr_value[i]) {
55561+ default:
55562+ return PAX_PARSE_FLAGS_FALLBACK;
55563+
55564+#define parse_flag(option1, option2, flag) \
55565+ case option1: \
55566+ if (pax_flags_hardmode & MF_PAX_##flag) \
55567+ return PAX_PARSE_FLAGS_FALLBACK;\
55568+ pax_flags_hardmode |= MF_PAX_##flag; \
55569+ break; \
55570+ case option2: \
55571+ if (pax_flags_softmode & MF_PAX_##flag) \
55572+ return PAX_PARSE_FLAGS_FALLBACK;\
55573+ pax_flags_softmode |= MF_PAX_##flag; \
55574+ break;
55575+
55576+ parse_flag('p', 'P', PAGEEXEC);
55577+ parse_flag('e', 'E', EMUTRAMP);
55578+ parse_flag('m', 'M', MPROTECT);
55579+ parse_flag('r', 'R', RANDMMAP);
55580+ parse_flag('s', 'S', SEGMEXEC);
55581+
55582+#undef parse_flag
55583+ }
55584+
55585+ if (pax_flags_hardmode & pax_flags_softmode)
55586+ return PAX_PARSE_FLAGS_FALLBACK;
55587+
55588+#ifdef CONFIG_PAX_SOFTMODE
55589+ if (pax_softmode)
55590+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
55591+ else
55592+#endif
55593+
55594+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
55595+#else
55596+ return PAX_PARSE_FLAGS_FALLBACK;
55597+#endif
55598+
55599+}
55600+
55601+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
55602+{
55603+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
55604+
55605+ pax_flags = pax_parse_defaults();
55606+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
55607+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
55608+ xattr_pax_flags = pax_parse_xattr_pax(file);
55609+
55610+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
55611+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
55612+ pt_pax_flags != xattr_pax_flags)
55613+ return -EINVAL;
55614+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
55615+ pax_flags = xattr_pax_flags;
55616+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
55617+ pax_flags = pt_pax_flags;
55618+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
55619+ pax_flags = ei_pax_flags;
55620+
55621+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
55622+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
55623+ if ((__supported_pte_mask & _PAGE_NX))
55624+ pax_flags &= ~MF_PAX_SEGMEXEC;
55625+ else
55626+ pax_flags &= ~MF_PAX_PAGEEXEC;
55627+ }
55628+#endif
55629+
55630+ if (0 > pax_check_flags(&pax_flags))
55631+ return -EINVAL;
55632+
55633+ current->mm->pax_flags = pax_flags;
55634+ return 0;
55635+}
55636+#endif
55637+
55638 /*
55639 * These are the functions used to load ELF style executables and shared
55640 * libraries. There is no binary dependent code anywhere else.
55641@@ -554,6 +915,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
55642 {
55643 unsigned int random_variable = 0;
55644
55645+#ifdef CONFIG_PAX_RANDUSTACK
55646+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
55647+ return stack_top - current->mm->delta_stack;
55648+#endif
55649+
55650 if ((current->flags & PF_RANDOMIZE) &&
55651 !(current->personality & ADDR_NO_RANDOMIZE)) {
55652 random_variable = get_random_int() & STACK_RND_MASK;
55653@@ -572,7 +938,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
55654 unsigned long load_addr = 0, load_bias = 0;
55655 int load_addr_set = 0;
55656 char * elf_interpreter = NULL;
55657- unsigned long error;
55658+ unsigned long error = 0;
55659 struct elf_phdr *elf_ppnt, *elf_phdata;
55660 unsigned long elf_bss, elf_brk;
55661 int retval, i;
55662@@ -582,12 +948,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
55663 unsigned long start_code, end_code, start_data, end_data;
55664 unsigned long reloc_func_desc __maybe_unused = 0;
55665 int executable_stack = EXSTACK_DEFAULT;
55666- unsigned long def_flags = 0;
55667 struct pt_regs *regs = current_pt_regs();
55668 struct {
55669 struct elfhdr elf_ex;
55670 struct elfhdr interp_elf_ex;
55671 } *loc;
55672+ unsigned long pax_task_size;
55673
55674 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
55675 if (!loc) {
55676@@ -723,11 +1089,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
55677 goto out_free_dentry;
55678
55679 /* OK, This is the point of no return */
55680- current->mm->def_flags = def_flags;
55681+ current->mm->def_flags = 0;
55682
55683 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
55684 may depend on the personality. */
55685 SET_PERSONALITY(loc->elf_ex);
55686+
55687+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55688+ current->mm->pax_flags = 0UL;
55689+#endif
55690+
55691+#ifdef CONFIG_PAX_DLRESOLVE
55692+ current->mm->call_dl_resolve = 0UL;
55693+#endif
55694+
55695+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
55696+ current->mm->call_syscall = 0UL;
55697+#endif
55698+
55699+#ifdef CONFIG_PAX_ASLR
55700+ current->mm->delta_mmap = 0UL;
55701+ current->mm->delta_stack = 0UL;
55702+#endif
55703+
55704+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55705+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
55706+ send_sig(SIGKILL, current, 0);
55707+ goto out_free_dentry;
55708+ }
55709+#endif
55710+
55711+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
55712+ pax_set_initial_flags(bprm);
55713+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
55714+ if (pax_set_initial_flags_func)
55715+ (pax_set_initial_flags_func)(bprm);
55716+#endif
55717+
55718+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
55719+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
55720+ current->mm->context.user_cs_limit = PAGE_SIZE;
55721+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
55722+ }
55723+#endif
55724+
55725+#ifdef CONFIG_PAX_SEGMEXEC
55726+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
55727+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
55728+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
55729+ pax_task_size = SEGMEXEC_TASK_SIZE;
55730+ current->mm->def_flags |= VM_NOHUGEPAGE;
55731+ } else
55732+#endif
55733+
55734+ pax_task_size = TASK_SIZE;
55735+
55736+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
55737+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
55738+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
55739+ put_cpu();
55740+ }
55741+#endif
55742+
55743+#ifdef CONFIG_PAX_ASLR
55744+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
55745+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
55746+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
55747+ }
55748+#endif
55749+
55750+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
55751+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
55752+ executable_stack = EXSTACK_DISABLE_X;
55753+ current->personality &= ~READ_IMPLIES_EXEC;
55754+ } else
55755+#endif
55756+
55757 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
55758 current->personality |= READ_IMPLIES_EXEC;
55759
55760@@ -817,6 +1254,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
55761 #else
55762 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
55763 #endif
55764+
55765+#ifdef CONFIG_PAX_RANDMMAP
55766+ /* PaX: randomize base address at the default exe base if requested */
55767+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
55768+#ifdef CONFIG_SPARC64
55769+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
55770+#else
55771+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
55772+#endif
55773+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
55774+ elf_flags |= MAP_FIXED;
55775+ }
55776+#endif
55777+
55778 }
55779
55780 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
55781@@ -849,9 +1300,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
55782 * allowed task size. Note that p_filesz must always be
55783 * <= p_memsz so it is only necessary to check p_memsz.
55784 */
55785- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
55786- elf_ppnt->p_memsz > TASK_SIZE ||
55787- TASK_SIZE - elf_ppnt->p_memsz < k) {
55788+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
55789+ elf_ppnt->p_memsz > pax_task_size ||
55790+ pax_task_size - elf_ppnt->p_memsz < k) {
55791 /* set_brk can never work. Avoid overflows. */
55792 send_sig(SIGKILL, current, 0);
55793 retval = -EINVAL;
55794@@ -890,17 +1341,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
55795 goto out_free_dentry;
55796 }
55797 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
55798- send_sig(SIGSEGV, current, 0);
55799- retval = -EFAULT; /* Nobody gets to see this, but.. */
55800- goto out_free_dentry;
55801+ /*
55802+ * This bss-zeroing can fail if the ELF
55803+ * file specifies odd protections. So
55804+ * we don't check the return value
55805+ */
55806 }
55807
55808+#ifdef CONFIG_PAX_RANDMMAP
55809+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
55810+ unsigned long start, size, flags;
55811+ vm_flags_t vm_flags;
55812+
55813+ start = ELF_PAGEALIGN(elf_brk);
55814+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
55815+ flags = MAP_FIXED | MAP_PRIVATE;
55816+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
55817+
55818+ down_write(&current->mm->mmap_sem);
55819+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
55820+ retval = -ENOMEM;
55821+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
55822+// if (current->personality & ADDR_NO_RANDOMIZE)
55823+// vm_flags |= VM_READ | VM_MAYREAD;
55824+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
55825+ retval = IS_ERR_VALUE(start) ? start : 0;
55826+ }
55827+ up_write(&current->mm->mmap_sem);
55828+ if (retval == 0)
55829+ retval = set_brk(start + size, start + size + PAGE_SIZE);
55830+ if (retval < 0) {
55831+ send_sig(SIGKILL, current, 0);
55832+ goto out_free_dentry;
55833+ }
55834+ }
55835+#endif
55836+
55837 if (elf_interpreter) {
55838- unsigned long interp_map_addr = 0;
55839-
55840 elf_entry = load_elf_interp(&loc->interp_elf_ex,
55841 interpreter,
55842- &interp_map_addr,
55843 load_bias);
55844 if (!IS_ERR((void *)elf_entry)) {
55845 /*
55846@@ -1122,7 +1601,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
55847 * Decide what to dump of a segment, part, all or none.
55848 */
55849 static unsigned long vma_dump_size(struct vm_area_struct *vma,
55850- unsigned long mm_flags)
55851+ unsigned long mm_flags, long signr)
55852 {
55853 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
55854
55855@@ -1160,7 +1639,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
55856 if (vma->vm_file == NULL)
55857 return 0;
55858
55859- if (FILTER(MAPPED_PRIVATE))
55860+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
55861 goto whole;
55862
55863 /*
55864@@ -1367,9 +1846,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
55865 {
55866 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
55867 int i = 0;
55868- do
55869+ do {
55870 i += 2;
55871- while (auxv[i - 2] != AT_NULL);
55872+ } while (auxv[i - 2] != AT_NULL);
55873 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
55874 }
55875
55876@@ -1378,7 +1857,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
55877 {
55878 mm_segment_t old_fs = get_fs();
55879 set_fs(KERNEL_DS);
55880- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
55881+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
55882 set_fs(old_fs);
55883 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
55884 }
55885@@ -2002,14 +2481,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
55886 }
55887
55888 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
55889- unsigned long mm_flags)
55890+ struct coredump_params *cprm)
55891 {
55892 struct vm_area_struct *vma;
55893 size_t size = 0;
55894
55895 for (vma = first_vma(current, gate_vma); vma != NULL;
55896 vma = next_vma(vma, gate_vma))
55897- size += vma_dump_size(vma, mm_flags);
55898+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
55899 return size;
55900 }
55901
55902@@ -2100,7 +2579,7 @@ static int elf_core_dump(struct coredump_params *cprm)
55903
55904 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
55905
55906- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
55907+ offset += elf_core_vma_data_size(gate_vma, cprm);
55908 offset += elf_core_extra_data_size();
55909 e_shoff = offset;
55910
55911@@ -2128,7 +2607,7 @@ static int elf_core_dump(struct coredump_params *cprm)
55912 phdr.p_offset = offset;
55913 phdr.p_vaddr = vma->vm_start;
55914 phdr.p_paddr = 0;
55915- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
55916+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
55917 phdr.p_memsz = vma->vm_end - vma->vm_start;
55918 offset += phdr.p_filesz;
55919 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
55920@@ -2161,7 +2640,7 @@ static int elf_core_dump(struct coredump_params *cprm)
55921 unsigned long addr;
55922 unsigned long end;
55923
55924- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
55925+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
55926
55927 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
55928 struct page *page;
55929@@ -2202,6 +2681,167 @@ out:
55930
55931 #endif /* CONFIG_ELF_CORE */
55932
55933+#ifdef CONFIG_PAX_MPROTECT
55934+/* PaX: non-PIC ELF libraries need relocations on their executable segments
55935+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
55936+ * we'll remove VM_MAYWRITE for good on RELRO segments.
55937+ *
55938+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
55939+ * basis because we want to allow the common case and not the special ones.
55940+ */
55941+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
55942+{
55943+ struct elfhdr elf_h;
55944+ struct elf_phdr elf_p;
55945+ unsigned long i;
55946+ unsigned long oldflags;
55947+ bool is_textrel_rw, is_textrel_rx, is_relro;
55948+
55949+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
55950+ return;
55951+
55952+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
55953+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
55954+
55955+#ifdef CONFIG_PAX_ELFRELOCS
55956+ /* possible TEXTREL */
55957+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
55958+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
55959+#else
55960+ is_textrel_rw = false;
55961+ is_textrel_rx = false;
55962+#endif
55963+
55964+ /* possible RELRO */
55965+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
55966+
55967+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
55968+ return;
55969+
55970+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
55971+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
55972+
55973+#ifdef CONFIG_PAX_ETEXECRELOCS
55974+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
55975+#else
55976+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
55977+#endif
55978+
55979+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
55980+ !elf_check_arch(&elf_h) ||
55981+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
55982+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
55983+ return;
55984+
55985+ for (i = 0UL; i < elf_h.e_phnum; i++) {
55986+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
55987+ return;
55988+ switch (elf_p.p_type) {
55989+ case PT_DYNAMIC:
55990+ if (!is_textrel_rw && !is_textrel_rx)
55991+ continue;
55992+ i = 0UL;
55993+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
55994+ elf_dyn dyn;
55995+
55996+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
55997+ break;
55998+ if (dyn.d_tag == DT_NULL)
55999+ break;
56000+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
56001+ gr_log_textrel(vma);
56002+ if (is_textrel_rw)
56003+ vma->vm_flags |= VM_MAYWRITE;
56004+ else
56005+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
56006+ vma->vm_flags &= ~VM_MAYWRITE;
56007+ break;
56008+ }
56009+ i++;
56010+ }
56011+ is_textrel_rw = false;
56012+ is_textrel_rx = false;
56013+ continue;
56014+
56015+ case PT_GNU_RELRO:
56016+ if (!is_relro)
56017+ continue;
56018+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
56019+ vma->vm_flags &= ~VM_MAYWRITE;
56020+ is_relro = false;
56021+ continue;
56022+
56023+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56024+ case PT_PAX_FLAGS: {
56025+ const char *msg_mprotect = "", *msg_emutramp = "";
56026+ char *buffer_lib, *buffer_exe;
56027+
56028+ if (elf_p.p_flags & PF_NOMPROTECT)
56029+ msg_mprotect = "MPROTECT disabled";
56030+
56031+#ifdef CONFIG_PAX_EMUTRAMP
56032+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
56033+ msg_emutramp = "EMUTRAMP enabled";
56034+#endif
56035+
56036+ if (!msg_mprotect[0] && !msg_emutramp[0])
56037+ continue;
56038+
56039+ if (!printk_ratelimit())
56040+ continue;
56041+
56042+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
56043+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
56044+ if (buffer_lib && buffer_exe) {
56045+ char *path_lib, *path_exe;
56046+
56047+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
56048+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
56049+
56050+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
56051+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
56052+
56053+ }
56054+ free_page((unsigned long)buffer_exe);
56055+ free_page((unsigned long)buffer_lib);
56056+ continue;
56057+ }
56058+#endif
56059+
56060+ }
56061+ }
56062+}
56063+#endif
56064+
56065+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56066+
56067+extern int grsec_enable_log_rwxmaps;
56068+
56069+static void elf_handle_mmap(struct file *file)
56070+{
56071+ struct elfhdr elf_h;
56072+ struct elf_phdr elf_p;
56073+ unsigned long i;
56074+
56075+ if (!grsec_enable_log_rwxmaps)
56076+ return;
56077+
56078+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56079+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56080+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
56081+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56082+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56083+ return;
56084+
56085+ for (i = 0UL; i < elf_h.e_phnum; i++) {
56086+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56087+ return;
56088+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
56089+ gr_log_ptgnustack(file);
56090+ }
56091+}
56092+#endif
56093+
56094 static int __init init_elf_binfmt(void)
56095 {
56096 register_binfmt(&elf_format);
56097diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
56098index d50bbe5..af3b649 100644
56099--- a/fs/binfmt_flat.c
56100+++ b/fs/binfmt_flat.c
56101@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
56102 realdatastart = (unsigned long) -ENOMEM;
56103 printk("Unable to allocate RAM for process data, errno %d\n",
56104 (int)-realdatastart);
56105+ down_write(&current->mm->mmap_sem);
56106 vm_munmap(textpos, text_len);
56107+ up_write(&current->mm->mmap_sem);
56108 ret = realdatastart;
56109 goto err;
56110 }
56111@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
56112 }
56113 if (IS_ERR_VALUE(result)) {
56114 printk("Unable to read data+bss, errno %d\n", (int)-result);
56115+ down_write(&current->mm->mmap_sem);
56116 vm_munmap(textpos, text_len);
56117 vm_munmap(realdatastart, len);
56118+ up_write(&current->mm->mmap_sem);
56119 ret = result;
56120 goto err;
56121 }
56122@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
56123 }
56124 if (IS_ERR_VALUE(result)) {
56125 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
56126+ down_write(&current->mm->mmap_sem);
56127 vm_munmap(textpos, text_len + data_len + extra +
56128 MAX_SHARED_LIBS * sizeof(unsigned long));
56129+ up_write(&current->mm->mmap_sem);
56130 ret = result;
56131 goto err;
56132 }
56133diff --git a/fs/bio.c b/fs/bio.c
56134index 33d79a4..c3c9893 100644
56135--- a/fs/bio.c
56136+++ b/fs/bio.c
56137@@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
56138 /*
56139 * Overflow, abort
56140 */
56141- if (end < start)
56142+ if (end < start || end - start > INT_MAX - nr_pages)
56143 return ERR_PTR(-EINVAL);
56144
56145 nr_pages += end - start;
56146@@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
56147 /*
56148 * Overflow, abort
56149 */
56150- if (end < start)
56151+ if (end < start || end - start > INT_MAX - nr_pages)
56152 return ERR_PTR(-EINVAL);
56153
56154 nr_pages += end - start;
56155@@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
56156 const int read = bio_data_dir(bio) == READ;
56157 struct bio_map_data *bmd = bio->bi_private;
56158 int i;
56159- char *p = bmd->sgvecs[0].iov_base;
56160+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
56161
56162 bio_for_each_segment_all(bvec, bio, i) {
56163 char *addr = page_address(bvec->bv_page);
56164diff --git a/fs/block_dev.c b/fs/block_dev.c
56165index 1e86823..8e34695 100644
56166--- a/fs/block_dev.c
56167+++ b/fs/block_dev.c
56168@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
56169 else if (bdev->bd_contains == bdev)
56170 return true; /* is a whole device which isn't held */
56171
56172- else if (whole->bd_holder == bd_may_claim)
56173+ else if (whole->bd_holder == (void *)bd_may_claim)
56174 return true; /* is a partition of a device that is being partitioned */
56175 else if (whole->bd_holder != NULL)
56176 return false; /* is a partition of a held device */
56177diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
56178index 316136b..e7a3a50 100644
56179--- a/fs/btrfs/ctree.c
56180+++ b/fs/btrfs/ctree.c
56181@@ -1028,9 +1028,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
56182 free_extent_buffer(buf);
56183 add_root_to_dirty_list(root);
56184 } else {
56185- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
56186- parent_start = parent->start;
56187- else
56188+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
56189+ if (parent)
56190+ parent_start = parent->start;
56191+ else
56192+ parent_start = 0;
56193+ } else
56194 parent_start = 0;
56195
56196 WARN_ON(trans->transid != btrfs_header_generation(parent));
56197diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
56198index 8d292fb..bc205c2 100644
56199--- a/fs/btrfs/delayed-inode.c
56200+++ b/fs/btrfs/delayed-inode.c
56201@@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
56202
56203 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
56204 {
56205- int seq = atomic_inc_return(&delayed_root->items_seq);
56206+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
56207 if ((atomic_dec_return(&delayed_root->items) <
56208 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
56209 waitqueue_active(&delayed_root->wait))
56210@@ -1379,7 +1379,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
56211 static int refs_newer(struct btrfs_delayed_root *delayed_root,
56212 int seq, int count)
56213 {
56214- int val = atomic_read(&delayed_root->items_seq);
56215+ int val = atomic_read_unchecked(&delayed_root->items_seq);
56216
56217 if (val < seq || val >= seq + count)
56218 return 1;
56219@@ -1396,7 +1396,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
56220 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
56221 return;
56222
56223- seq = atomic_read(&delayed_root->items_seq);
56224+ seq = atomic_read_unchecked(&delayed_root->items_seq);
56225
56226 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
56227 int ret;
56228diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
56229index a4b38f9..f86a509 100644
56230--- a/fs/btrfs/delayed-inode.h
56231+++ b/fs/btrfs/delayed-inode.h
56232@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
56233 */
56234 struct list_head prepare_list;
56235 atomic_t items; /* for delayed items */
56236- atomic_t items_seq; /* for delayed items */
56237+ atomic_unchecked_t items_seq; /* for delayed items */
56238 int nodes; /* for delayed nodes */
56239 wait_queue_head_t wait;
56240 };
56241@@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
56242 struct btrfs_delayed_root *delayed_root)
56243 {
56244 atomic_set(&delayed_root->items, 0);
56245- atomic_set(&delayed_root->items_seq, 0);
56246+ atomic_set_unchecked(&delayed_root->items_seq, 0);
56247 delayed_root->nodes = 0;
56248 spin_lock_init(&delayed_root->lock);
56249 init_waitqueue_head(&delayed_root->wait);
56250diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
56251index 9f831bb..14afde5 100644
56252--- a/fs/btrfs/ioctl.c
56253+++ b/fs/btrfs/ioctl.c
56254@@ -3457,9 +3457,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
56255 for (i = 0; i < num_types; i++) {
56256 struct btrfs_space_info *tmp;
56257
56258+ /* Don't copy in more than we allocated */
56259 if (!slot_count)
56260 break;
56261
56262+ slot_count--;
56263+
56264 info = NULL;
56265 rcu_read_lock();
56266 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
56267@@ -3481,10 +3484,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
56268 memcpy(dest, &space, sizeof(space));
56269 dest++;
56270 space_args.total_spaces++;
56271- slot_count--;
56272 }
56273- if (!slot_count)
56274- break;
56275 }
56276 up_read(&info->groups_sem);
56277 }
56278diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
56279index d71a11d..384e2c4 100644
56280--- a/fs/btrfs/super.c
56281+++ b/fs/btrfs/super.c
56282@@ -265,7 +265,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
56283 function, line, errstr);
56284 return;
56285 }
56286- ACCESS_ONCE(trans->transaction->aborted) = errno;
56287+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
56288 /* Wake up anybody who may be waiting on this transaction */
56289 wake_up(&root->fs_info->transaction_wait);
56290 wake_up(&root->fs_info->transaction_blocked_wait);
56291diff --git a/fs/buffer.c b/fs/buffer.c
56292index 6024877..7bd000a 100644
56293--- a/fs/buffer.c
56294+++ b/fs/buffer.c
56295@@ -3426,7 +3426,7 @@ void __init buffer_init(void)
56296 bh_cachep = kmem_cache_create("buffer_head",
56297 sizeof(struct buffer_head), 0,
56298 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
56299- SLAB_MEM_SPREAD),
56300+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
56301 NULL);
56302
56303 /*
56304diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
56305index 622f469..e8d2d55 100644
56306--- a/fs/cachefiles/bind.c
56307+++ b/fs/cachefiles/bind.c
56308@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
56309 args);
56310
56311 /* start by checking things over */
56312- ASSERT(cache->fstop_percent >= 0 &&
56313- cache->fstop_percent < cache->fcull_percent &&
56314+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
56315 cache->fcull_percent < cache->frun_percent &&
56316 cache->frun_percent < 100);
56317
56318- ASSERT(cache->bstop_percent >= 0 &&
56319- cache->bstop_percent < cache->bcull_percent &&
56320+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
56321 cache->bcull_percent < cache->brun_percent &&
56322 cache->brun_percent < 100);
56323
56324diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
56325index 0a1467b..6a53245 100644
56326--- a/fs/cachefiles/daemon.c
56327+++ b/fs/cachefiles/daemon.c
56328@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
56329 if (n > buflen)
56330 return -EMSGSIZE;
56331
56332- if (copy_to_user(_buffer, buffer, n) != 0)
56333+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
56334 return -EFAULT;
56335
56336 return n;
56337@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
56338 if (test_bit(CACHEFILES_DEAD, &cache->flags))
56339 return -EIO;
56340
56341- if (datalen < 0 || datalen > PAGE_SIZE - 1)
56342+ if (datalen > PAGE_SIZE - 1)
56343 return -EOPNOTSUPP;
56344
56345 /* drag the command string into the kernel so we can parse it */
56346@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
56347 if (args[0] != '%' || args[1] != '\0')
56348 return -EINVAL;
56349
56350- if (fstop < 0 || fstop >= cache->fcull_percent)
56351+ if (fstop >= cache->fcull_percent)
56352 return cachefiles_daemon_range_error(cache, args);
56353
56354 cache->fstop_percent = fstop;
56355@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
56356 if (args[0] != '%' || args[1] != '\0')
56357 return -EINVAL;
56358
56359- if (bstop < 0 || bstop >= cache->bcull_percent)
56360+ if (bstop >= cache->bcull_percent)
56361 return cachefiles_daemon_range_error(cache, args);
56362
56363 cache->bstop_percent = bstop;
56364diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
56365index 5349473..d6c0b93 100644
56366--- a/fs/cachefiles/internal.h
56367+++ b/fs/cachefiles/internal.h
56368@@ -59,7 +59,7 @@ struct cachefiles_cache {
56369 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
56370 struct rb_root active_nodes; /* active nodes (can't be culled) */
56371 rwlock_t active_lock; /* lock for active_nodes */
56372- atomic_t gravecounter; /* graveyard uniquifier */
56373+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
56374 unsigned frun_percent; /* when to stop culling (% files) */
56375 unsigned fcull_percent; /* when to start culling (% files) */
56376 unsigned fstop_percent; /* when to stop allocating (% files) */
56377@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
56378 * proc.c
56379 */
56380 #ifdef CONFIG_CACHEFILES_HISTOGRAM
56381-extern atomic_t cachefiles_lookup_histogram[HZ];
56382-extern atomic_t cachefiles_mkdir_histogram[HZ];
56383-extern atomic_t cachefiles_create_histogram[HZ];
56384+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
56385+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
56386+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
56387
56388 extern int __init cachefiles_proc_init(void);
56389 extern void cachefiles_proc_cleanup(void);
56390 static inline
56391-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
56392+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
56393 {
56394 unsigned long jif = jiffies - start_jif;
56395 if (jif >= HZ)
56396 jif = HZ - 1;
56397- atomic_inc(&histogram[jif]);
56398+ atomic_inc_unchecked(&histogram[jif]);
56399 }
56400
56401 #else
56402diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
56403index ca65f39..48921e3 100644
56404--- a/fs/cachefiles/namei.c
56405+++ b/fs/cachefiles/namei.c
56406@@ -317,7 +317,7 @@ try_again:
56407 /* first step is to make up a grave dentry in the graveyard */
56408 sprintf(nbuffer, "%08x%08x",
56409 (uint32_t) get_seconds(),
56410- (uint32_t) atomic_inc_return(&cache->gravecounter));
56411+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
56412
56413 /* do the multiway lock magic */
56414 trap = lock_rename(cache->graveyard, dir);
56415diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
56416index eccd339..4c1d995 100644
56417--- a/fs/cachefiles/proc.c
56418+++ b/fs/cachefiles/proc.c
56419@@ -14,9 +14,9 @@
56420 #include <linux/seq_file.h>
56421 #include "internal.h"
56422
56423-atomic_t cachefiles_lookup_histogram[HZ];
56424-atomic_t cachefiles_mkdir_histogram[HZ];
56425-atomic_t cachefiles_create_histogram[HZ];
56426+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
56427+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
56428+atomic_unchecked_t cachefiles_create_histogram[HZ];
56429
56430 /*
56431 * display the latency histogram
56432@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
56433 return 0;
56434 default:
56435 index = (unsigned long) v - 3;
56436- x = atomic_read(&cachefiles_lookup_histogram[index]);
56437- y = atomic_read(&cachefiles_mkdir_histogram[index]);
56438- z = atomic_read(&cachefiles_create_histogram[index]);
56439+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
56440+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
56441+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
56442 if (x == 0 && y == 0 && z == 0)
56443 return 0;
56444
56445diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
56446index ebaff36..7e3ea26 100644
56447--- a/fs/cachefiles/rdwr.c
56448+++ b/fs/cachefiles/rdwr.c
56449@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
56450 old_fs = get_fs();
56451 set_fs(KERNEL_DS);
56452 ret = file->f_op->write(
56453- file, (const void __user *) data, len, &pos);
56454+ file, (const void __force_user *) data, len, &pos);
56455 set_fs(old_fs);
56456 kunmap(page);
56457 file_end_write(file);
56458diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
56459index 2a0bcae..34ec24e 100644
56460--- a/fs/ceph/dir.c
56461+++ b/fs/ceph/dir.c
56462@@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
56463 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
56464 struct ceph_mds_client *mdsc = fsc->mdsc;
56465 unsigned frag = fpos_frag(ctx->pos);
56466- int off = fpos_off(ctx->pos);
56467+ unsigned int off = fpos_off(ctx->pos);
56468 int err;
56469 u32 ftype;
56470 struct ceph_mds_reply_info_parsed *rinfo;
56471diff --git a/fs/ceph/super.c b/fs/ceph/super.c
56472index 6a0951e..03fac6d 100644
56473--- a/fs/ceph/super.c
56474+++ b/fs/ceph/super.c
56475@@ -870,7 +870,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
56476 /*
56477 * construct our own bdi so we can control readahead, etc.
56478 */
56479-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
56480+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
56481
56482 static int ceph_register_bdi(struct super_block *sb,
56483 struct ceph_fs_client *fsc)
56484@@ -887,7 +887,7 @@ static int ceph_register_bdi(struct super_block *sb,
56485 default_backing_dev_info.ra_pages;
56486
56487 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
56488- atomic_long_inc_return(&bdi_seq));
56489+ atomic_long_inc_return_unchecked(&bdi_seq));
56490 if (!err)
56491 sb->s_bdi = &fsc->backing_dev_info;
56492 return err;
56493diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
56494index f3ac415..3d2420c 100644
56495--- a/fs/cifs/cifs_debug.c
56496+++ b/fs/cifs/cifs_debug.c
56497@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
56498
56499 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
56500 #ifdef CONFIG_CIFS_STATS2
56501- atomic_set(&totBufAllocCount, 0);
56502- atomic_set(&totSmBufAllocCount, 0);
56503+ atomic_set_unchecked(&totBufAllocCount, 0);
56504+ atomic_set_unchecked(&totSmBufAllocCount, 0);
56505 #endif /* CONFIG_CIFS_STATS2 */
56506 spin_lock(&cifs_tcp_ses_lock);
56507 list_for_each(tmp1, &cifs_tcp_ses_list) {
56508@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
56509 tcon = list_entry(tmp3,
56510 struct cifs_tcon,
56511 tcon_list);
56512- atomic_set(&tcon->num_smbs_sent, 0);
56513+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
56514 if (server->ops->clear_stats)
56515 server->ops->clear_stats(tcon);
56516 }
56517@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
56518 smBufAllocCount.counter, cifs_min_small);
56519 #ifdef CONFIG_CIFS_STATS2
56520 seq_printf(m, "Total Large %d Small %d Allocations\n",
56521- atomic_read(&totBufAllocCount),
56522- atomic_read(&totSmBufAllocCount));
56523+ atomic_read_unchecked(&totBufAllocCount),
56524+ atomic_read_unchecked(&totSmBufAllocCount));
56525 #endif /* CONFIG_CIFS_STATS2 */
56526
56527 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
56528@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
56529 if (tcon->need_reconnect)
56530 seq_puts(m, "\tDISCONNECTED ");
56531 seq_printf(m, "\nSMBs: %d",
56532- atomic_read(&tcon->num_smbs_sent));
56533+ atomic_read_unchecked(&tcon->num_smbs_sent));
56534 if (server->ops->print_stats)
56535 server->ops->print_stats(m, tcon);
56536 }
56537diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
56538index 849f613..eae6dec 100644
56539--- a/fs/cifs/cifsfs.c
56540+++ b/fs/cifs/cifsfs.c
56541@@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
56542 */
56543 cifs_req_cachep = kmem_cache_create("cifs_request",
56544 CIFSMaxBufSize + max_hdr_size, 0,
56545- SLAB_HWCACHE_ALIGN, NULL);
56546+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
56547 if (cifs_req_cachep == NULL)
56548 return -ENOMEM;
56549
56550@@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
56551 efficient to alloc 1 per page off the slab compared to 17K (5page)
56552 alloc of large cifs buffers even when page debugging is on */
56553 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
56554- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
56555+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
56556 NULL);
56557 if (cifs_sm_req_cachep == NULL) {
56558 mempool_destroy(cifs_req_poolp);
56559@@ -1168,8 +1168,8 @@ init_cifs(void)
56560 atomic_set(&bufAllocCount, 0);
56561 atomic_set(&smBufAllocCount, 0);
56562 #ifdef CONFIG_CIFS_STATS2
56563- atomic_set(&totBufAllocCount, 0);
56564- atomic_set(&totSmBufAllocCount, 0);
56565+ atomic_set_unchecked(&totBufAllocCount, 0);
56566+ atomic_set_unchecked(&totSmBufAllocCount, 0);
56567 #endif /* CONFIG_CIFS_STATS2 */
56568
56569 atomic_set(&midCount, 0);
56570diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
56571index f918a99..bb300d5 100644
56572--- a/fs/cifs/cifsglob.h
56573+++ b/fs/cifs/cifsglob.h
56574@@ -787,35 +787,35 @@ struct cifs_tcon {
56575 __u16 Flags; /* optional support bits */
56576 enum statusEnum tidStatus;
56577 #ifdef CONFIG_CIFS_STATS
56578- atomic_t num_smbs_sent;
56579+ atomic_unchecked_t num_smbs_sent;
56580 union {
56581 struct {
56582- atomic_t num_writes;
56583- atomic_t num_reads;
56584- atomic_t num_flushes;
56585- atomic_t num_oplock_brks;
56586- atomic_t num_opens;
56587- atomic_t num_closes;
56588- atomic_t num_deletes;
56589- atomic_t num_mkdirs;
56590- atomic_t num_posixopens;
56591- atomic_t num_posixmkdirs;
56592- atomic_t num_rmdirs;
56593- atomic_t num_renames;
56594- atomic_t num_t2renames;
56595- atomic_t num_ffirst;
56596- atomic_t num_fnext;
56597- atomic_t num_fclose;
56598- atomic_t num_hardlinks;
56599- atomic_t num_symlinks;
56600- atomic_t num_locks;
56601- atomic_t num_acl_get;
56602- atomic_t num_acl_set;
56603+ atomic_unchecked_t num_writes;
56604+ atomic_unchecked_t num_reads;
56605+ atomic_unchecked_t num_flushes;
56606+ atomic_unchecked_t num_oplock_brks;
56607+ atomic_unchecked_t num_opens;
56608+ atomic_unchecked_t num_closes;
56609+ atomic_unchecked_t num_deletes;
56610+ atomic_unchecked_t num_mkdirs;
56611+ atomic_unchecked_t num_posixopens;
56612+ atomic_unchecked_t num_posixmkdirs;
56613+ atomic_unchecked_t num_rmdirs;
56614+ atomic_unchecked_t num_renames;
56615+ atomic_unchecked_t num_t2renames;
56616+ atomic_unchecked_t num_ffirst;
56617+ atomic_unchecked_t num_fnext;
56618+ atomic_unchecked_t num_fclose;
56619+ atomic_unchecked_t num_hardlinks;
56620+ atomic_unchecked_t num_symlinks;
56621+ atomic_unchecked_t num_locks;
56622+ atomic_unchecked_t num_acl_get;
56623+ atomic_unchecked_t num_acl_set;
56624 } cifs_stats;
56625 #ifdef CONFIG_CIFS_SMB2
56626 struct {
56627- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
56628- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
56629+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
56630+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
56631 } smb2_stats;
56632 #endif /* CONFIG_CIFS_SMB2 */
56633 } stats;
56634@@ -1145,7 +1145,7 @@ convert_delimiter(char *path, char delim)
56635 }
56636
56637 #ifdef CONFIG_CIFS_STATS
56638-#define cifs_stats_inc atomic_inc
56639+#define cifs_stats_inc atomic_inc_unchecked
56640
56641 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
56642 unsigned int bytes)
56643@@ -1511,8 +1511,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
56644 /* Various Debug counters */
56645 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
56646 #ifdef CONFIG_CIFS_STATS2
56647-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
56648-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
56649+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
56650+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
56651 #endif
56652 GLOBAL_EXTERN atomic_t smBufAllocCount;
56653 GLOBAL_EXTERN atomic_t midCount;
56654diff --git a/fs/cifs/file.c b/fs/cifs/file.c
56655index 5a5a872..92c3210 100644
56656--- a/fs/cifs/file.c
56657+++ b/fs/cifs/file.c
56658@@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
56659 index = mapping->writeback_index; /* Start from prev offset */
56660 end = -1;
56661 } else {
56662- index = wbc->range_start >> PAGE_CACHE_SHIFT;
56663- end = wbc->range_end >> PAGE_CACHE_SHIFT;
56664- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
56665+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
56666 range_whole = true;
56667+ index = 0;
56668+ end = ULONG_MAX;
56669+ } else {
56670+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
56671+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
56672+ }
56673 scanned = true;
56674 }
56675 retry:
56676diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
56677index 2f9f379..43f8025 100644
56678--- a/fs/cifs/misc.c
56679+++ b/fs/cifs/misc.c
56680@@ -170,7 +170,7 @@ cifs_buf_get(void)
56681 memset(ret_buf, 0, buf_size + 3);
56682 atomic_inc(&bufAllocCount);
56683 #ifdef CONFIG_CIFS_STATS2
56684- atomic_inc(&totBufAllocCount);
56685+ atomic_inc_unchecked(&totBufAllocCount);
56686 #endif /* CONFIG_CIFS_STATS2 */
56687 }
56688
56689@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
56690 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
56691 atomic_inc(&smBufAllocCount);
56692 #ifdef CONFIG_CIFS_STATS2
56693- atomic_inc(&totSmBufAllocCount);
56694+ atomic_inc_unchecked(&totSmBufAllocCount);
56695 #endif /* CONFIG_CIFS_STATS2 */
56696
56697 }
56698diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
56699index 5f5ba0d..8d6ef7d 100644
56700--- a/fs/cifs/smb1ops.c
56701+++ b/fs/cifs/smb1ops.c
56702@@ -609,27 +609,27 @@ static void
56703 cifs_clear_stats(struct cifs_tcon *tcon)
56704 {
56705 #ifdef CONFIG_CIFS_STATS
56706- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
56707- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
56708- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
56709- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
56710- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
56711- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
56712- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
56713- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
56714- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
56715- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
56716- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
56717- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
56718- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
56719- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
56720- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
56721- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
56722- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
56723- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
56724- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
56725- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
56726- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
56727+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
56728+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
56729+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
56730+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
56731+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
56732+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
56733+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
56734+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
56735+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
56736+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
56737+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
56738+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
56739+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
56740+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
56741+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
56742+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
56743+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
56744+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
56745+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
56746+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
56747+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
56748 #endif
56749 }
56750
56751@@ -638,36 +638,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
56752 {
56753 #ifdef CONFIG_CIFS_STATS
56754 seq_printf(m, " Oplocks breaks: %d",
56755- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
56756+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
56757 seq_printf(m, "\nReads: %d Bytes: %llu",
56758- atomic_read(&tcon->stats.cifs_stats.num_reads),
56759+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
56760 (long long)(tcon->bytes_read));
56761 seq_printf(m, "\nWrites: %d Bytes: %llu",
56762- atomic_read(&tcon->stats.cifs_stats.num_writes),
56763+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
56764 (long long)(tcon->bytes_written));
56765 seq_printf(m, "\nFlushes: %d",
56766- atomic_read(&tcon->stats.cifs_stats.num_flushes));
56767+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
56768 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
56769- atomic_read(&tcon->stats.cifs_stats.num_locks),
56770- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
56771- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
56772+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
56773+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
56774+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
56775 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
56776- atomic_read(&tcon->stats.cifs_stats.num_opens),
56777- atomic_read(&tcon->stats.cifs_stats.num_closes),
56778- atomic_read(&tcon->stats.cifs_stats.num_deletes));
56779+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
56780+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
56781+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
56782 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
56783- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
56784- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
56785+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
56786+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
56787 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
56788- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
56789- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
56790+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
56791+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
56792 seq_printf(m, "\nRenames: %d T2 Renames %d",
56793- atomic_read(&tcon->stats.cifs_stats.num_renames),
56794- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
56795+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
56796+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
56797 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
56798- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
56799- atomic_read(&tcon->stats.cifs_stats.num_fnext),
56800- atomic_read(&tcon->stats.cifs_stats.num_fclose));
56801+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
56802+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
56803+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
56804 #endif
56805 }
56806
56807diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
56808index 757da3e..07bf1ed 100644
56809--- a/fs/cifs/smb2ops.c
56810+++ b/fs/cifs/smb2ops.c
56811@@ -370,8 +370,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
56812 #ifdef CONFIG_CIFS_STATS
56813 int i;
56814 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
56815- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
56816- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
56817+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
56818+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
56819 }
56820 #endif
56821 }
56822@@ -411,65 +411,65 @@ static void
56823 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
56824 {
56825 #ifdef CONFIG_CIFS_STATS
56826- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
56827- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
56828+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
56829+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
56830 seq_printf(m, "\nNegotiates: %d sent %d failed",
56831- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
56832- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
56833+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
56834+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
56835 seq_printf(m, "\nSessionSetups: %d sent %d failed",
56836- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
56837- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
56838+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
56839+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
56840 seq_printf(m, "\nLogoffs: %d sent %d failed",
56841- atomic_read(&sent[SMB2_LOGOFF_HE]),
56842- atomic_read(&failed[SMB2_LOGOFF_HE]));
56843+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
56844+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
56845 seq_printf(m, "\nTreeConnects: %d sent %d failed",
56846- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
56847- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
56848+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
56849+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
56850 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
56851- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
56852- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
56853+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
56854+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
56855 seq_printf(m, "\nCreates: %d sent %d failed",
56856- atomic_read(&sent[SMB2_CREATE_HE]),
56857- atomic_read(&failed[SMB2_CREATE_HE]));
56858+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
56859+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
56860 seq_printf(m, "\nCloses: %d sent %d failed",
56861- atomic_read(&sent[SMB2_CLOSE_HE]),
56862- atomic_read(&failed[SMB2_CLOSE_HE]));
56863+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
56864+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
56865 seq_printf(m, "\nFlushes: %d sent %d failed",
56866- atomic_read(&sent[SMB2_FLUSH_HE]),
56867- atomic_read(&failed[SMB2_FLUSH_HE]));
56868+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
56869+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
56870 seq_printf(m, "\nReads: %d sent %d failed",
56871- atomic_read(&sent[SMB2_READ_HE]),
56872- atomic_read(&failed[SMB2_READ_HE]));
56873+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
56874+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
56875 seq_printf(m, "\nWrites: %d sent %d failed",
56876- atomic_read(&sent[SMB2_WRITE_HE]),
56877- atomic_read(&failed[SMB2_WRITE_HE]));
56878+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
56879+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
56880 seq_printf(m, "\nLocks: %d sent %d failed",
56881- atomic_read(&sent[SMB2_LOCK_HE]),
56882- atomic_read(&failed[SMB2_LOCK_HE]));
56883+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
56884+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
56885 seq_printf(m, "\nIOCTLs: %d sent %d failed",
56886- atomic_read(&sent[SMB2_IOCTL_HE]),
56887- atomic_read(&failed[SMB2_IOCTL_HE]));
56888+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
56889+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
56890 seq_printf(m, "\nCancels: %d sent %d failed",
56891- atomic_read(&sent[SMB2_CANCEL_HE]),
56892- atomic_read(&failed[SMB2_CANCEL_HE]));
56893+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
56894+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
56895 seq_printf(m, "\nEchos: %d sent %d failed",
56896- atomic_read(&sent[SMB2_ECHO_HE]),
56897- atomic_read(&failed[SMB2_ECHO_HE]));
56898+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
56899+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
56900 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
56901- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
56902- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
56903+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
56904+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
56905 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
56906- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
56907- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
56908+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
56909+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
56910 seq_printf(m, "\nQueryInfos: %d sent %d failed",
56911- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
56912- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
56913+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
56914+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
56915 seq_printf(m, "\nSetInfos: %d sent %d failed",
56916- atomic_read(&sent[SMB2_SET_INFO_HE]),
56917- atomic_read(&failed[SMB2_SET_INFO_HE]));
56918+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
56919+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
56920 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
56921- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
56922- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
56923+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
56924+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
56925 #endif
56926 }
56927
56928diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
56929index 2013234..a720734 100644
56930--- a/fs/cifs/smb2pdu.c
56931+++ b/fs/cifs/smb2pdu.c
56932@@ -2091,8 +2091,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
56933 default:
56934 cifs_dbg(VFS, "info level %u isn't supported\n",
56935 srch_inf->info_level);
56936- rc = -EINVAL;
56937- goto qdir_exit;
56938+ return -EINVAL;
56939 }
56940
56941 req->FileIndex = cpu_to_le32(index);
56942diff --git a/fs/coda/cache.c b/fs/coda/cache.c
56943index 1da168c..8bc7ff6 100644
56944--- a/fs/coda/cache.c
56945+++ b/fs/coda/cache.c
56946@@ -24,7 +24,7 @@
56947 #include "coda_linux.h"
56948 #include "coda_cache.h"
56949
56950-static atomic_t permission_epoch = ATOMIC_INIT(0);
56951+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
56952
56953 /* replace or extend an acl cache hit */
56954 void coda_cache_enter(struct inode *inode, int mask)
56955@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
56956 struct coda_inode_info *cii = ITOC(inode);
56957
56958 spin_lock(&cii->c_lock);
56959- cii->c_cached_epoch = atomic_read(&permission_epoch);
56960+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
56961 if (!uid_eq(cii->c_uid, current_fsuid())) {
56962 cii->c_uid = current_fsuid();
56963 cii->c_cached_perm = mask;
56964@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
56965 {
56966 struct coda_inode_info *cii = ITOC(inode);
56967 spin_lock(&cii->c_lock);
56968- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
56969+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
56970 spin_unlock(&cii->c_lock);
56971 }
56972
56973 /* remove all acl caches */
56974 void coda_cache_clear_all(struct super_block *sb)
56975 {
56976- atomic_inc(&permission_epoch);
56977+ atomic_inc_unchecked(&permission_epoch);
56978 }
56979
56980
56981@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
56982 spin_lock(&cii->c_lock);
56983 hit = (mask & cii->c_cached_perm) == mask &&
56984 uid_eq(cii->c_uid, current_fsuid()) &&
56985- cii->c_cached_epoch == atomic_read(&permission_epoch);
56986+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
56987 spin_unlock(&cii->c_lock);
56988
56989 return hit;
56990diff --git a/fs/compat.c b/fs/compat.c
56991index 6af20de..fec3fbb 100644
56992--- a/fs/compat.c
56993+++ b/fs/compat.c
56994@@ -54,7 +54,7 @@
56995 #include <asm/ioctls.h>
56996 #include "internal.h"
56997
56998-int compat_log = 1;
56999+int compat_log = 0;
57000
57001 int compat_printk(const char *fmt, ...)
57002 {
57003@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
57004
57005 set_fs(KERNEL_DS);
57006 /* The __user pointer cast is valid because of the set_fs() */
57007- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
57008+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
57009 set_fs(oldfs);
57010 /* truncating is ok because it's a user address */
57011 if (!ret)
57012@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
57013 goto out;
57014
57015 ret = -EINVAL;
57016- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
57017+ if (nr_segs > UIO_MAXIOV)
57018 goto out;
57019 if (nr_segs > fast_segs) {
57020 ret = -ENOMEM;
57021@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
57022 struct compat_readdir_callback {
57023 struct dir_context ctx;
57024 struct compat_old_linux_dirent __user *dirent;
57025+ struct file * file;
57026 int result;
57027 };
57028
57029@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
57030 buf->result = -EOVERFLOW;
57031 return -EOVERFLOW;
57032 }
57033+
57034+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57035+ return 0;
57036+
57037 buf->result++;
57038 dirent = buf->dirent;
57039 if (!access_ok(VERIFY_WRITE, dirent,
57040@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
57041 if (!f.file)
57042 return -EBADF;
57043
57044+ buf.file = f.file;
57045 error = iterate_dir(f.file, &buf.ctx);
57046 if (buf.result)
57047 error = buf.result;
57048@@ -901,6 +907,7 @@ struct compat_getdents_callback {
57049 struct dir_context ctx;
57050 struct compat_linux_dirent __user *current_dir;
57051 struct compat_linux_dirent __user *previous;
57052+ struct file * file;
57053 int count;
57054 int error;
57055 };
57056@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
57057 buf->error = -EOVERFLOW;
57058 return -EOVERFLOW;
57059 }
57060+
57061+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57062+ return 0;
57063+
57064 dirent = buf->previous;
57065 if (dirent) {
57066 if (__put_user(offset, &dirent->d_off))
57067@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
57068 if (!f.file)
57069 return -EBADF;
57070
57071+ buf.file = f.file;
57072 error = iterate_dir(f.file, &buf.ctx);
57073 if (error >= 0)
57074 error = buf.error;
57075@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
57076 struct dir_context ctx;
57077 struct linux_dirent64 __user *current_dir;
57078 struct linux_dirent64 __user *previous;
57079+ struct file * file;
57080 int count;
57081 int error;
57082 };
57083@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
57084 buf->error = -EINVAL; /* only used if we fail.. */
57085 if (reclen > buf->count)
57086 return -EINVAL;
57087+
57088+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57089+ return 0;
57090+
57091 dirent = buf->previous;
57092
57093 if (dirent) {
57094@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
57095 if (!f.file)
57096 return -EBADF;
57097
57098+ buf.file = f.file;
57099 error = iterate_dir(f.file, &buf.ctx);
57100 if (error >= 0)
57101 error = buf.error;
57102diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
57103index a81147e..20bf2b5 100644
57104--- a/fs/compat_binfmt_elf.c
57105+++ b/fs/compat_binfmt_elf.c
57106@@ -30,11 +30,13 @@
57107 #undef elf_phdr
57108 #undef elf_shdr
57109 #undef elf_note
57110+#undef elf_dyn
57111 #undef elf_addr_t
57112 #define elfhdr elf32_hdr
57113 #define elf_phdr elf32_phdr
57114 #define elf_shdr elf32_shdr
57115 #define elf_note elf32_note
57116+#define elf_dyn Elf32_Dyn
57117 #define elf_addr_t Elf32_Addr
57118
57119 /*
57120diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
57121index dc52e13..ec61057 100644
57122--- a/fs/compat_ioctl.c
57123+++ b/fs/compat_ioctl.c
57124@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
57125 return -EFAULT;
57126 if (__get_user(udata, &ss32->iomem_base))
57127 return -EFAULT;
57128- ss.iomem_base = compat_ptr(udata);
57129+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
57130 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
57131 __get_user(ss.port_high, &ss32->port_high))
57132 return -EFAULT;
57133@@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
57134 for (i = 0; i < nmsgs; i++) {
57135 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
57136 return -EFAULT;
57137- if (get_user(datap, &umsgs[i].buf) ||
57138- put_user(compat_ptr(datap), &tmsgs[i].buf))
57139+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
57140+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
57141 return -EFAULT;
57142 }
57143 return sys_ioctl(fd, cmd, (unsigned long)tdata);
57144@@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
57145 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
57146 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
57147 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
57148- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
57149+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
57150 return -EFAULT;
57151
57152 return ioctl_preallocate(file, p);
57153@@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
57154 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
57155 {
57156 unsigned int a, b;
57157- a = *(unsigned int *)p;
57158- b = *(unsigned int *)q;
57159+ a = *(const unsigned int *)p;
57160+ b = *(const unsigned int *)q;
57161 if (a > b)
57162 return 1;
57163 if (a < b)
57164diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
57165index e081acb..911df21 100644
57166--- a/fs/configfs/dir.c
57167+++ b/fs/configfs/dir.c
57168@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
57169 }
57170 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
57171 struct configfs_dirent *next;
57172- const char *name;
57173+ const unsigned char * name;
57174+ char d_name[sizeof(next->s_dentry->d_iname)];
57175 int len;
57176 struct inode *inode = NULL;
57177
57178@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
57179 continue;
57180
57181 name = configfs_get_name(next);
57182- len = strlen(name);
57183+ if (next->s_dentry && name == next->s_dentry->d_iname) {
57184+ len = next->s_dentry->d_name.len;
57185+ memcpy(d_name, name, len);
57186+ name = d_name;
57187+ } else
57188+ len = strlen(name);
57189
57190 /*
57191 * We'll have a dentry and an inode for
57192diff --git a/fs/coredump.c b/fs/coredump.c
57193index bc3fbcd..6031650 100644
57194--- a/fs/coredump.c
57195+++ b/fs/coredump.c
57196@@ -438,8 +438,8 @@ static void wait_for_dump_helpers(struct file *file)
57197 struct pipe_inode_info *pipe = file->private_data;
57198
57199 pipe_lock(pipe);
57200- pipe->readers++;
57201- pipe->writers--;
57202+ atomic_inc(&pipe->readers);
57203+ atomic_dec(&pipe->writers);
57204 wake_up_interruptible_sync(&pipe->wait);
57205 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
57206 pipe_unlock(pipe);
57207@@ -448,11 +448,11 @@ static void wait_for_dump_helpers(struct file *file)
57208 * We actually want wait_event_freezable() but then we need
57209 * to clear TIF_SIGPENDING and improve dump_interrupted().
57210 */
57211- wait_event_interruptible(pipe->wait, pipe->readers == 1);
57212+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
57213
57214 pipe_lock(pipe);
57215- pipe->readers--;
57216- pipe->writers++;
57217+ atomic_dec(&pipe->readers);
57218+ atomic_inc(&pipe->writers);
57219 pipe_unlock(pipe);
57220 }
57221
57222@@ -499,7 +499,9 @@ void do_coredump(const siginfo_t *siginfo)
57223 struct files_struct *displaced;
57224 bool need_nonrelative = false;
57225 bool core_dumped = false;
57226- static atomic_t core_dump_count = ATOMIC_INIT(0);
57227+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
57228+ long signr = siginfo->si_signo;
57229+ int dumpable;
57230 struct coredump_params cprm = {
57231 .siginfo = siginfo,
57232 .regs = signal_pt_regs(),
57233@@ -512,12 +514,17 @@ void do_coredump(const siginfo_t *siginfo)
57234 .mm_flags = mm->flags,
57235 };
57236
57237- audit_core_dumps(siginfo->si_signo);
57238+ audit_core_dumps(signr);
57239+
57240+ dumpable = __get_dumpable(cprm.mm_flags);
57241+
57242+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
57243+ gr_handle_brute_attach(dumpable);
57244
57245 binfmt = mm->binfmt;
57246 if (!binfmt || !binfmt->core_dump)
57247 goto fail;
57248- if (!__get_dumpable(cprm.mm_flags))
57249+ if (!dumpable)
57250 goto fail;
57251
57252 cred = prepare_creds();
57253@@ -536,7 +543,7 @@ void do_coredump(const siginfo_t *siginfo)
57254 need_nonrelative = true;
57255 }
57256
57257- retval = coredump_wait(siginfo->si_signo, &core_state);
57258+ retval = coredump_wait(signr, &core_state);
57259 if (retval < 0)
57260 goto fail_creds;
57261
57262@@ -579,7 +586,7 @@ void do_coredump(const siginfo_t *siginfo)
57263 }
57264 cprm.limit = RLIM_INFINITY;
57265
57266- dump_count = atomic_inc_return(&core_dump_count);
57267+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
57268 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
57269 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
57270 task_tgid_vnr(current), current->comm);
57271@@ -611,6 +618,8 @@ void do_coredump(const siginfo_t *siginfo)
57272 } else {
57273 struct inode *inode;
57274
57275+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
57276+
57277 if (cprm.limit < binfmt->min_coredump)
57278 goto fail_unlock;
57279
57280@@ -669,7 +678,7 @@ close_fail:
57281 filp_close(cprm.file, NULL);
57282 fail_dropcount:
57283 if (ispipe)
57284- atomic_dec(&core_dump_count);
57285+ atomic_dec_unchecked(&core_dump_count);
57286 fail_unlock:
57287 kfree(cn.corename);
57288 coredump_finish(mm, core_dumped);
57289@@ -690,6 +699,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
57290 struct file *file = cprm->file;
57291 loff_t pos = file->f_pos;
57292 ssize_t n;
57293+
57294+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
57295 if (cprm->written + nr > cprm->limit)
57296 return 0;
57297 while (nr) {
57298diff --git a/fs/dcache.c b/fs/dcache.c
57299index fdbe230..ba17c1f 100644
57300--- a/fs/dcache.c
57301+++ b/fs/dcache.c
57302@@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
57303 */
57304 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
57305 if (name->len > DNAME_INLINE_LEN-1) {
57306- dname = kmalloc(name->len + 1, GFP_KERNEL);
57307+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
57308 if (!dname) {
57309 kmem_cache_free(dentry_cache, dentry);
57310 return NULL;
57311@@ -3428,7 +3428,8 @@ void __init vfs_caches_init(unsigned long mempages)
57312 mempages -= reserve;
57313
57314 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
57315- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
57316+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
57317+ SLAB_NO_SANITIZE, NULL);
57318
57319 dcache_init();
57320 inode_init();
57321diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
57322index 9c0444c..628490c 100644
57323--- a/fs/debugfs/inode.c
57324+++ b/fs/debugfs/inode.c
57325@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
57326 */
57327 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
57328 {
57329+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
57330+ return __create_file(name, S_IFDIR | S_IRWXU,
57331+#else
57332 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
57333+#endif
57334 parent, NULL, NULL);
57335 }
57336 EXPORT_SYMBOL_GPL(debugfs_create_dir);
57337diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
57338index c36c448..fc96710 100644
57339--- a/fs/ecryptfs/inode.c
57340+++ b/fs/ecryptfs/inode.c
57341@@ -675,7 +675,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
57342 old_fs = get_fs();
57343 set_fs(get_ds());
57344 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
57345- (char __user *)lower_buf,
57346+ (char __force_user *)lower_buf,
57347 PATH_MAX);
57348 set_fs(old_fs);
57349 if (rc < 0)
57350diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
57351index e4141f2..d8263e8 100644
57352--- a/fs/ecryptfs/miscdev.c
57353+++ b/fs/ecryptfs/miscdev.c
57354@@ -304,7 +304,7 @@ check_list:
57355 goto out_unlock_msg_ctx;
57356 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
57357 if (msg_ctx->msg) {
57358- if (copy_to_user(&buf[i], packet_length, packet_length_size))
57359+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
57360 goto out_unlock_msg_ctx;
57361 i += packet_length_size;
57362 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
57363diff --git a/fs/exec.c b/fs/exec.c
57364index 7ea097f..0158d8a 100644
57365--- a/fs/exec.c
57366+++ b/fs/exec.c
57367@@ -55,8 +55,20 @@
57368 #include <linux/pipe_fs_i.h>
57369 #include <linux/oom.h>
57370 #include <linux/compat.h>
57371+#include <linux/random.h>
57372+#include <linux/seq_file.h>
57373+#include <linux/coredump.h>
57374+#include <linux/mman.h>
57375+
57376+#ifdef CONFIG_PAX_REFCOUNT
57377+#include <linux/kallsyms.h>
57378+#include <linux/kdebug.h>
57379+#endif
57380+
57381+#include <trace/events/fs.h>
57382
57383 #include <asm/uaccess.h>
57384+#include <asm/sections.h>
57385 #include <asm/mmu_context.h>
57386 #include <asm/tlb.h>
57387
57388@@ -66,19 +78,34 @@
57389
57390 #include <trace/events/sched.h>
57391
57392+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57393+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
57394+{
57395+ 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");
57396+}
57397+#endif
57398+
57399+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
57400+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
57401+EXPORT_SYMBOL(pax_set_initial_flags_func);
57402+#endif
57403+
57404 int suid_dumpable = 0;
57405
57406 static LIST_HEAD(formats);
57407 static DEFINE_RWLOCK(binfmt_lock);
57408
57409+extern int gr_process_kernel_exec_ban(void);
57410+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
57411+
57412 void __register_binfmt(struct linux_binfmt * fmt, int insert)
57413 {
57414 BUG_ON(!fmt);
57415 if (WARN_ON(!fmt->load_binary))
57416 return;
57417 write_lock(&binfmt_lock);
57418- insert ? list_add(&fmt->lh, &formats) :
57419- list_add_tail(&fmt->lh, &formats);
57420+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
57421+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
57422 write_unlock(&binfmt_lock);
57423 }
57424
57425@@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
57426 void unregister_binfmt(struct linux_binfmt * fmt)
57427 {
57428 write_lock(&binfmt_lock);
57429- list_del(&fmt->lh);
57430+ pax_list_del((struct list_head *)&fmt->lh);
57431 write_unlock(&binfmt_lock);
57432 }
57433
57434@@ -181,18 +208,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
57435 int write)
57436 {
57437 struct page *page;
57438- int ret;
57439
57440-#ifdef CONFIG_STACK_GROWSUP
57441- if (write) {
57442- ret = expand_downwards(bprm->vma, pos);
57443- if (ret < 0)
57444- return NULL;
57445- }
57446-#endif
57447- ret = get_user_pages(current, bprm->mm, pos,
57448- 1, write, 1, &page, NULL);
57449- if (ret <= 0)
57450+ if (0 > expand_downwards(bprm->vma, pos))
57451+ return NULL;
57452+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
57453 return NULL;
57454
57455 if (write) {
57456@@ -208,6 +227,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
57457 if (size <= ARG_MAX)
57458 return page;
57459
57460+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57461+ // only allow 512KB for argv+env on suid/sgid binaries
57462+ // to prevent easy ASLR exhaustion
57463+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
57464+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
57465+ (size > (512 * 1024))) {
57466+ put_page(page);
57467+ return NULL;
57468+ }
57469+#endif
57470+
57471 /*
57472 * Limit to 1/4-th the stack size for the argv+env strings.
57473 * This ensures that:
57474@@ -267,6 +297,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
57475 vma->vm_end = STACK_TOP_MAX;
57476 vma->vm_start = vma->vm_end - PAGE_SIZE;
57477 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
57478+
57479+#ifdef CONFIG_PAX_SEGMEXEC
57480+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
57481+#endif
57482+
57483 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
57484 INIT_LIST_HEAD(&vma->anon_vma_chain);
57485
57486@@ -277,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
57487 mm->stack_vm = mm->total_vm = 1;
57488 up_write(&mm->mmap_sem);
57489 bprm->p = vma->vm_end - sizeof(void *);
57490+
57491+#ifdef CONFIG_PAX_RANDUSTACK
57492+ if (randomize_va_space)
57493+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
57494+#endif
57495+
57496 return 0;
57497 err:
57498 up_write(&mm->mmap_sem);
57499@@ -397,7 +438,7 @@ struct user_arg_ptr {
57500 } ptr;
57501 };
57502
57503-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
57504+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
57505 {
57506 const char __user *native;
57507
57508@@ -406,14 +447,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
57509 compat_uptr_t compat;
57510
57511 if (get_user(compat, argv.ptr.compat + nr))
57512- return ERR_PTR(-EFAULT);
57513+ return (const char __force_user *)ERR_PTR(-EFAULT);
57514
57515 return compat_ptr(compat);
57516 }
57517 #endif
57518
57519 if (get_user(native, argv.ptr.native + nr))
57520- return ERR_PTR(-EFAULT);
57521+ return (const char __force_user *)ERR_PTR(-EFAULT);
57522
57523 return native;
57524 }
57525@@ -432,7 +473,7 @@ static int count(struct user_arg_ptr argv, int max)
57526 if (!p)
57527 break;
57528
57529- if (IS_ERR(p))
57530+ if (IS_ERR((const char __force_kernel *)p))
57531 return -EFAULT;
57532
57533 if (i >= max)
57534@@ -467,7 +508,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
57535
57536 ret = -EFAULT;
57537 str = get_user_arg_ptr(argv, argc);
57538- if (IS_ERR(str))
57539+ if (IS_ERR((const char __force_kernel *)str))
57540 goto out;
57541
57542 len = strnlen_user(str, MAX_ARG_STRLEN);
57543@@ -549,7 +590,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
57544 int r;
57545 mm_segment_t oldfs = get_fs();
57546 struct user_arg_ptr argv = {
57547- .ptr.native = (const char __user *const __user *)__argv,
57548+ .ptr.native = (const char __user * const __force_user *)__argv,
57549 };
57550
57551 set_fs(KERNEL_DS);
57552@@ -584,7 +625,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
57553 unsigned long new_end = old_end - shift;
57554 struct mmu_gather tlb;
57555
57556- BUG_ON(new_start > new_end);
57557+ if (new_start >= new_end || new_start < mmap_min_addr)
57558+ return -ENOMEM;
57559
57560 /*
57561 * ensure there are no vmas between where we want to go
57562@@ -593,6 +635,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
57563 if (vma != find_vma(mm, new_start))
57564 return -EFAULT;
57565
57566+#ifdef CONFIG_PAX_SEGMEXEC
57567+ BUG_ON(pax_find_mirror_vma(vma));
57568+#endif
57569+
57570 /*
57571 * cover the whole range: [new_start, old_end)
57572 */
57573@@ -673,10 +719,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
57574 stack_top = arch_align_stack(stack_top);
57575 stack_top = PAGE_ALIGN(stack_top);
57576
57577- if (unlikely(stack_top < mmap_min_addr) ||
57578- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
57579- return -ENOMEM;
57580-
57581 stack_shift = vma->vm_end - stack_top;
57582
57583 bprm->p -= stack_shift;
57584@@ -688,8 +730,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
57585 bprm->exec -= stack_shift;
57586
57587 down_write(&mm->mmap_sem);
57588+
57589+ /* Move stack pages down in memory. */
57590+ if (stack_shift) {
57591+ ret = shift_arg_pages(vma, stack_shift);
57592+ if (ret)
57593+ goto out_unlock;
57594+ }
57595+
57596 vm_flags = VM_STACK_FLAGS;
57597
57598+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
57599+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57600+ vm_flags &= ~VM_EXEC;
57601+
57602+#ifdef CONFIG_PAX_MPROTECT
57603+ if (mm->pax_flags & MF_PAX_MPROTECT)
57604+ vm_flags &= ~VM_MAYEXEC;
57605+#endif
57606+
57607+ }
57608+#endif
57609+
57610 /*
57611 * Adjust stack execute permissions; explicitly enable for
57612 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
57613@@ -708,13 +770,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
57614 goto out_unlock;
57615 BUG_ON(prev != vma);
57616
57617- /* Move stack pages down in memory. */
57618- if (stack_shift) {
57619- ret = shift_arg_pages(vma, stack_shift);
57620- if (ret)
57621- goto out_unlock;
57622- }
57623-
57624 /* mprotect_fixup is overkill to remove the temporary stack flags */
57625 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
57626
57627@@ -738,6 +793,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
57628 #endif
57629 current->mm->start_stack = bprm->p;
57630 ret = expand_stack(vma, stack_base);
57631+
57632+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
57633+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
57634+ unsigned long size;
57635+ vm_flags_t vm_flags;
57636+
57637+ size = STACK_TOP - vma->vm_end;
57638+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
57639+
57640+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
57641+
57642+#ifdef CONFIG_X86
57643+ if (!ret) {
57644+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
57645+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
57646+ }
57647+#endif
57648+
57649+ }
57650+#endif
57651+
57652 if (ret)
57653 ret = -EFAULT;
57654
57655@@ -774,6 +850,8 @@ struct file *open_exec(const char *name)
57656
57657 fsnotify_open(file);
57658
57659+ trace_open_exec(name);
57660+
57661 err = deny_write_access(file);
57662 if (err)
57663 goto exit;
57664@@ -797,7 +875,7 @@ int kernel_read(struct file *file, loff_t offset,
57665 old_fs = get_fs();
57666 set_fs(get_ds());
57667 /* The cast to a user pointer is valid due to the set_fs() */
57668- result = vfs_read(file, (void __user *)addr, count, &pos);
57669+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
57670 set_fs(old_fs);
57671 return result;
57672 }
57673@@ -1253,7 +1331,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
57674 }
57675 rcu_read_unlock();
57676
57677- if (p->fs->users > n_fs) {
57678+ if (atomic_read(&p->fs->users) > n_fs) {
57679 bprm->unsafe |= LSM_UNSAFE_SHARE;
57680 } else {
57681 res = -EAGAIN;
57682@@ -1443,6 +1521,31 @@ static int exec_binprm(struct linux_binprm *bprm)
57683 return ret;
57684 }
57685
57686+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57687+static DEFINE_PER_CPU(u64, exec_counter);
57688+static int __init init_exec_counters(void)
57689+{
57690+ unsigned int cpu;
57691+
57692+ for_each_possible_cpu(cpu) {
57693+ per_cpu(exec_counter, cpu) = (u64)cpu;
57694+ }
57695+
57696+ return 0;
57697+}
57698+early_initcall(init_exec_counters);
57699+static inline void increment_exec_counter(void)
57700+{
57701+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
57702+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
57703+}
57704+#else
57705+static inline void increment_exec_counter(void) {}
57706+#endif
57707+
57708+extern void gr_handle_exec_args(struct linux_binprm *bprm,
57709+ struct user_arg_ptr argv);
57710+
57711 /*
57712 * sys_execve() executes a new program.
57713 */
57714@@ -1450,12 +1553,19 @@ static int do_execve_common(const char *filename,
57715 struct user_arg_ptr argv,
57716 struct user_arg_ptr envp)
57717 {
57718+#ifdef CONFIG_GRKERNSEC
57719+ struct file *old_exec_file;
57720+ struct acl_subject_label *old_acl;
57721+ struct rlimit old_rlim[RLIM_NLIMITS];
57722+#endif
57723 struct linux_binprm *bprm;
57724 struct file *file;
57725 struct files_struct *displaced;
57726 bool clear_in_exec;
57727 int retval;
57728
57729+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
57730+
57731 /*
57732 * We move the actual failure in case of RLIMIT_NPROC excess from
57733 * set*uid() to execve() because too many poorly written programs
57734@@ -1496,12 +1606,22 @@ static int do_execve_common(const char *filename,
57735 if (IS_ERR(file))
57736 goto out_unmark;
57737
57738+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
57739+ retval = -EPERM;
57740+ goto out_file;
57741+ }
57742+
57743 sched_exec();
57744
57745 bprm->file = file;
57746 bprm->filename = filename;
57747 bprm->interp = filename;
57748
57749+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
57750+ retval = -EACCES;
57751+ goto out_file;
57752+ }
57753+
57754 retval = bprm_mm_init(bprm);
57755 if (retval)
57756 goto out_file;
57757@@ -1518,24 +1638,70 @@ static int do_execve_common(const char *filename,
57758 if (retval < 0)
57759 goto out;
57760
57761+#ifdef CONFIG_GRKERNSEC
57762+ old_acl = current->acl;
57763+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
57764+ old_exec_file = current->exec_file;
57765+ get_file(file);
57766+ current->exec_file = file;
57767+#endif
57768+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57769+ /* limit suid stack to 8MB
57770+ * we saved the old limits above and will restore them if this exec fails
57771+ */
57772+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
57773+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
57774+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
57775+#endif
57776+
57777+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
57778+ retval = -EPERM;
57779+ goto out_fail;
57780+ }
57781+
57782+ if (!gr_tpe_allow(file)) {
57783+ retval = -EACCES;
57784+ goto out_fail;
57785+ }
57786+
57787+ if (gr_check_crash_exec(file)) {
57788+ retval = -EACCES;
57789+ goto out_fail;
57790+ }
57791+
57792+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
57793+ bprm->unsafe);
57794+ if (retval < 0)
57795+ goto out_fail;
57796+
57797 retval = copy_strings_kernel(1, &bprm->filename, bprm);
57798 if (retval < 0)
57799- goto out;
57800+ goto out_fail;
57801
57802 bprm->exec = bprm->p;
57803 retval = copy_strings(bprm->envc, envp, bprm);
57804 if (retval < 0)
57805- goto out;
57806+ goto out_fail;
57807
57808 retval = copy_strings(bprm->argc, argv, bprm);
57809 if (retval < 0)
57810- goto out;
57811+ goto out_fail;
57812+
57813+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
57814+
57815+ gr_handle_exec_args(bprm, argv);
57816
57817 retval = exec_binprm(bprm);
57818 if (retval < 0)
57819- goto out;
57820+ goto out_fail;
57821+#ifdef CONFIG_GRKERNSEC
57822+ if (old_exec_file)
57823+ fput(old_exec_file);
57824+#endif
57825
57826 /* execve succeeded */
57827+
57828+ increment_exec_counter();
57829 current->fs->in_exec = 0;
57830 current->in_execve = 0;
57831 acct_update_integrals(current);
57832@@ -1545,6 +1711,14 @@ static int do_execve_common(const char *filename,
57833 put_files_struct(displaced);
57834 return retval;
57835
57836+out_fail:
57837+#ifdef CONFIG_GRKERNSEC
57838+ current->acl = old_acl;
57839+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
57840+ fput(current->exec_file);
57841+ current->exec_file = old_exec_file;
57842+#endif
57843+
57844 out:
57845 if (bprm->mm) {
57846 acct_arg_size(bprm, 0);
57847@@ -1699,3 +1873,295 @@ asmlinkage long compat_sys_execve(const char __user * filename,
57848 return error;
57849 }
57850 #endif
57851+
57852+int pax_check_flags(unsigned long *flags)
57853+{
57854+ int retval = 0;
57855+
57856+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
57857+ if (*flags & MF_PAX_SEGMEXEC)
57858+ {
57859+ *flags &= ~MF_PAX_SEGMEXEC;
57860+ retval = -EINVAL;
57861+ }
57862+#endif
57863+
57864+ if ((*flags & MF_PAX_PAGEEXEC)
57865+
57866+#ifdef CONFIG_PAX_PAGEEXEC
57867+ && (*flags & MF_PAX_SEGMEXEC)
57868+#endif
57869+
57870+ )
57871+ {
57872+ *flags &= ~MF_PAX_PAGEEXEC;
57873+ retval = -EINVAL;
57874+ }
57875+
57876+ if ((*flags & MF_PAX_MPROTECT)
57877+
57878+#ifdef CONFIG_PAX_MPROTECT
57879+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
57880+#endif
57881+
57882+ )
57883+ {
57884+ *flags &= ~MF_PAX_MPROTECT;
57885+ retval = -EINVAL;
57886+ }
57887+
57888+ if ((*flags & MF_PAX_EMUTRAMP)
57889+
57890+#ifdef CONFIG_PAX_EMUTRAMP
57891+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
57892+#endif
57893+
57894+ )
57895+ {
57896+ *flags &= ~MF_PAX_EMUTRAMP;
57897+ retval = -EINVAL;
57898+ }
57899+
57900+ return retval;
57901+}
57902+
57903+EXPORT_SYMBOL(pax_check_flags);
57904+
57905+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
57906+char *pax_get_path(const struct path *path, char *buf, int buflen)
57907+{
57908+ char *pathname = d_path(path, buf, buflen);
57909+
57910+ if (IS_ERR(pathname))
57911+ goto toolong;
57912+
57913+ pathname = mangle_path(buf, pathname, "\t\n\\");
57914+ if (!pathname)
57915+ goto toolong;
57916+
57917+ *pathname = 0;
57918+ return buf;
57919+
57920+toolong:
57921+ return "<path too long>";
57922+}
57923+EXPORT_SYMBOL(pax_get_path);
57924+
57925+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
57926+{
57927+ struct task_struct *tsk = current;
57928+ struct mm_struct *mm = current->mm;
57929+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
57930+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
57931+ char *path_exec = NULL;
57932+ char *path_fault = NULL;
57933+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
57934+ siginfo_t info = { };
57935+
57936+ if (buffer_exec && buffer_fault) {
57937+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
57938+
57939+ down_read(&mm->mmap_sem);
57940+ vma = mm->mmap;
57941+ while (vma && (!vma_exec || !vma_fault)) {
57942+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
57943+ vma_exec = vma;
57944+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
57945+ vma_fault = vma;
57946+ vma = vma->vm_next;
57947+ }
57948+ if (vma_exec)
57949+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
57950+ if (vma_fault) {
57951+ start = vma_fault->vm_start;
57952+ end = vma_fault->vm_end;
57953+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
57954+ if (vma_fault->vm_file)
57955+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
57956+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
57957+ path_fault = "<heap>";
57958+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
57959+ path_fault = "<stack>";
57960+ else
57961+ path_fault = "<anonymous mapping>";
57962+ }
57963+ up_read(&mm->mmap_sem);
57964+ }
57965+ if (tsk->signal->curr_ip)
57966+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
57967+ else
57968+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
57969+ 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),
57970+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
57971+ free_page((unsigned long)buffer_exec);
57972+ free_page((unsigned long)buffer_fault);
57973+ pax_report_insns(regs, pc, sp);
57974+ info.si_signo = SIGKILL;
57975+ info.si_errno = 0;
57976+ info.si_code = SI_KERNEL;
57977+ info.si_pid = 0;
57978+ info.si_uid = 0;
57979+ do_coredump(&info);
57980+}
57981+#endif
57982+
57983+#ifdef CONFIG_PAX_REFCOUNT
57984+void pax_report_refcount_overflow(struct pt_regs *regs)
57985+{
57986+ if (current->signal->curr_ip)
57987+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
57988+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
57989+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
57990+ else
57991+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
57992+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
57993+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
57994+ preempt_disable();
57995+ show_regs(regs);
57996+ preempt_enable();
57997+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
57998+}
57999+#endif
58000+
58001+#ifdef CONFIG_PAX_USERCOPY
58002+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
58003+static noinline int check_stack_object(const void *obj, unsigned long len)
58004+{
58005+ const void * const stack = task_stack_page(current);
58006+ const void * const stackend = stack + THREAD_SIZE;
58007+
58008+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58009+ const void *frame = NULL;
58010+ const void *oldframe;
58011+#endif
58012+
58013+ if (obj + len < obj)
58014+ return -1;
58015+
58016+ if (obj + len <= stack || stackend <= obj)
58017+ return 0;
58018+
58019+ if (obj < stack || stackend < obj + len)
58020+ return -1;
58021+
58022+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58023+ oldframe = __builtin_frame_address(1);
58024+ if (oldframe)
58025+ frame = __builtin_frame_address(2);
58026+ /*
58027+ low ----------------------------------------------> high
58028+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
58029+ ^----------------^
58030+ allow copies only within here
58031+ */
58032+ while (stack <= frame && frame < stackend) {
58033+ /* if obj + len extends past the last frame, this
58034+ check won't pass and the next frame will be 0,
58035+ causing us to bail out and correctly report
58036+ the copy as invalid
58037+ */
58038+ if (obj + len <= frame)
58039+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
58040+ oldframe = frame;
58041+ frame = *(const void * const *)frame;
58042+ }
58043+ return -1;
58044+#else
58045+ return 1;
58046+#endif
58047+}
58048+
58049+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
58050+{
58051+ if (current->signal->curr_ip)
58052+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58053+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58054+ else
58055+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58056+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58057+ dump_stack();
58058+ gr_handle_kernel_exploit();
58059+ do_group_exit(SIGKILL);
58060+}
58061+#endif
58062+
58063+#ifdef CONFIG_PAX_USERCOPY
58064+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
58065+{
58066+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
58067+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
58068+#ifdef CONFIG_MODULES
58069+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
58070+#else
58071+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
58072+#endif
58073+
58074+#else
58075+ unsigned long textlow = (unsigned long)_stext;
58076+ unsigned long texthigh = (unsigned long)_etext;
58077+
58078+#ifdef CONFIG_X86_64
58079+ /* check against linear mapping as well */
58080+ if (high > (unsigned long)__va(__pa(textlow)) &&
58081+ low <= (unsigned long)__va(__pa(texthigh)))
58082+ return true;
58083+#endif
58084+
58085+#endif
58086+
58087+ if (high <= textlow || low > texthigh)
58088+ return false;
58089+ else
58090+ return true;
58091+}
58092+#endif
58093+
58094+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
58095+{
58096+
58097+#ifdef CONFIG_PAX_USERCOPY
58098+ const char *type;
58099+
58100+ if (!n)
58101+ return;
58102+
58103+ type = check_heap_object(ptr, n);
58104+ if (!type) {
58105+ int ret = check_stack_object(ptr, n);
58106+ if (ret == 1 || ret == 2)
58107+ return;
58108+ if (ret == 0) {
58109+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
58110+ type = "<kernel text>";
58111+ else
58112+ return;
58113+ } else
58114+ type = "<process stack>";
58115+ }
58116+
58117+ pax_report_usercopy(ptr, n, to_user, type);
58118+#endif
58119+
58120+}
58121+EXPORT_SYMBOL(__check_object_size);
58122+
58123+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
58124+void pax_track_stack(void)
58125+{
58126+ unsigned long sp = (unsigned long)&sp;
58127+ if (sp < current_thread_info()->lowest_stack &&
58128+ sp > (unsigned long)task_stack_page(current))
58129+ current_thread_info()->lowest_stack = sp;
58130+}
58131+EXPORT_SYMBOL(pax_track_stack);
58132+#endif
58133+
58134+#ifdef CONFIG_PAX_SIZE_OVERFLOW
58135+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
58136+{
58137+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
58138+ dump_stack();
58139+ do_group_exit(SIGKILL);
58140+}
58141+EXPORT_SYMBOL(report_size_overflow);
58142+#endif
58143diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
58144index 9f9992b..8b59411 100644
58145--- a/fs/ext2/balloc.c
58146+++ b/fs/ext2/balloc.c
58147@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
58148
58149 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
58150 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
58151- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
58152+ if (free_blocks < root_blocks + 1 &&
58153 !uid_eq(sbi->s_resuid, current_fsuid()) &&
58154 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
58155- !in_group_p (sbi->s_resgid))) {
58156+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
58157 return 0;
58158 }
58159 return 1;
58160diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
58161index 2d7557d..14e38f94 100644
58162--- a/fs/ext2/xattr.c
58163+++ b/fs/ext2/xattr.c
58164@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
58165 struct buffer_head *bh = NULL;
58166 struct ext2_xattr_entry *entry;
58167 char *end;
58168- size_t rest = buffer_size;
58169+ size_t rest = buffer_size, total_size = 0;
58170 int error;
58171
58172 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
58173@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
58174 buffer += size;
58175 }
58176 rest -= size;
58177+ total_size += size;
58178 }
58179 }
58180- error = buffer_size - rest; /* total size */
58181+ error = total_size;
58182
58183 cleanup:
58184 brelse(bh);
58185diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
58186index 22548f5..41521d8 100644
58187--- a/fs/ext3/balloc.c
58188+++ b/fs/ext3/balloc.c
58189@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
58190
58191 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
58192 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
58193- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
58194+ if (free_blocks < root_blocks + 1 &&
58195 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
58196 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
58197- !in_group_p (sbi->s_resgid))) {
58198+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
58199 return 0;
58200 }
58201 return 1;
58202diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
58203index b1fc963..881228c 100644
58204--- a/fs/ext3/xattr.c
58205+++ b/fs/ext3/xattr.c
58206@@ -330,7 +330,7 @@ static int
58207 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
58208 char *buffer, size_t buffer_size)
58209 {
58210- size_t rest = buffer_size;
58211+ size_t rest = buffer_size, total_size = 0;
58212
58213 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
58214 const struct xattr_handler *handler =
58215@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
58216 buffer += size;
58217 }
58218 rest -= size;
58219+ total_size += size;
58220 }
58221 }
58222- return buffer_size - rest;
58223+ return total_size;
58224 }
58225
58226 static int
58227diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
58228index 6ea7b14..8fa16d9 100644
58229--- a/fs/ext4/balloc.c
58230+++ b/fs/ext4/balloc.c
58231@@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
58232 /* Hm, nope. Are (enough) root reserved clusters available? */
58233 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
58234 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
58235- capable(CAP_SYS_RESOURCE) ||
58236- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
58237+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
58238+ capable_nolog(CAP_SYS_RESOURCE)) {
58239
58240 if (free_clusters >= (nclusters + dirty_clusters +
58241 resv_clusters))
58242diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
58243index ece5556..e39d3a8 100644
58244--- a/fs/ext4/ext4.h
58245+++ b/fs/ext4/ext4.h
58246@@ -1267,19 +1267,19 @@ struct ext4_sb_info {
58247 unsigned long s_mb_last_start;
58248
58249 /* stats for buddy allocator */
58250- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
58251- atomic_t s_bal_success; /* we found long enough chunks */
58252- atomic_t s_bal_allocated; /* in blocks */
58253- atomic_t s_bal_ex_scanned; /* total extents scanned */
58254- atomic_t s_bal_goals; /* goal hits */
58255- atomic_t s_bal_breaks; /* too long searches */
58256- atomic_t s_bal_2orders; /* 2^order hits */
58257+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
58258+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
58259+ atomic_unchecked_t s_bal_allocated; /* in blocks */
58260+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
58261+ atomic_unchecked_t s_bal_goals; /* goal hits */
58262+ atomic_unchecked_t s_bal_breaks; /* too long searches */
58263+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
58264 spinlock_t s_bal_lock;
58265 unsigned long s_mb_buddies_generated;
58266 unsigned long long s_mb_generation_time;
58267- atomic_t s_mb_lost_chunks;
58268- atomic_t s_mb_preallocated;
58269- atomic_t s_mb_discarded;
58270+ atomic_unchecked_t s_mb_lost_chunks;
58271+ atomic_unchecked_t s_mb_preallocated;
58272+ atomic_unchecked_t s_mb_discarded;
58273 atomic_t s_lock_busy;
58274
58275 /* locality groups */
58276diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
58277index 04a5c75..09894fa 100644
58278--- a/fs/ext4/mballoc.c
58279+++ b/fs/ext4/mballoc.c
58280@@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
58281 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
58282
58283 if (EXT4_SB(sb)->s_mb_stats)
58284- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
58285+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
58286
58287 break;
58288 }
58289@@ -2189,7 +2189,7 @@ repeat:
58290 ac->ac_status = AC_STATUS_CONTINUE;
58291 ac->ac_flags |= EXT4_MB_HINT_FIRST;
58292 cr = 3;
58293- atomic_inc(&sbi->s_mb_lost_chunks);
58294+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
58295 goto repeat;
58296 }
58297 }
58298@@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
58299 if (sbi->s_mb_stats) {
58300 ext4_msg(sb, KERN_INFO,
58301 "mballoc: %u blocks %u reqs (%u success)",
58302- atomic_read(&sbi->s_bal_allocated),
58303- atomic_read(&sbi->s_bal_reqs),
58304- atomic_read(&sbi->s_bal_success));
58305+ atomic_read_unchecked(&sbi->s_bal_allocated),
58306+ atomic_read_unchecked(&sbi->s_bal_reqs),
58307+ atomic_read_unchecked(&sbi->s_bal_success));
58308 ext4_msg(sb, KERN_INFO,
58309 "mballoc: %u extents scanned, %u goal hits, "
58310 "%u 2^N hits, %u breaks, %u lost",
58311- atomic_read(&sbi->s_bal_ex_scanned),
58312- atomic_read(&sbi->s_bal_goals),
58313- atomic_read(&sbi->s_bal_2orders),
58314- atomic_read(&sbi->s_bal_breaks),
58315- atomic_read(&sbi->s_mb_lost_chunks));
58316+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
58317+ atomic_read_unchecked(&sbi->s_bal_goals),
58318+ atomic_read_unchecked(&sbi->s_bal_2orders),
58319+ atomic_read_unchecked(&sbi->s_bal_breaks),
58320+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
58321 ext4_msg(sb, KERN_INFO,
58322 "mballoc: %lu generated and it took %Lu",
58323 sbi->s_mb_buddies_generated,
58324 sbi->s_mb_generation_time);
58325 ext4_msg(sb, KERN_INFO,
58326 "mballoc: %u preallocated, %u discarded",
58327- atomic_read(&sbi->s_mb_preallocated),
58328- atomic_read(&sbi->s_mb_discarded));
58329+ atomic_read_unchecked(&sbi->s_mb_preallocated),
58330+ atomic_read_unchecked(&sbi->s_mb_discarded));
58331 }
58332
58333 free_percpu(sbi->s_locality_groups);
58334@@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
58335 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
58336
58337 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
58338- atomic_inc(&sbi->s_bal_reqs);
58339- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
58340+ atomic_inc_unchecked(&sbi->s_bal_reqs);
58341+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
58342 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
58343- atomic_inc(&sbi->s_bal_success);
58344- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
58345+ atomic_inc_unchecked(&sbi->s_bal_success);
58346+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
58347 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
58348 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
58349- atomic_inc(&sbi->s_bal_goals);
58350+ atomic_inc_unchecked(&sbi->s_bal_goals);
58351 if (ac->ac_found > sbi->s_mb_max_to_scan)
58352- atomic_inc(&sbi->s_bal_breaks);
58353+ atomic_inc_unchecked(&sbi->s_bal_breaks);
58354 }
58355
58356 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
58357@@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
58358 trace_ext4_mb_new_inode_pa(ac, pa);
58359
58360 ext4_mb_use_inode_pa(ac, pa);
58361- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
58362+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
58363
58364 ei = EXT4_I(ac->ac_inode);
58365 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
58366@@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
58367 trace_ext4_mb_new_group_pa(ac, pa);
58368
58369 ext4_mb_use_group_pa(ac, pa);
58370- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
58371+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
58372
58373 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
58374 lg = ac->ac_lg;
58375@@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
58376 * from the bitmap and continue.
58377 */
58378 }
58379- atomic_add(free, &sbi->s_mb_discarded);
58380+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
58381
58382 return err;
58383 }
58384@@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
58385 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
58386 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
58387 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
58388- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
58389+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
58390 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
58391
58392 return 0;
58393diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
58394index 04434ad..6404663 100644
58395--- a/fs/ext4/mmp.c
58396+++ b/fs/ext4/mmp.c
58397@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
58398 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
58399 const char *function, unsigned int line, const char *msg)
58400 {
58401- __ext4_warning(sb, function, line, msg);
58402+ __ext4_warning(sb, function, line, "%s", msg);
58403 __ext4_warning(sb, function, line,
58404 "MMP failure info: last update time: %llu, last update "
58405 "node: %s, last update device: %s\n",
58406diff --git a/fs/ext4/super.c b/fs/ext4/super.c
58407index 1f7784d..5d8bbad 100644
58408--- a/fs/ext4/super.c
58409+++ b/fs/ext4/super.c
58410@@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
58411 }
58412
58413 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
58414-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
58415+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
58416 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
58417
58418 #ifdef CONFIG_QUOTA
58419@@ -2450,7 +2450,7 @@ struct ext4_attr {
58420 int offset;
58421 int deprecated_val;
58422 } u;
58423-};
58424+} __do_const;
58425
58426 static int parse_strtoull(const char *buf,
58427 unsigned long long max, unsigned long long *value)
58428diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
58429index 1423c48..9c0c6dc 100644
58430--- a/fs/ext4/xattr.c
58431+++ b/fs/ext4/xattr.c
58432@@ -381,7 +381,7 @@ static int
58433 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
58434 char *buffer, size_t buffer_size)
58435 {
58436- size_t rest = buffer_size;
58437+ size_t rest = buffer_size, total_size = 0;
58438
58439 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
58440 const struct xattr_handler *handler =
58441@@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
58442 buffer += size;
58443 }
58444 rest -= size;
58445+ total_size += size;
58446 }
58447 }
58448- return buffer_size - rest;
58449+ return total_size;
58450 }
58451
58452 static int
58453diff --git a/fs/fcntl.c b/fs/fcntl.c
58454index ef68665..5deacdc 100644
58455--- a/fs/fcntl.c
58456+++ b/fs/fcntl.c
58457@@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
58458 if (err)
58459 return err;
58460
58461+ if (gr_handle_chroot_fowner(pid, type))
58462+ return -ENOENT;
58463+ if (gr_check_protected_task_fowner(pid, type))
58464+ return -EACCES;
58465+
58466 f_modown(filp, pid, type, force);
58467 return 0;
58468 }
58469diff --git a/fs/fhandle.c b/fs/fhandle.c
58470index 999ff5c..41f4109 100644
58471--- a/fs/fhandle.c
58472+++ b/fs/fhandle.c
58473@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
58474 } else
58475 retval = 0;
58476 /* copy the mount id */
58477- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
58478- sizeof(*mnt_id)) ||
58479+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
58480 copy_to_user(ufh, handle,
58481 sizeof(struct file_handle) + handle_bytes))
58482 retval = -EFAULT;
58483diff --git a/fs/file.c b/fs/file.c
58484index 4a78f98..f9a6d25 100644
58485--- a/fs/file.c
58486+++ b/fs/file.c
58487@@ -16,6 +16,7 @@
58488 #include <linux/slab.h>
58489 #include <linux/vmalloc.h>
58490 #include <linux/file.h>
58491+#include <linux/security.h>
58492 #include <linux/fdtable.h>
58493 #include <linux/bitops.h>
58494 #include <linux/interrupt.h>
58495@@ -141,7 +142,7 @@ out:
58496 * Return <0 error code on error; 1 on successful completion.
58497 * The files->file_lock should be held on entry, and will be held on exit.
58498 */
58499-static int expand_fdtable(struct files_struct *files, int nr)
58500+static int expand_fdtable(struct files_struct *files, unsigned int nr)
58501 __releases(files->file_lock)
58502 __acquires(files->file_lock)
58503 {
58504@@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
58505 * expanded and execution may have blocked.
58506 * The files->file_lock should be held on entry, and will be held on exit.
58507 */
58508-static int expand_files(struct files_struct *files, int nr)
58509+static int expand_files(struct files_struct *files, unsigned int nr)
58510 {
58511 struct fdtable *fdt;
58512
58513@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
58514 if (!file)
58515 return __close_fd(files, fd);
58516
58517+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
58518 if (fd >= rlimit(RLIMIT_NOFILE))
58519 return -EBADF;
58520
58521@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
58522 if (unlikely(oldfd == newfd))
58523 return -EINVAL;
58524
58525+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
58526 if (newfd >= rlimit(RLIMIT_NOFILE))
58527 return -EBADF;
58528
58529@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
58530 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
58531 {
58532 int err;
58533+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
58534 if (from >= rlimit(RLIMIT_NOFILE))
58535 return -EINVAL;
58536 err = alloc_fd(from, flags);
58537diff --git a/fs/filesystems.c b/fs/filesystems.c
58538index 92567d9..fcd8cbf 100644
58539--- a/fs/filesystems.c
58540+++ b/fs/filesystems.c
58541@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
58542 int len = dot ? dot - name : strlen(name);
58543
58544 fs = __get_fs_type(name, len);
58545+#ifdef CONFIG_GRKERNSEC_MODHARDEN
58546+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
58547+#else
58548 if (!fs && (request_module("fs-%.*s", len, name) == 0))
58549+#endif
58550 fs = __get_fs_type(name, len);
58551
58552 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
58553diff --git a/fs/fs_struct.c b/fs/fs_struct.c
58554index 7dca743..543d620 100644
58555--- a/fs/fs_struct.c
58556+++ b/fs/fs_struct.c
58557@@ -4,6 +4,7 @@
58558 #include <linux/path.h>
58559 #include <linux/slab.h>
58560 #include <linux/fs_struct.h>
58561+#include <linux/grsecurity.h>
58562 #include "internal.h"
58563
58564 /*
58565@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
58566 write_seqcount_begin(&fs->seq);
58567 old_root = fs->root;
58568 fs->root = *path;
58569+ gr_set_chroot_entries(current, path);
58570 write_seqcount_end(&fs->seq);
58571 spin_unlock(&fs->lock);
58572 if (old_root.dentry)
58573@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
58574 int hits = 0;
58575 spin_lock(&fs->lock);
58576 write_seqcount_begin(&fs->seq);
58577+ /* this root replacement is only done by pivot_root,
58578+ leave grsec's chroot tagging alone for this task
58579+ so that a pivoted root isn't treated as a chroot
58580+ */
58581 hits += replace_path(&fs->root, old_root, new_root);
58582 hits += replace_path(&fs->pwd, old_root, new_root);
58583 write_seqcount_end(&fs->seq);
58584@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
58585 task_lock(tsk);
58586 spin_lock(&fs->lock);
58587 tsk->fs = NULL;
58588- kill = !--fs->users;
58589+ gr_clear_chroot_entries(tsk);
58590+ kill = !atomic_dec_return(&fs->users);
58591 spin_unlock(&fs->lock);
58592 task_unlock(tsk);
58593 if (kill)
58594@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
58595 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
58596 /* We don't need to lock fs - think why ;-) */
58597 if (fs) {
58598- fs->users = 1;
58599+ atomic_set(&fs->users, 1);
58600 fs->in_exec = 0;
58601 spin_lock_init(&fs->lock);
58602 seqcount_init(&fs->seq);
58603@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
58604 spin_lock(&old->lock);
58605 fs->root = old->root;
58606 path_get(&fs->root);
58607+ /* instead of calling gr_set_chroot_entries here,
58608+ we call it from every caller of this function
58609+ */
58610 fs->pwd = old->pwd;
58611 path_get(&fs->pwd);
58612 spin_unlock(&old->lock);
58613@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
58614
58615 task_lock(current);
58616 spin_lock(&fs->lock);
58617- kill = !--fs->users;
58618+ kill = !atomic_dec_return(&fs->users);
58619 current->fs = new_fs;
58620+ gr_set_chroot_entries(current, &new_fs->root);
58621 spin_unlock(&fs->lock);
58622 task_unlock(current);
58623
58624@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
58625
58626 int current_umask(void)
58627 {
58628- return current->fs->umask;
58629+ return current->fs->umask | gr_acl_umask();
58630 }
58631 EXPORT_SYMBOL(current_umask);
58632
58633 /* to be mentioned only in INIT_TASK */
58634 struct fs_struct init_fs = {
58635- .users = 1,
58636+ .users = ATOMIC_INIT(1),
58637 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
58638 .seq = SEQCNT_ZERO(init_fs.seq),
58639 .umask = 0022,
58640diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
58641index 29d7feb..303644d 100644
58642--- a/fs/fscache/cookie.c
58643+++ b/fs/fscache/cookie.c
58644@@ -19,7 +19,7 @@
58645
58646 struct kmem_cache *fscache_cookie_jar;
58647
58648-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
58649+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
58650
58651 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
58652 static int fscache_alloc_object(struct fscache_cache *cache,
58653@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
58654 parent ? (char *) parent->def->name : "<no-parent>",
58655 def->name, netfs_data, enable);
58656
58657- fscache_stat(&fscache_n_acquires);
58658+ fscache_stat_unchecked(&fscache_n_acquires);
58659
58660 /* if there's no parent cookie, then we don't create one here either */
58661 if (!parent) {
58662- fscache_stat(&fscache_n_acquires_null);
58663+ fscache_stat_unchecked(&fscache_n_acquires_null);
58664 _leave(" [no parent]");
58665 return NULL;
58666 }
58667@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
58668 /* allocate and initialise a cookie */
58669 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
58670 if (!cookie) {
58671- fscache_stat(&fscache_n_acquires_oom);
58672+ fscache_stat_unchecked(&fscache_n_acquires_oom);
58673 _leave(" [ENOMEM]");
58674 return NULL;
58675 }
58676@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
58677
58678 switch (cookie->def->type) {
58679 case FSCACHE_COOKIE_TYPE_INDEX:
58680- fscache_stat(&fscache_n_cookie_index);
58681+ fscache_stat_unchecked(&fscache_n_cookie_index);
58682 break;
58683 case FSCACHE_COOKIE_TYPE_DATAFILE:
58684- fscache_stat(&fscache_n_cookie_data);
58685+ fscache_stat_unchecked(&fscache_n_cookie_data);
58686 break;
58687 default:
58688- fscache_stat(&fscache_n_cookie_special);
58689+ fscache_stat_unchecked(&fscache_n_cookie_special);
58690 break;
58691 }
58692
58693@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
58694 } else {
58695 atomic_dec(&parent->n_children);
58696 __fscache_cookie_put(cookie);
58697- fscache_stat(&fscache_n_acquires_nobufs);
58698+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
58699 _leave(" = NULL");
58700 return NULL;
58701 }
58702@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
58703 }
58704 }
58705
58706- fscache_stat(&fscache_n_acquires_ok);
58707+ fscache_stat_unchecked(&fscache_n_acquires_ok);
58708 _leave(" = %p", cookie);
58709 return cookie;
58710 }
58711@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
58712 cache = fscache_select_cache_for_object(cookie->parent);
58713 if (!cache) {
58714 up_read(&fscache_addremove_sem);
58715- fscache_stat(&fscache_n_acquires_no_cache);
58716+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
58717 _leave(" = -ENOMEDIUM [no cache]");
58718 return -ENOMEDIUM;
58719 }
58720@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
58721 object = cache->ops->alloc_object(cache, cookie);
58722 fscache_stat_d(&fscache_n_cop_alloc_object);
58723 if (IS_ERR(object)) {
58724- fscache_stat(&fscache_n_object_no_alloc);
58725+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
58726 ret = PTR_ERR(object);
58727 goto error;
58728 }
58729
58730- fscache_stat(&fscache_n_object_alloc);
58731+ fscache_stat_unchecked(&fscache_n_object_alloc);
58732
58733- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
58734+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
58735
58736 _debug("ALLOC OBJ%x: %s {%lx}",
58737 object->debug_id, cookie->def->name, object->events);
58738@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
58739
58740 _enter("{%s}", cookie->def->name);
58741
58742- fscache_stat(&fscache_n_invalidates);
58743+ fscache_stat_unchecked(&fscache_n_invalidates);
58744
58745 /* Only permit invalidation of data files. Invalidating an index will
58746 * require the caller to release all its attachments to the tree rooted
58747@@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
58748 {
58749 struct fscache_object *object;
58750
58751- fscache_stat(&fscache_n_updates);
58752+ fscache_stat_unchecked(&fscache_n_updates);
58753
58754 if (!cookie) {
58755- fscache_stat(&fscache_n_updates_null);
58756+ fscache_stat_unchecked(&fscache_n_updates_null);
58757 _leave(" [no cookie]");
58758 return;
58759 }
58760@@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
58761 */
58762 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
58763 {
58764- fscache_stat(&fscache_n_relinquishes);
58765+ fscache_stat_unchecked(&fscache_n_relinquishes);
58766 if (retire)
58767- fscache_stat(&fscache_n_relinquishes_retire);
58768+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
58769
58770 if (!cookie) {
58771- fscache_stat(&fscache_n_relinquishes_null);
58772+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
58773 _leave(" [no cookie]");
58774 return;
58775 }
58776@@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
58777 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
58778 goto inconsistent;
58779
58780- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
58781+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
58782
58783 __fscache_use_cookie(cookie);
58784 if (fscache_submit_op(object, op) < 0)
58785diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
58786index 4226f66..0fb3f45 100644
58787--- a/fs/fscache/internal.h
58788+++ b/fs/fscache/internal.h
58789@@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
58790 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
58791 extern int fscache_wait_for_operation_activation(struct fscache_object *,
58792 struct fscache_operation *,
58793- atomic_t *,
58794- atomic_t *,
58795+ atomic_unchecked_t *,
58796+ atomic_unchecked_t *,
58797 void (*)(struct fscache_operation *));
58798 extern void fscache_invalidate_writes(struct fscache_cookie *);
58799
58800@@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
58801 * stats.c
58802 */
58803 #ifdef CONFIG_FSCACHE_STATS
58804-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
58805-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
58806+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
58807+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
58808
58809-extern atomic_t fscache_n_op_pend;
58810-extern atomic_t fscache_n_op_run;
58811-extern atomic_t fscache_n_op_enqueue;
58812-extern atomic_t fscache_n_op_deferred_release;
58813-extern atomic_t fscache_n_op_release;
58814-extern atomic_t fscache_n_op_gc;
58815-extern atomic_t fscache_n_op_cancelled;
58816-extern atomic_t fscache_n_op_rejected;
58817+extern atomic_unchecked_t fscache_n_op_pend;
58818+extern atomic_unchecked_t fscache_n_op_run;
58819+extern atomic_unchecked_t fscache_n_op_enqueue;
58820+extern atomic_unchecked_t fscache_n_op_deferred_release;
58821+extern atomic_unchecked_t fscache_n_op_release;
58822+extern atomic_unchecked_t fscache_n_op_gc;
58823+extern atomic_unchecked_t fscache_n_op_cancelled;
58824+extern atomic_unchecked_t fscache_n_op_rejected;
58825
58826-extern atomic_t fscache_n_attr_changed;
58827-extern atomic_t fscache_n_attr_changed_ok;
58828-extern atomic_t fscache_n_attr_changed_nobufs;
58829-extern atomic_t fscache_n_attr_changed_nomem;
58830-extern atomic_t fscache_n_attr_changed_calls;
58831+extern atomic_unchecked_t fscache_n_attr_changed;
58832+extern atomic_unchecked_t fscache_n_attr_changed_ok;
58833+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
58834+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
58835+extern atomic_unchecked_t fscache_n_attr_changed_calls;
58836
58837-extern atomic_t fscache_n_allocs;
58838-extern atomic_t fscache_n_allocs_ok;
58839-extern atomic_t fscache_n_allocs_wait;
58840-extern atomic_t fscache_n_allocs_nobufs;
58841-extern atomic_t fscache_n_allocs_intr;
58842-extern atomic_t fscache_n_allocs_object_dead;
58843-extern atomic_t fscache_n_alloc_ops;
58844-extern atomic_t fscache_n_alloc_op_waits;
58845+extern atomic_unchecked_t fscache_n_allocs;
58846+extern atomic_unchecked_t fscache_n_allocs_ok;
58847+extern atomic_unchecked_t fscache_n_allocs_wait;
58848+extern atomic_unchecked_t fscache_n_allocs_nobufs;
58849+extern atomic_unchecked_t fscache_n_allocs_intr;
58850+extern atomic_unchecked_t fscache_n_allocs_object_dead;
58851+extern atomic_unchecked_t fscache_n_alloc_ops;
58852+extern atomic_unchecked_t fscache_n_alloc_op_waits;
58853
58854-extern atomic_t fscache_n_retrievals;
58855-extern atomic_t fscache_n_retrievals_ok;
58856-extern atomic_t fscache_n_retrievals_wait;
58857-extern atomic_t fscache_n_retrievals_nodata;
58858-extern atomic_t fscache_n_retrievals_nobufs;
58859-extern atomic_t fscache_n_retrievals_intr;
58860-extern atomic_t fscache_n_retrievals_nomem;
58861-extern atomic_t fscache_n_retrievals_object_dead;
58862-extern atomic_t fscache_n_retrieval_ops;
58863-extern atomic_t fscache_n_retrieval_op_waits;
58864+extern atomic_unchecked_t fscache_n_retrievals;
58865+extern atomic_unchecked_t fscache_n_retrievals_ok;
58866+extern atomic_unchecked_t fscache_n_retrievals_wait;
58867+extern atomic_unchecked_t fscache_n_retrievals_nodata;
58868+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
58869+extern atomic_unchecked_t fscache_n_retrievals_intr;
58870+extern atomic_unchecked_t fscache_n_retrievals_nomem;
58871+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
58872+extern atomic_unchecked_t fscache_n_retrieval_ops;
58873+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
58874
58875-extern atomic_t fscache_n_stores;
58876-extern atomic_t fscache_n_stores_ok;
58877-extern atomic_t fscache_n_stores_again;
58878-extern atomic_t fscache_n_stores_nobufs;
58879-extern atomic_t fscache_n_stores_oom;
58880-extern atomic_t fscache_n_store_ops;
58881-extern atomic_t fscache_n_store_calls;
58882-extern atomic_t fscache_n_store_pages;
58883-extern atomic_t fscache_n_store_radix_deletes;
58884-extern atomic_t fscache_n_store_pages_over_limit;
58885+extern atomic_unchecked_t fscache_n_stores;
58886+extern atomic_unchecked_t fscache_n_stores_ok;
58887+extern atomic_unchecked_t fscache_n_stores_again;
58888+extern atomic_unchecked_t fscache_n_stores_nobufs;
58889+extern atomic_unchecked_t fscache_n_stores_oom;
58890+extern atomic_unchecked_t fscache_n_store_ops;
58891+extern atomic_unchecked_t fscache_n_store_calls;
58892+extern atomic_unchecked_t fscache_n_store_pages;
58893+extern atomic_unchecked_t fscache_n_store_radix_deletes;
58894+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
58895
58896-extern atomic_t fscache_n_store_vmscan_not_storing;
58897-extern atomic_t fscache_n_store_vmscan_gone;
58898-extern atomic_t fscache_n_store_vmscan_busy;
58899-extern atomic_t fscache_n_store_vmscan_cancelled;
58900-extern atomic_t fscache_n_store_vmscan_wait;
58901+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
58902+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
58903+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
58904+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
58905+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
58906
58907-extern atomic_t fscache_n_marks;
58908-extern atomic_t fscache_n_uncaches;
58909+extern atomic_unchecked_t fscache_n_marks;
58910+extern atomic_unchecked_t fscache_n_uncaches;
58911
58912-extern atomic_t fscache_n_acquires;
58913-extern atomic_t fscache_n_acquires_null;
58914-extern atomic_t fscache_n_acquires_no_cache;
58915-extern atomic_t fscache_n_acquires_ok;
58916-extern atomic_t fscache_n_acquires_nobufs;
58917-extern atomic_t fscache_n_acquires_oom;
58918+extern atomic_unchecked_t fscache_n_acquires;
58919+extern atomic_unchecked_t fscache_n_acquires_null;
58920+extern atomic_unchecked_t fscache_n_acquires_no_cache;
58921+extern atomic_unchecked_t fscache_n_acquires_ok;
58922+extern atomic_unchecked_t fscache_n_acquires_nobufs;
58923+extern atomic_unchecked_t fscache_n_acquires_oom;
58924
58925-extern atomic_t fscache_n_invalidates;
58926-extern atomic_t fscache_n_invalidates_run;
58927+extern atomic_unchecked_t fscache_n_invalidates;
58928+extern atomic_unchecked_t fscache_n_invalidates_run;
58929
58930-extern atomic_t fscache_n_updates;
58931-extern atomic_t fscache_n_updates_null;
58932-extern atomic_t fscache_n_updates_run;
58933+extern atomic_unchecked_t fscache_n_updates;
58934+extern atomic_unchecked_t fscache_n_updates_null;
58935+extern atomic_unchecked_t fscache_n_updates_run;
58936
58937-extern atomic_t fscache_n_relinquishes;
58938-extern atomic_t fscache_n_relinquishes_null;
58939-extern atomic_t fscache_n_relinquishes_waitcrt;
58940-extern atomic_t fscache_n_relinquishes_retire;
58941+extern atomic_unchecked_t fscache_n_relinquishes;
58942+extern atomic_unchecked_t fscache_n_relinquishes_null;
58943+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
58944+extern atomic_unchecked_t fscache_n_relinquishes_retire;
58945
58946-extern atomic_t fscache_n_cookie_index;
58947-extern atomic_t fscache_n_cookie_data;
58948-extern atomic_t fscache_n_cookie_special;
58949+extern atomic_unchecked_t fscache_n_cookie_index;
58950+extern atomic_unchecked_t fscache_n_cookie_data;
58951+extern atomic_unchecked_t fscache_n_cookie_special;
58952
58953-extern atomic_t fscache_n_object_alloc;
58954-extern atomic_t fscache_n_object_no_alloc;
58955-extern atomic_t fscache_n_object_lookups;
58956-extern atomic_t fscache_n_object_lookups_negative;
58957-extern atomic_t fscache_n_object_lookups_positive;
58958-extern atomic_t fscache_n_object_lookups_timed_out;
58959-extern atomic_t fscache_n_object_created;
58960-extern atomic_t fscache_n_object_avail;
58961-extern atomic_t fscache_n_object_dead;
58962+extern atomic_unchecked_t fscache_n_object_alloc;
58963+extern atomic_unchecked_t fscache_n_object_no_alloc;
58964+extern atomic_unchecked_t fscache_n_object_lookups;
58965+extern atomic_unchecked_t fscache_n_object_lookups_negative;
58966+extern atomic_unchecked_t fscache_n_object_lookups_positive;
58967+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
58968+extern atomic_unchecked_t fscache_n_object_created;
58969+extern atomic_unchecked_t fscache_n_object_avail;
58970+extern atomic_unchecked_t fscache_n_object_dead;
58971
58972-extern atomic_t fscache_n_checkaux_none;
58973-extern atomic_t fscache_n_checkaux_okay;
58974-extern atomic_t fscache_n_checkaux_update;
58975-extern atomic_t fscache_n_checkaux_obsolete;
58976+extern atomic_unchecked_t fscache_n_checkaux_none;
58977+extern atomic_unchecked_t fscache_n_checkaux_okay;
58978+extern atomic_unchecked_t fscache_n_checkaux_update;
58979+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
58980
58981 extern atomic_t fscache_n_cop_alloc_object;
58982 extern atomic_t fscache_n_cop_lookup_object;
58983@@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
58984 atomic_inc(stat);
58985 }
58986
58987+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
58988+{
58989+ atomic_inc_unchecked(stat);
58990+}
58991+
58992 static inline void fscache_stat_d(atomic_t *stat)
58993 {
58994 atomic_dec(stat);
58995@@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
58996
58997 #define __fscache_stat(stat) (NULL)
58998 #define fscache_stat(stat) do {} while (0)
58999+#define fscache_stat_unchecked(stat) do {} while (0)
59000 #define fscache_stat_d(stat) do {} while (0)
59001 #endif
59002
59003diff --git a/fs/fscache/object.c b/fs/fscache/object.c
59004index 53d35c5..5d68ed4 100644
59005--- a/fs/fscache/object.c
59006+++ b/fs/fscache/object.c
59007@@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
59008 _debug("LOOKUP \"%s\" in \"%s\"",
59009 cookie->def->name, object->cache->tag->name);
59010
59011- fscache_stat(&fscache_n_object_lookups);
59012+ fscache_stat_unchecked(&fscache_n_object_lookups);
59013 fscache_stat(&fscache_n_cop_lookup_object);
59014 ret = object->cache->ops->lookup_object(object);
59015 fscache_stat_d(&fscache_n_cop_lookup_object);
59016@@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
59017 if (ret == -ETIMEDOUT) {
59018 /* probably stuck behind another object, so move this one to
59019 * the back of the queue */
59020- fscache_stat(&fscache_n_object_lookups_timed_out);
59021+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
59022 _leave(" [timeout]");
59023 return NO_TRANSIT;
59024 }
59025@@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
59026 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
59027
59028 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59029- fscache_stat(&fscache_n_object_lookups_negative);
59030+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
59031
59032 /* Allow write requests to begin stacking up and read requests to begin
59033 * returning ENODATA.
59034@@ -524,7 +524,7 @@ void fscache_obtained_object(struct fscache_object *object)
59035 /* if we were still looking up, then we must have a positive lookup
59036 * result, in which case there may be data available */
59037 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59038- fscache_stat(&fscache_n_object_lookups_positive);
59039+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
59040
59041 /* We do (presumably) have data */
59042 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
59043@@ -536,7 +536,7 @@ void fscache_obtained_object(struct fscache_object *object)
59044 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
59045 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
59046 } else {
59047- fscache_stat(&fscache_n_object_created);
59048+ fscache_stat_unchecked(&fscache_n_object_created);
59049 }
59050
59051 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
59052@@ -572,7 +572,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
59053 fscache_stat_d(&fscache_n_cop_lookup_complete);
59054
59055 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
59056- fscache_stat(&fscache_n_object_avail);
59057+ fscache_stat_unchecked(&fscache_n_object_avail);
59058
59059 _leave("");
59060 return transit_to(JUMPSTART_DEPS);
59061@@ -719,7 +719,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
59062
59063 /* this just shifts the object release to the work processor */
59064 fscache_put_object(object);
59065- fscache_stat(&fscache_n_object_dead);
59066+ fscache_stat_unchecked(&fscache_n_object_dead);
59067
59068 _leave("");
59069 return transit_to(OBJECT_DEAD);
59070@@ -884,7 +884,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
59071 enum fscache_checkaux result;
59072
59073 if (!object->cookie->def->check_aux) {
59074- fscache_stat(&fscache_n_checkaux_none);
59075+ fscache_stat_unchecked(&fscache_n_checkaux_none);
59076 return FSCACHE_CHECKAUX_OKAY;
59077 }
59078
59079@@ -893,17 +893,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
59080 switch (result) {
59081 /* entry okay as is */
59082 case FSCACHE_CHECKAUX_OKAY:
59083- fscache_stat(&fscache_n_checkaux_okay);
59084+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
59085 break;
59086
59087 /* entry requires update */
59088 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
59089- fscache_stat(&fscache_n_checkaux_update);
59090+ fscache_stat_unchecked(&fscache_n_checkaux_update);
59091 break;
59092
59093 /* entry requires deletion */
59094 case FSCACHE_CHECKAUX_OBSOLETE:
59095- fscache_stat(&fscache_n_checkaux_obsolete);
59096+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
59097 break;
59098
59099 default:
59100@@ -989,7 +989,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
59101 {
59102 const struct fscache_state *s;
59103
59104- fscache_stat(&fscache_n_invalidates_run);
59105+ fscache_stat_unchecked(&fscache_n_invalidates_run);
59106 fscache_stat(&fscache_n_cop_invalidate_object);
59107 s = _fscache_invalidate_object(object, event);
59108 fscache_stat_d(&fscache_n_cop_invalidate_object);
59109@@ -1004,7 +1004,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
59110 {
59111 _enter("{OBJ%x},%d", object->debug_id, event);
59112
59113- fscache_stat(&fscache_n_updates_run);
59114+ fscache_stat_unchecked(&fscache_n_updates_run);
59115 fscache_stat(&fscache_n_cop_update_object);
59116 object->cache->ops->update_object(object);
59117 fscache_stat_d(&fscache_n_cop_update_object);
59118diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
59119index 318071a..379938b 100644
59120--- a/fs/fscache/operation.c
59121+++ b/fs/fscache/operation.c
59122@@ -17,7 +17,7 @@
59123 #include <linux/slab.h>
59124 #include "internal.h"
59125
59126-atomic_t fscache_op_debug_id;
59127+atomic_unchecked_t fscache_op_debug_id;
59128 EXPORT_SYMBOL(fscache_op_debug_id);
59129
59130 /**
59131@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
59132 ASSERTCMP(atomic_read(&op->usage), >, 0);
59133 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
59134
59135- fscache_stat(&fscache_n_op_enqueue);
59136+ fscache_stat_unchecked(&fscache_n_op_enqueue);
59137 switch (op->flags & FSCACHE_OP_TYPE) {
59138 case FSCACHE_OP_ASYNC:
59139 _debug("queue async");
59140@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
59141 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
59142 if (op->processor)
59143 fscache_enqueue_operation(op);
59144- fscache_stat(&fscache_n_op_run);
59145+ fscache_stat_unchecked(&fscache_n_op_run);
59146 }
59147
59148 /*
59149@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
59150 if (object->n_in_progress > 0) {
59151 atomic_inc(&op->usage);
59152 list_add_tail(&op->pend_link, &object->pending_ops);
59153- fscache_stat(&fscache_n_op_pend);
59154+ fscache_stat_unchecked(&fscache_n_op_pend);
59155 } else if (!list_empty(&object->pending_ops)) {
59156 atomic_inc(&op->usage);
59157 list_add_tail(&op->pend_link, &object->pending_ops);
59158- fscache_stat(&fscache_n_op_pend);
59159+ fscache_stat_unchecked(&fscache_n_op_pend);
59160 fscache_start_operations(object);
59161 } else {
59162 ASSERTCMP(object->n_in_progress, ==, 0);
59163@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
59164 object->n_exclusive++; /* reads and writes must wait */
59165 atomic_inc(&op->usage);
59166 list_add_tail(&op->pend_link, &object->pending_ops);
59167- fscache_stat(&fscache_n_op_pend);
59168+ fscache_stat_unchecked(&fscache_n_op_pend);
59169 ret = 0;
59170 } else {
59171 /* If we're in any other state, there must have been an I/O
59172@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
59173 if (object->n_exclusive > 0) {
59174 atomic_inc(&op->usage);
59175 list_add_tail(&op->pend_link, &object->pending_ops);
59176- fscache_stat(&fscache_n_op_pend);
59177+ fscache_stat_unchecked(&fscache_n_op_pend);
59178 } else if (!list_empty(&object->pending_ops)) {
59179 atomic_inc(&op->usage);
59180 list_add_tail(&op->pend_link, &object->pending_ops);
59181- fscache_stat(&fscache_n_op_pend);
59182+ fscache_stat_unchecked(&fscache_n_op_pend);
59183 fscache_start_operations(object);
59184 } else {
59185 ASSERTCMP(object->n_exclusive, ==, 0);
59186@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
59187 object->n_ops++;
59188 atomic_inc(&op->usage);
59189 list_add_tail(&op->pend_link, &object->pending_ops);
59190- fscache_stat(&fscache_n_op_pend);
59191+ fscache_stat_unchecked(&fscache_n_op_pend);
59192 ret = 0;
59193 } else if (fscache_object_is_dying(object)) {
59194- fscache_stat(&fscache_n_op_rejected);
59195+ fscache_stat_unchecked(&fscache_n_op_rejected);
59196 op->state = FSCACHE_OP_ST_CANCELLED;
59197 ret = -ENOBUFS;
59198 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
59199@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
59200 ret = -EBUSY;
59201 if (op->state == FSCACHE_OP_ST_PENDING) {
59202 ASSERT(!list_empty(&op->pend_link));
59203- fscache_stat(&fscache_n_op_cancelled);
59204+ fscache_stat_unchecked(&fscache_n_op_cancelled);
59205 list_del_init(&op->pend_link);
59206 if (do_cancel)
59207 do_cancel(op);
59208@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
59209 while (!list_empty(&object->pending_ops)) {
59210 op = list_entry(object->pending_ops.next,
59211 struct fscache_operation, pend_link);
59212- fscache_stat(&fscache_n_op_cancelled);
59213+ fscache_stat_unchecked(&fscache_n_op_cancelled);
59214 list_del_init(&op->pend_link);
59215
59216 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
59217@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
59218 op->state, ==, FSCACHE_OP_ST_CANCELLED);
59219 op->state = FSCACHE_OP_ST_DEAD;
59220
59221- fscache_stat(&fscache_n_op_release);
59222+ fscache_stat_unchecked(&fscache_n_op_release);
59223
59224 if (op->release) {
59225 op->release(op);
59226@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
59227 * lock, and defer it otherwise */
59228 if (!spin_trylock(&object->lock)) {
59229 _debug("defer put");
59230- fscache_stat(&fscache_n_op_deferred_release);
59231+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
59232
59233 cache = object->cache;
59234 spin_lock(&cache->op_gc_list_lock);
59235@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
59236
59237 _debug("GC DEFERRED REL OBJ%x OP%x",
59238 object->debug_id, op->debug_id);
59239- fscache_stat(&fscache_n_op_gc);
59240+ fscache_stat_unchecked(&fscache_n_op_gc);
59241
59242 ASSERTCMP(atomic_read(&op->usage), ==, 0);
59243 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
59244diff --git a/fs/fscache/page.c b/fs/fscache/page.c
59245index 7f5c658..6c1e164 100644
59246--- a/fs/fscache/page.c
59247+++ b/fs/fscache/page.c
59248@@ -61,7 +61,7 @@ try_again:
59249 val = radix_tree_lookup(&cookie->stores, page->index);
59250 if (!val) {
59251 rcu_read_unlock();
59252- fscache_stat(&fscache_n_store_vmscan_not_storing);
59253+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
59254 __fscache_uncache_page(cookie, page);
59255 return true;
59256 }
59257@@ -91,11 +91,11 @@ try_again:
59258 spin_unlock(&cookie->stores_lock);
59259
59260 if (xpage) {
59261- fscache_stat(&fscache_n_store_vmscan_cancelled);
59262- fscache_stat(&fscache_n_store_radix_deletes);
59263+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
59264+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
59265 ASSERTCMP(xpage, ==, page);
59266 } else {
59267- fscache_stat(&fscache_n_store_vmscan_gone);
59268+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
59269 }
59270
59271 wake_up_bit(&cookie->flags, 0);
59272@@ -110,11 +110,11 @@ page_busy:
59273 * sleeping on memory allocation, so we may need to impose a timeout
59274 * too. */
59275 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
59276- fscache_stat(&fscache_n_store_vmscan_busy);
59277+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
59278 return false;
59279 }
59280
59281- fscache_stat(&fscache_n_store_vmscan_wait);
59282+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
59283 __fscache_wait_on_page_write(cookie, page);
59284 gfp &= ~__GFP_WAIT;
59285 goto try_again;
59286@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
59287 FSCACHE_COOKIE_STORING_TAG);
59288 if (!radix_tree_tag_get(&cookie->stores, page->index,
59289 FSCACHE_COOKIE_PENDING_TAG)) {
59290- fscache_stat(&fscache_n_store_radix_deletes);
59291+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
59292 xpage = radix_tree_delete(&cookie->stores, page->index);
59293 }
59294 spin_unlock(&cookie->stores_lock);
59295@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
59296
59297 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
59298
59299- fscache_stat(&fscache_n_attr_changed_calls);
59300+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
59301
59302 if (fscache_object_is_active(object)) {
59303 fscache_stat(&fscache_n_cop_attr_changed);
59304@@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
59305
59306 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
59307
59308- fscache_stat(&fscache_n_attr_changed);
59309+ fscache_stat_unchecked(&fscache_n_attr_changed);
59310
59311 op = kzalloc(sizeof(*op), GFP_KERNEL);
59312 if (!op) {
59313- fscache_stat(&fscache_n_attr_changed_nomem);
59314+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
59315 _leave(" = -ENOMEM");
59316 return -ENOMEM;
59317 }
59318@@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
59319 if (fscache_submit_exclusive_op(object, op) < 0)
59320 goto nobufs;
59321 spin_unlock(&cookie->lock);
59322- fscache_stat(&fscache_n_attr_changed_ok);
59323+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
59324 fscache_put_operation(op);
59325 _leave(" = 0");
59326 return 0;
59327@@ -225,7 +225,7 @@ nobufs:
59328 kfree(op);
59329 if (wake_cookie)
59330 __fscache_wake_unused_cookie(cookie);
59331- fscache_stat(&fscache_n_attr_changed_nobufs);
59332+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
59333 _leave(" = %d", -ENOBUFS);
59334 return -ENOBUFS;
59335 }
59336@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
59337 /* allocate a retrieval operation and attempt to submit it */
59338 op = kzalloc(sizeof(*op), GFP_NOIO);
59339 if (!op) {
59340- fscache_stat(&fscache_n_retrievals_nomem);
59341+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
59342 return NULL;
59343 }
59344
59345@@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
59346 return 0;
59347 }
59348
59349- fscache_stat(&fscache_n_retrievals_wait);
59350+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
59351
59352 jif = jiffies;
59353 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
59354 fscache_wait_bit_interruptible,
59355 TASK_INTERRUPTIBLE) != 0) {
59356- fscache_stat(&fscache_n_retrievals_intr);
59357+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
59358 _leave(" = -ERESTARTSYS");
59359 return -ERESTARTSYS;
59360 }
59361@@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
59362 */
59363 int fscache_wait_for_operation_activation(struct fscache_object *object,
59364 struct fscache_operation *op,
59365- atomic_t *stat_op_waits,
59366- atomic_t *stat_object_dead,
59367+ atomic_unchecked_t *stat_op_waits,
59368+ atomic_unchecked_t *stat_object_dead,
59369 void (*do_cancel)(struct fscache_operation *))
59370 {
59371 int ret;
59372@@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
59373
59374 _debug(">>> WT");
59375 if (stat_op_waits)
59376- fscache_stat(stat_op_waits);
59377+ fscache_stat_unchecked(stat_op_waits);
59378 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
59379 fscache_wait_bit_interruptible,
59380 TASK_INTERRUPTIBLE) != 0) {
59381@@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
59382 check_if_dead:
59383 if (op->state == FSCACHE_OP_ST_CANCELLED) {
59384 if (stat_object_dead)
59385- fscache_stat(stat_object_dead);
59386+ fscache_stat_unchecked(stat_object_dead);
59387 _leave(" = -ENOBUFS [cancelled]");
59388 return -ENOBUFS;
59389 }
59390@@ -366,7 +366,7 @@ check_if_dead:
59391 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
59392 fscache_cancel_op(op, do_cancel);
59393 if (stat_object_dead)
59394- fscache_stat(stat_object_dead);
59395+ fscache_stat_unchecked(stat_object_dead);
59396 return -ENOBUFS;
59397 }
59398 return 0;
59399@@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
59400
59401 _enter("%p,%p,,,", cookie, page);
59402
59403- fscache_stat(&fscache_n_retrievals);
59404+ fscache_stat_unchecked(&fscache_n_retrievals);
59405
59406 if (hlist_empty(&cookie->backing_objects))
59407 goto nobufs;
59408@@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
59409 goto nobufs_unlock_dec;
59410 spin_unlock(&cookie->lock);
59411
59412- fscache_stat(&fscache_n_retrieval_ops);
59413+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
59414
59415 /* pin the netfs read context in case we need to do the actual netfs
59416 * read because we've encountered a cache read failure */
59417@@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
59418
59419 error:
59420 if (ret == -ENOMEM)
59421- fscache_stat(&fscache_n_retrievals_nomem);
59422+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
59423 else if (ret == -ERESTARTSYS)
59424- fscache_stat(&fscache_n_retrievals_intr);
59425+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
59426 else if (ret == -ENODATA)
59427- fscache_stat(&fscache_n_retrievals_nodata);
59428+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
59429 else if (ret < 0)
59430- fscache_stat(&fscache_n_retrievals_nobufs);
59431+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59432 else
59433- fscache_stat(&fscache_n_retrievals_ok);
59434+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
59435
59436 fscache_put_retrieval(op);
59437 _leave(" = %d", ret);
59438@@ -490,7 +490,7 @@ nobufs_unlock:
59439 __fscache_wake_unused_cookie(cookie);
59440 kfree(op);
59441 nobufs:
59442- fscache_stat(&fscache_n_retrievals_nobufs);
59443+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59444 _leave(" = -ENOBUFS");
59445 return -ENOBUFS;
59446 }
59447@@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
59448
59449 _enter("%p,,%d,,,", cookie, *nr_pages);
59450
59451- fscache_stat(&fscache_n_retrievals);
59452+ fscache_stat_unchecked(&fscache_n_retrievals);
59453
59454 if (hlist_empty(&cookie->backing_objects))
59455 goto nobufs;
59456@@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
59457 goto nobufs_unlock_dec;
59458 spin_unlock(&cookie->lock);
59459
59460- fscache_stat(&fscache_n_retrieval_ops);
59461+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
59462
59463 /* pin the netfs read context in case we need to do the actual netfs
59464 * read because we've encountered a cache read failure */
59465@@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
59466
59467 error:
59468 if (ret == -ENOMEM)
59469- fscache_stat(&fscache_n_retrievals_nomem);
59470+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
59471 else if (ret == -ERESTARTSYS)
59472- fscache_stat(&fscache_n_retrievals_intr);
59473+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
59474 else if (ret == -ENODATA)
59475- fscache_stat(&fscache_n_retrievals_nodata);
59476+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
59477 else if (ret < 0)
59478- fscache_stat(&fscache_n_retrievals_nobufs);
59479+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59480 else
59481- fscache_stat(&fscache_n_retrievals_ok);
59482+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
59483
59484 fscache_put_retrieval(op);
59485 _leave(" = %d", ret);
59486@@ -621,7 +621,7 @@ nobufs_unlock:
59487 if (wake_cookie)
59488 __fscache_wake_unused_cookie(cookie);
59489 nobufs:
59490- fscache_stat(&fscache_n_retrievals_nobufs);
59491+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59492 _leave(" = -ENOBUFS");
59493 return -ENOBUFS;
59494 }
59495@@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
59496
59497 _enter("%p,%p,,,", cookie, page);
59498
59499- fscache_stat(&fscache_n_allocs);
59500+ fscache_stat_unchecked(&fscache_n_allocs);
59501
59502 if (hlist_empty(&cookie->backing_objects))
59503 goto nobufs;
59504@@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
59505 goto nobufs_unlock_dec;
59506 spin_unlock(&cookie->lock);
59507
59508- fscache_stat(&fscache_n_alloc_ops);
59509+ fscache_stat_unchecked(&fscache_n_alloc_ops);
59510
59511 ret = fscache_wait_for_operation_activation(
59512 object, &op->op,
59513@@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
59514
59515 error:
59516 if (ret == -ERESTARTSYS)
59517- fscache_stat(&fscache_n_allocs_intr);
59518+ fscache_stat_unchecked(&fscache_n_allocs_intr);
59519 else if (ret < 0)
59520- fscache_stat(&fscache_n_allocs_nobufs);
59521+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
59522 else
59523- fscache_stat(&fscache_n_allocs_ok);
59524+ fscache_stat_unchecked(&fscache_n_allocs_ok);
59525
59526 fscache_put_retrieval(op);
59527 _leave(" = %d", ret);
59528@@ -715,7 +715,7 @@ nobufs_unlock:
59529 if (wake_cookie)
59530 __fscache_wake_unused_cookie(cookie);
59531 nobufs:
59532- fscache_stat(&fscache_n_allocs_nobufs);
59533+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
59534 _leave(" = -ENOBUFS");
59535 return -ENOBUFS;
59536 }
59537@@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
59538
59539 spin_lock(&cookie->stores_lock);
59540
59541- fscache_stat(&fscache_n_store_calls);
59542+ fscache_stat_unchecked(&fscache_n_store_calls);
59543
59544 /* find a page to store */
59545 page = NULL;
59546@@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
59547 page = results[0];
59548 _debug("gang %d [%lx]", n, page->index);
59549 if (page->index > op->store_limit) {
59550- fscache_stat(&fscache_n_store_pages_over_limit);
59551+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
59552 goto superseded;
59553 }
59554
59555@@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
59556 spin_unlock(&cookie->stores_lock);
59557 spin_unlock(&object->lock);
59558
59559- fscache_stat(&fscache_n_store_pages);
59560+ fscache_stat_unchecked(&fscache_n_store_pages);
59561 fscache_stat(&fscache_n_cop_write_page);
59562 ret = object->cache->ops->write_page(op, page);
59563 fscache_stat_d(&fscache_n_cop_write_page);
59564@@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59565 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
59566 ASSERT(PageFsCache(page));
59567
59568- fscache_stat(&fscache_n_stores);
59569+ fscache_stat_unchecked(&fscache_n_stores);
59570
59571 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
59572 _leave(" = -ENOBUFS [invalidating]");
59573@@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59574 spin_unlock(&cookie->stores_lock);
59575 spin_unlock(&object->lock);
59576
59577- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
59578+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59579 op->store_limit = object->store_limit;
59580
59581 __fscache_use_cookie(cookie);
59582@@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59583
59584 spin_unlock(&cookie->lock);
59585 radix_tree_preload_end();
59586- fscache_stat(&fscache_n_store_ops);
59587- fscache_stat(&fscache_n_stores_ok);
59588+ fscache_stat_unchecked(&fscache_n_store_ops);
59589+ fscache_stat_unchecked(&fscache_n_stores_ok);
59590
59591 /* the work queue now carries its own ref on the object */
59592 fscache_put_operation(&op->op);
59593@@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59594 return 0;
59595
59596 already_queued:
59597- fscache_stat(&fscache_n_stores_again);
59598+ fscache_stat_unchecked(&fscache_n_stores_again);
59599 already_pending:
59600 spin_unlock(&cookie->stores_lock);
59601 spin_unlock(&object->lock);
59602 spin_unlock(&cookie->lock);
59603 radix_tree_preload_end();
59604 kfree(op);
59605- fscache_stat(&fscache_n_stores_ok);
59606+ fscache_stat_unchecked(&fscache_n_stores_ok);
59607 _leave(" = 0");
59608 return 0;
59609
59610@@ -1024,14 +1024,14 @@ nobufs:
59611 kfree(op);
59612 if (wake_cookie)
59613 __fscache_wake_unused_cookie(cookie);
59614- fscache_stat(&fscache_n_stores_nobufs);
59615+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
59616 _leave(" = -ENOBUFS");
59617 return -ENOBUFS;
59618
59619 nomem_free:
59620 kfree(op);
59621 nomem:
59622- fscache_stat(&fscache_n_stores_oom);
59623+ fscache_stat_unchecked(&fscache_n_stores_oom);
59624 _leave(" = -ENOMEM");
59625 return -ENOMEM;
59626 }
59627@@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
59628 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
59629 ASSERTCMP(page, !=, NULL);
59630
59631- fscache_stat(&fscache_n_uncaches);
59632+ fscache_stat_unchecked(&fscache_n_uncaches);
59633
59634 /* cache withdrawal may beat us to it */
59635 if (!PageFsCache(page))
59636@@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
59637 struct fscache_cookie *cookie = op->op.object->cookie;
59638
59639 #ifdef CONFIG_FSCACHE_STATS
59640- atomic_inc(&fscache_n_marks);
59641+ atomic_inc_unchecked(&fscache_n_marks);
59642 #endif
59643
59644 _debug("- mark %p{%lx}", page, page->index);
59645diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
59646index 40d13c7..ddf52b9 100644
59647--- a/fs/fscache/stats.c
59648+++ b/fs/fscache/stats.c
59649@@ -18,99 +18,99 @@
59650 /*
59651 * operation counters
59652 */
59653-atomic_t fscache_n_op_pend;
59654-atomic_t fscache_n_op_run;
59655-atomic_t fscache_n_op_enqueue;
59656-atomic_t fscache_n_op_requeue;
59657-atomic_t fscache_n_op_deferred_release;
59658-atomic_t fscache_n_op_release;
59659-atomic_t fscache_n_op_gc;
59660-atomic_t fscache_n_op_cancelled;
59661-atomic_t fscache_n_op_rejected;
59662+atomic_unchecked_t fscache_n_op_pend;
59663+atomic_unchecked_t fscache_n_op_run;
59664+atomic_unchecked_t fscache_n_op_enqueue;
59665+atomic_unchecked_t fscache_n_op_requeue;
59666+atomic_unchecked_t fscache_n_op_deferred_release;
59667+atomic_unchecked_t fscache_n_op_release;
59668+atomic_unchecked_t fscache_n_op_gc;
59669+atomic_unchecked_t fscache_n_op_cancelled;
59670+atomic_unchecked_t fscache_n_op_rejected;
59671
59672-atomic_t fscache_n_attr_changed;
59673-atomic_t fscache_n_attr_changed_ok;
59674-atomic_t fscache_n_attr_changed_nobufs;
59675-atomic_t fscache_n_attr_changed_nomem;
59676-atomic_t fscache_n_attr_changed_calls;
59677+atomic_unchecked_t fscache_n_attr_changed;
59678+atomic_unchecked_t fscache_n_attr_changed_ok;
59679+atomic_unchecked_t fscache_n_attr_changed_nobufs;
59680+atomic_unchecked_t fscache_n_attr_changed_nomem;
59681+atomic_unchecked_t fscache_n_attr_changed_calls;
59682
59683-atomic_t fscache_n_allocs;
59684-atomic_t fscache_n_allocs_ok;
59685-atomic_t fscache_n_allocs_wait;
59686-atomic_t fscache_n_allocs_nobufs;
59687-atomic_t fscache_n_allocs_intr;
59688-atomic_t fscache_n_allocs_object_dead;
59689-atomic_t fscache_n_alloc_ops;
59690-atomic_t fscache_n_alloc_op_waits;
59691+atomic_unchecked_t fscache_n_allocs;
59692+atomic_unchecked_t fscache_n_allocs_ok;
59693+atomic_unchecked_t fscache_n_allocs_wait;
59694+atomic_unchecked_t fscache_n_allocs_nobufs;
59695+atomic_unchecked_t fscache_n_allocs_intr;
59696+atomic_unchecked_t fscache_n_allocs_object_dead;
59697+atomic_unchecked_t fscache_n_alloc_ops;
59698+atomic_unchecked_t fscache_n_alloc_op_waits;
59699
59700-atomic_t fscache_n_retrievals;
59701-atomic_t fscache_n_retrievals_ok;
59702-atomic_t fscache_n_retrievals_wait;
59703-atomic_t fscache_n_retrievals_nodata;
59704-atomic_t fscache_n_retrievals_nobufs;
59705-atomic_t fscache_n_retrievals_intr;
59706-atomic_t fscache_n_retrievals_nomem;
59707-atomic_t fscache_n_retrievals_object_dead;
59708-atomic_t fscache_n_retrieval_ops;
59709-atomic_t fscache_n_retrieval_op_waits;
59710+atomic_unchecked_t fscache_n_retrievals;
59711+atomic_unchecked_t fscache_n_retrievals_ok;
59712+atomic_unchecked_t fscache_n_retrievals_wait;
59713+atomic_unchecked_t fscache_n_retrievals_nodata;
59714+atomic_unchecked_t fscache_n_retrievals_nobufs;
59715+atomic_unchecked_t fscache_n_retrievals_intr;
59716+atomic_unchecked_t fscache_n_retrievals_nomem;
59717+atomic_unchecked_t fscache_n_retrievals_object_dead;
59718+atomic_unchecked_t fscache_n_retrieval_ops;
59719+atomic_unchecked_t fscache_n_retrieval_op_waits;
59720
59721-atomic_t fscache_n_stores;
59722-atomic_t fscache_n_stores_ok;
59723-atomic_t fscache_n_stores_again;
59724-atomic_t fscache_n_stores_nobufs;
59725-atomic_t fscache_n_stores_oom;
59726-atomic_t fscache_n_store_ops;
59727-atomic_t fscache_n_store_calls;
59728-atomic_t fscache_n_store_pages;
59729-atomic_t fscache_n_store_radix_deletes;
59730-atomic_t fscache_n_store_pages_over_limit;
59731+atomic_unchecked_t fscache_n_stores;
59732+atomic_unchecked_t fscache_n_stores_ok;
59733+atomic_unchecked_t fscache_n_stores_again;
59734+atomic_unchecked_t fscache_n_stores_nobufs;
59735+atomic_unchecked_t fscache_n_stores_oom;
59736+atomic_unchecked_t fscache_n_store_ops;
59737+atomic_unchecked_t fscache_n_store_calls;
59738+atomic_unchecked_t fscache_n_store_pages;
59739+atomic_unchecked_t fscache_n_store_radix_deletes;
59740+atomic_unchecked_t fscache_n_store_pages_over_limit;
59741
59742-atomic_t fscache_n_store_vmscan_not_storing;
59743-atomic_t fscache_n_store_vmscan_gone;
59744-atomic_t fscache_n_store_vmscan_busy;
59745-atomic_t fscache_n_store_vmscan_cancelled;
59746-atomic_t fscache_n_store_vmscan_wait;
59747+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
59748+atomic_unchecked_t fscache_n_store_vmscan_gone;
59749+atomic_unchecked_t fscache_n_store_vmscan_busy;
59750+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
59751+atomic_unchecked_t fscache_n_store_vmscan_wait;
59752
59753-atomic_t fscache_n_marks;
59754-atomic_t fscache_n_uncaches;
59755+atomic_unchecked_t fscache_n_marks;
59756+atomic_unchecked_t fscache_n_uncaches;
59757
59758-atomic_t fscache_n_acquires;
59759-atomic_t fscache_n_acquires_null;
59760-atomic_t fscache_n_acquires_no_cache;
59761-atomic_t fscache_n_acquires_ok;
59762-atomic_t fscache_n_acquires_nobufs;
59763-atomic_t fscache_n_acquires_oom;
59764+atomic_unchecked_t fscache_n_acquires;
59765+atomic_unchecked_t fscache_n_acquires_null;
59766+atomic_unchecked_t fscache_n_acquires_no_cache;
59767+atomic_unchecked_t fscache_n_acquires_ok;
59768+atomic_unchecked_t fscache_n_acquires_nobufs;
59769+atomic_unchecked_t fscache_n_acquires_oom;
59770
59771-atomic_t fscache_n_invalidates;
59772-atomic_t fscache_n_invalidates_run;
59773+atomic_unchecked_t fscache_n_invalidates;
59774+atomic_unchecked_t fscache_n_invalidates_run;
59775
59776-atomic_t fscache_n_updates;
59777-atomic_t fscache_n_updates_null;
59778-atomic_t fscache_n_updates_run;
59779+atomic_unchecked_t fscache_n_updates;
59780+atomic_unchecked_t fscache_n_updates_null;
59781+atomic_unchecked_t fscache_n_updates_run;
59782
59783-atomic_t fscache_n_relinquishes;
59784-atomic_t fscache_n_relinquishes_null;
59785-atomic_t fscache_n_relinquishes_waitcrt;
59786-atomic_t fscache_n_relinquishes_retire;
59787+atomic_unchecked_t fscache_n_relinquishes;
59788+atomic_unchecked_t fscache_n_relinquishes_null;
59789+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
59790+atomic_unchecked_t fscache_n_relinquishes_retire;
59791
59792-atomic_t fscache_n_cookie_index;
59793-atomic_t fscache_n_cookie_data;
59794-atomic_t fscache_n_cookie_special;
59795+atomic_unchecked_t fscache_n_cookie_index;
59796+atomic_unchecked_t fscache_n_cookie_data;
59797+atomic_unchecked_t fscache_n_cookie_special;
59798
59799-atomic_t fscache_n_object_alloc;
59800-atomic_t fscache_n_object_no_alloc;
59801-atomic_t fscache_n_object_lookups;
59802-atomic_t fscache_n_object_lookups_negative;
59803-atomic_t fscache_n_object_lookups_positive;
59804-atomic_t fscache_n_object_lookups_timed_out;
59805-atomic_t fscache_n_object_created;
59806-atomic_t fscache_n_object_avail;
59807-atomic_t fscache_n_object_dead;
59808+atomic_unchecked_t fscache_n_object_alloc;
59809+atomic_unchecked_t fscache_n_object_no_alloc;
59810+atomic_unchecked_t fscache_n_object_lookups;
59811+atomic_unchecked_t fscache_n_object_lookups_negative;
59812+atomic_unchecked_t fscache_n_object_lookups_positive;
59813+atomic_unchecked_t fscache_n_object_lookups_timed_out;
59814+atomic_unchecked_t fscache_n_object_created;
59815+atomic_unchecked_t fscache_n_object_avail;
59816+atomic_unchecked_t fscache_n_object_dead;
59817
59818-atomic_t fscache_n_checkaux_none;
59819-atomic_t fscache_n_checkaux_okay;
59820-atomic_t fscache_n_checkaux_update;
59821-atomic_t fscache_n_checkaux_obsolete;
59822+atomic_unchecked_t fscache_n_checkaux_none;
59823+atomic_unchecked_t fscache_n_checkaux_okay;
59824+atomic_unchecked_t fscache_n_checkaux_update;
59825+atomic_unchecked_t fscache_n_checkaux_obsolete;
59826
59827 atomic_t fscache_n_cop_alloc_object;
59828 atomic_t fscache_n_cop_lookup_object;
59829@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
59830 seq_puts(m, "FS-Cache statistics\n");
59831
59832 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
59833- atomic_read(&fscache_n_cookie_index),
59834- atomic_read(&fscache_n_cookie_data),
59835- atomic_read(&fscache_n_cookie_special));
59836+ atomic_read_unchecked(&fscache_n_cookie_index),
59837+ atomic_read_unchecked(&fscache_n_cookie_data),
59838+ atomic_read_unchecked(&fscache_n_cookie_special));
59839
59840 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
59841- atomic_read(&fscache_n_object_alloc),
59842- atomic_read(&fscache_n_object_no_alloc),
59843- atomic_read(&fscache_n_object_avail),
59844- atomic_read(&fscache_n_object_dead));
59845+ atomic_read_unchecked(&fscache_n_object_alloc),
59846+ atomic_read_unchecked(&fscache_n_object_no_alloc),
59847+ atomic_read_unchecked(&fscache_n_object_avail),
59848+ atomic_read_unchecked(&fscache_n_object_dead));
59849 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
59850- atomic_read(&fscache_n_checkaux_none),
59851- atomic_read(&fscache_n_checkaux_okay),
59852- atomic_read(&fscache_n_checkaux_update),
59853- atomic_read(&fscache_n_checkaux_obsolete));
59854+ atomic_read_unchecked(&fscache_n_checkaux_none),
59855+ atomic_read_unchecked(&fscache_n_checkaux_okay),
59856+ atomic_read_unchecked(&fscache_n_checkaux_update),
59857+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
59858
59859 seq_printf(m, "Pages : mrk=%u unc=%u\n",
59860- atomic_read(&fscache_n_marks),
59861- atomic_read(&fscache_n_uncaches));
59862+ atomic_read_unchecked(&fscache_n_marks),
59863+ atomic_read_unchecked(&fscache_n_uncaches));
59864
59865 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
59866 " oom=%u\n",
59867- atomic_read(&fscache_n_acquires),
59868- atomic_read(&fscache_n_acquires_null),
59869- atomic_read(&fscache_n_acquires_no_cache),
59870- atomic_read(&fscache_n_acquires_ok),
59871- atomic_read(&fscache_n_acquires_nobufs),
59872- atomic_read(&fscache_n_acquires_oom));
59873+ atomic_read_unchecked(&fscache_n_acquires),
59874+ atomic_read_unchecked(&fscache_n_acquires_null),
59875+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
59876+ atomic_read_unchecked(&fscache_n_acquires_ok),
59877+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
59878+ atomic_read_unchecked(&fscache_n_acquires_oom));
59879
59880 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
59881- atomic_read(&fscache_n_object_lookups),
59882- atomic_read(&fscache_n_object_lookups_negative),
59883- atomic_read(&fscache_n_object_lookups_positive),
59884- atomic_read(&fscache_n_object_created),
59885- atomic_read(&fscache_n_object_lookups_timed_out));
59886+ atomic_read_unchecked(&fscache_n_object_lookups),
59887+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
59888+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
59889+ atomic_read_unchecked(&fscache_n_object_created),
59890+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
59891
59892 seq_printf(m, "Invals : n=%u run=%u\n",
59893- atomic_read(&fscache_n_invalidates),
59894- atomic_read(&fscache_n_invalidates_run));
59895+ atomic_read_unchecked(&fscache_n_invalidates),
59896+ atomic_read_unchecked(&fscache_n_invalidates_run));
59897
59898 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
59899- atomic_read(&fscache_n_updates),
59900- atomic_read(&fscache_n_updates_null),
59901- atomic_read(&fscache_n_updates_run));
59902+ atomic_read_unchecked(&fscache_n_updates),
59903+ atomic_read_unchecked(&fscache_n_updates_null),
59904+ atomic_read_unchecked(&fscache_n_updates_run));
59905
59906 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
59907- atomic_read(&fscache_n_relinquishes),
59908- atomic_read(&fscache_n_relinquishes_null),
59909- atomic_read(&fscache_n_relinquishes_waitcrt),
59910- atomic_read(&fscache_n_relinquishes_retire));
59911+ atomic_read_unchecked(&fscache_n_relinquishes),
59912+ atomic_read_unchecked(&fscache_n_relinquishes_null),
59913+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
59914+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
59915
59916 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
59917- atomic_read(&fscache_n_attr_changed),
59918- atomic_read(&fscache_n_attr_changed_ok),
59919- atomic_read(&fscache_n_attr_changed_nobufs),
59920- atomic_read(&fscache_n_attr_changed_nomem),
59921- atomic_read(&fscache_n_attr_changed_calls));
59922+ atomic_read_unchecked(&fscache_n_attr_changed),
59923+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
59924+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
59925+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
59926+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
59927
59928 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
59929- atomic_read(&fscache_n_allocs),
59930- atomic_read(&fscache_n_allocs_ok),
59931- atomic_read(&fscache_n_allocs_wait),
59932- atomic_read(&fscache_n_allocs_nobufs),
59933- atomic_read(&fscache_n_allocs_intr));
59934+ atomic_read_unchecked(&fscache_n_allocs),
59935+ atomic_read_unchecked(&fscache_n_allocs_ok),
59936+ atomic_read_unchecked(&fscache_n_allocs_wait),
59937+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
59938+ atomic_read_unchecked(&fscache_n_allocs_intr));
59939 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
59940- atomic_read(&fscache_n_alloc_ops),
59941- atomic_read(&fscache_n_alloc_op_waits),
59942- atomic_read(&fscache_n_allocs_object_dead));
59943+ atomic_read_unchecked(&fscache_n_alloc_ops),
59944+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
59945+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
59946
59947 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
59948 " int=%u oom=%u\n",
59949- atomic_read(&fscache_n_retrievals),
59950- atomic_read(&fscache_n_retrievals_ok),
59951- atomic_read(&fscache_n_retrievals_wait),
59952- atomic_read(&fscache_n_retrievals_nodata),
59953- atomic_read(&fscache_n_retrievals_nobufs),
59954- atomic_read(&fscache_n_retrievals_intr),
59955- atomic_read(&fscache_n_retrievals_nomem));
59956+ atomic_read_unchecked(&fscache_n_retrievals),
59957+ atomic_read_unchecked(&fscache_n_retrievals_ok),
59958+ atomic_read_unchecked(&fscache_n_retrievals_wait),
59959+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
59960+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
59961+ atomic_read_unchecked(&fscache_n_retrievals_intr),
59962+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
59963 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
59964- atomic_read(&fscache_n_retrieval_ops),
59965- atomic_read(&fscache_n_retrieval_op_waits),
59966- atomic_read(&fscache_n_retrievals_object_dead));
59967+ atomic_read_unchecked(&fscache_n_retrieval_ops),
59968+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
59969+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
59970
59971 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
59972- atomic_read(&fscache_n_stores),
59973- atomic_read(&fscache_n_stores_ok),
59974- atomic_read(&fscache_n_stores_again),
59975- atomic_read(&fscache_n_stores_nobufs),
59976- atomic_read(&fscache_n_stores_oom));
59977+ atomic_read_unchecked(&fscache_n_stores),
59978+ atomic_read_unchecked(&fscache_n_stores_ok),
59979+ atomic_read_unchecked(&fscache_n_stores_again),
59980+ atomic_read_unchecked(&fscache_n_stores_nobufs),
59981+ atomic_read_unchecked(&fscache_n_stores_oom));
59982 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
59983- atomic_read(&fscache_n_store_ops),
59984- atomic_read(&fscache_n_store_calls),
59985- atomic_read(&fscache_n_store_pages),
59986- atomic_read(&fscache_n_store_radix_deletes),
59987- atomic_read(&fscache_n_store_pages_over_limit));
59988+ atomic_read_unchecked(&fscache_n_store_ops),
59989+ atomic_read_unchecked(&fscache_n_store_calls),
59990+ atomic_read_unchecked(&fscache_n_store_pages),
59991+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
59992+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
59993
59994 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
59995- atomic_read(&fscache_n_store_vmscan_not_storing),
59996- atomic_read(&fscache_n_store_vmscan_gone),
59997- atomic_read(&fscache_n_store_vmscan_busy),
59998- atomic_read(&fscache_n_store_vmscan_cancelled),
59999- atomic_read(&fscache_n_store_vmscan_wait));
60000+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
60001+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
60002+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
60003+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
60004+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
60005
60006 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
60007- atomic_read(&fscache_n_op_pend),
60008- atomic_read(&fscache_n_op_run),
60009- atomic_read(&fscache_n_op_enqueue),
60010- atomic_read(&fscache_n_op_cancelled),
60011- atomic_read(&fscache_n_op_rejected));
60012+ atomic_read_unchecked(&fscache_n_op_pend),
60013+ atomic_read_unchecked(&fscache_n_op_run),
60014+ atomic_read_unchecked(&fscache_n_op_enqueue),
60015+ atomic_read_unchecked(&fscache_n_op_cancelled),
60016+ atomic_read_unchecked(&fscache_n_op_rejected));
60017 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
60018- atomic_read(&fscache_n_op_deferred_release),
60019- atomic_read(&fscache_n_op_release),
60020- atomic_read(&fscache_n_op_gc));
60021+ atomic_read_unchecked(&fscache_n_op_deferred_release),
60022+ atomic_read_unchecked(&fscache_n_op_release),
60023+ atomic_read_unchecked(&fscache_n_op_gc));
60024
60025 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
60026 atomic_read(&fscache_n_cop_alloc_object),
60027diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
60028index b96a49b..9bfdc47 100644
60029--- a/fs/fuse/cuse.c
60030+++ b/fs/fuse/cuse.c
60031@@ -606,10 +606,12 @@ static int __init cuse_init(void)
60032 INIT_LIST_HEAD(&cuse_conntbl[i]);
60033
60034 /* inherit and extend fuse_dev_operations */
60035- cuse_channel_fops = fuse_dev_operations;
60036- cuse_channel_fops.owner = THIS_MODULE;
60037- cuse_channel_fops.open = cuse_channel_open;
60038- cuse_channel_fops.release = cuse_channel_release;
60039+ pax_open_kernel();
60040+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
60041+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
60042+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
60043+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
60044+ pax_close_kernel();
60045
60046 cuse_class = class_create(THIS_MODULE, "cuse");
60047 if (IS_ERR(cuse_class))
60048diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
60049index ef74ad5..c9ac759e 100644
60050--- a/fs/fuse/dev.c
60051+++ b/fs/fuse/dev.c
60052@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
60053 ret = 0;
60054 pipe_lock(pipe);
60055
60056- if (!pipe->readers) {
60057+ if (!atomic_read(&pipe->readers)) {
60058 send_sig(SIGPIPE, current, 0);
60059 if (!ret)
60060 ret = -EPIPE;
60061@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
60062 page_nr++;
60063 ret += buf->len;
60064
60065- if (pipe->files)
60066+ if (atomic_read(&pipe->files))
60067 do_wakeup = 1;
60068 }
60069
60070diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
60071index c3eb2c4..98007d4 100644
60072--- a/fs/fuse/dir.c
60073+++ b/fs/fuse/dir.c
60074@@ -1408,7 +1408,7 @@ static char *read_link(struct dentry *dentry)
60075 return link;
60076 }
60077
60078-static void free_link(char *link)
60079+static void free_link(const char *link)
60080 {
60081 if (!IS_ERR(link))
60082 free_page((unsigned long) link);
60083diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
60084index db23ce1..9e6cd9d 100644
60085--- a/fs/hostfs/hostfs_kern.c
60086+++ b/fs/hostfs/hostfs_kern.c
60087@@ -895,7 +895,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
60088
60089 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
60090 {
60091- char *s = nd_get_link(nd);
60092+ const char *s = nd_get_link(nd);
60093 if (!IS_ERR(s))
60094 __putname(s);
60095 }
60096diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
60097index d19b30a..ef89c36 100644
60098--- a/fs/hugetlbfs/inode.c
60099+++ b/fs/hugetlbfs/inode.c
60100@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
60101 struct mm_struct *mm = current->mm;
60102 struct vm_area_struct *vma;
60103 struct hstate *h = hstate_file(file);
60104+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
60105 struct vm_unmapped_area_info info;
60106
60107 if (len & ~huge_page_mask(h))
60108@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
60109 return addr;
60110 }
60111
60112+#ifdef CONFIG_PAX_RANDMMAP
60113+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
60114+#endif
60115+
60116 if (addr) {
60117 addr = ALIGN(addr, huge_page_size(h));
60118 vma = find_vma(mm, addr);
60119- if (TASK_SIZE - len >= addr &&
60120- (!vma || addr + len <= vma->vm_start))
60121+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
60122 return addr;
60123 }
60124
60125 info.flags = 0;
60126 info.length = len;
60127 info.low_limit = TASK_UNMAPPED_BASE;
60128+
60129+#ifdef CONFIG_PAX_RANDMMAP
60130+ if (mm->pax_flags & MF_PAX_RANDMMAP)
60131+ info.low_limit += mm->delta_mmap;
60132+#endif
60133+
60134 info.high_limit = TASK_SIZE;
60135 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
60136 info.align_offset = 0;
60137@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
60138 };
60139 MODULE_ALIAS_FS("hugetlbfs");
60140
60141-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
60142+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
60143
60144 static int can_do_hugetlb_shm(void)
60145 {
60146diff --git a/fs/inode.c b/fs/inode.c
60147index 4bcdad3..1883822 100644
60148--- a/fs/inode.c
60149+++ b/fs/inode.c
60150@@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
60151
60152 #ifdef CONFIG_SMP
60153 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
60154- static atomic_t shared_last_ino;
60155- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
60156+ static atomic_unchecked_t shared_last_ino;
60157+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
60158
60159 res = next - LAST_INO_BATCH;
60160 }
60161diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
60162index 4a6cf28..d3a29d3 100644
60163--- a/fs/jffs2/erase.c
60164+++ b/fs/jffs2/erase.c
60165@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
60166 struct jffs2_unknown_node marker = {
60167 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
60168 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
60169- .totlen = cpu_to_je32(c->cleanmarker_size)
60170+ .totlen = cpu_to_je32(c->cleanmarker_size),
60171+ .hdr_crc = cpu_to_je32(0)
60172 };
60173
60174 jffs2_prealloc_raw_node_refs(c, jeb, 1);
60175diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
60176index a6597d6..41b30ec 100644
60177--- a/fs/jffs2/wbuf.c
60178+++ b/fs/jffs2/wbuf.c
60179@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
60180 {
60181 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
60182 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
60183- .totlen = constant_cpu_to_je32(8)
60184+ .totlen = constant_cpu_to_je32(8),
60185+ .hdr_crc = constant_cpu_to_je32(0)
60186 };
60187
60188 /*
60189diff --git a/fs/jfs/super.c b/fs/jfs/super.c
60190index 6669aa2..36b033d 100644
60191--- a/fs/jfs/super.c
60192+++ b/fs/jfs/super.c
60193@@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
60194
60195 jfs_inode_cachep =
60196 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
60197- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
60198+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
60199 init_once);
60200 if (jfs_inode_cachep == NULL)
60201 return -ENOMEM;
60202diff --git a/fs/libfs.c b/fs/libfs.c
60203index a184424..944ddce 100644
60204--- a/fs/libfs.c
60205+++ b/fs/libfs.c
60206@@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
60207
60208 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
60209 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
60210+ char d_name[sizeof(next->d_iname)];
60211+ const unsigned char *name;
60212+
60213 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
60214 if (!simple_positive(next)) {
60215 spin_unlock(&next->d_lock);
60216@@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
60217
60218 spin_unlock(&next->d_lock);
60219 spin_unlock(&dentry->d_lock);
60220- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
60221+ name = next->d_name.name;
60222+ if (name == next->d_iname) {
60223+ memcpy(d_name, name, next->d_name.len);
60224+ name = d_name;
60225+ }
60226+ if (!dir_emit(ctx, name, next->d_name.len,
60227 next->d_inode->i_ino, dt_type(next->d_inode)))
60228 return 0;
60229 spin_lock(&dentry->d_lock);
60230@@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
60231 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
60232 void *cookie)
60233 {
60234- char *s = nd_get_link(nd);
60235+ const char *s = nd_get_link(nd);
60236 if (!IS_ERR(s))
60237 kfree(s);
60238 }
60239diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
60240index acd3947..1f896e2 100644
60241--- a/fs/lockd/clntproc.c
60242+++ b/fs/lockd/clntproc.c
60243@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
60244 /*
60245 * Cookie counter for NLM requests
60246 */
60247-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
60248+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
60249
60250 void nlmclnt_next_cookie(struct nlm_cookie *c)
60251 {
60252- u32 cookie = atomic_inc_return(&nlm_cookie);
60253+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
60254
60255 memcpy(c->data, &cookie, 4);
60256 c->len=4;
60257diff --git a/fs/locks.c b/fs/locks.c
60258index 92a0f0a..45a48f0 100644
60259--- a/fs/locks.c
60260+++ b/fs/locks.c
60261@@ -2219,16 +2219,16 @@ void locks_remove_flock(struct file *filp)
60262 return;
60263
60264 if (filp->f_op->flock) {
60265- struct file_lock fl = {
60266+ struct file_lock flock = {
60267 .fl_pid = current->tgid,
60268 .fl_file = filp,
60269 .fl_flags = FL_FLOCK,
60270 .fl_type = F_UNLCK,
60271 .fl_end = OFFSET_MAX,
60272 };
60273- filp->f_op->flock(filp, F_SETLKW, &fl);
60274- if (fl.fl_ops && fl.fl_ops->fl_release_private)
60275- fl.fl_ops->fl_release_private(&fl);
60276+ filp->f_op->flock(filp, F_SETLKW, &flock);
60277+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
60278+ flock.fl_ops->fl_release_private(&flock);
60279 }
60280
60281 spin_lock(&inode->i_lock);
60282diff --git a/fs/mount.h b/fs/mount.h
60283index a17458c..e69fb5b 100644
60284--- a/fs/mount.h
60285+++ b/fs/mount.h
60286@@ -11,7 +11,7 @@ struct mnt_namespace {
60287 u64 seq; /* Sequence number to prevent loops */
60288 wait_queue_head_t poll;
60289 int event;
60290-};
60291+} __randomize_layout;
60292
60293 struct mnt_pcp {
60294 int mnt_count;
60295@@ -57,7 +57,7 @@ struct mount {
60296 int mnt_expiry_mark; /* true if marked for expiry */
60297 int mnt_pinned;
60298 struct path mnt_ex_mountpoint;
60299-};
60300+} __randomize_layout;
60301
60302 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
60303
60304diff --git a/fs/namei.c b/fs/namei.c
60305index 3531dee..3177227 100644
60306--- a/fs/namei.c
60307+++ b/fs/namei.c
60308@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
60309 if (ret != -EACCES)
60310 return ret;
60311
60312+#ifdef CONFIG_GRKERNSEC
60313+ /* we'll block if we have to log due to a denied capability use */
60314+ if (mask & MAY_NOT_BLOCK)
60315+ return -ECHILD;
60316+#endif
60317+
60318 if (S_ISDIR(inode->i_mode)) {
60319 /* DACs are overridable for directories */
60320- if (inode_capable(inode, CAP_DAC_OVERRIDE))
60321- return 0;
60322 if (!(mask & MAY_WRITE))
60323- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
60324+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
60325+ inode_capable(inode, CAP_DAC_READ_SEARCH))
60326 return 0;
60327+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
60328+ return 0;
60329 return -EACCES;
60330 }
60331 /*
60332+ * Searching includes executable on directories, else just read.
60333+ */
60334+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
60335+ if (mask == MAY_READ)
60336+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
60337+ inode_capable(inode, CAP_DAC_READ_SEARCH))
60338+ return 0;
60339+
60340+ /*
60341 * Read/write DACs are always overridable.
60342 * Executable DACs are overridable when there is
60343 * at least one exec bit set.
60344@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
60345 if (inode_capable(inode, CAP_DAC_OVERRIDE))
60346 return 0;
60347
60348- /*
60349- * Searching includes executable on directories, else just read.
60350- */
60351- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
60352- if (mask == MAY_READ)
60353- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
60354- return 0;
60355-
60356 return -EACCES;
60357 }
60358
60359@@ -810,7 +818,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
60360 {
60361 struct dentry *dentry = link->dentry;
60362 int error;
60363- char *s;
60364+ const char *s;
60365
60366 BUG_ON(nd->flags & LOOKUP_RCU);
60367
60368@@ -831,6 +839,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
60369 if (error)
60370 goto out_put_nd_path;
60371
60372+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
60373+ dentry->d_inode, dentry, nd->path.mnt)) {
60374+ error = -EACCES;
60375+ goto out_put_nd_path;
60376+ }
60377+
60378 nd->last_type = LAST_BIND;
60379 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
60380 error = PTR_ERR(*p);
60381@@ -1582,6 +1596,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
60382 if (res)
60383 break;
60384 res = walk_component(nd, path, LOOKUP_FOLLOW);
60385+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
60386+ res = -EACCES;
60387 put_link(nd, &link, cookie);
60388 } while (res > 0);
60389
60390@@ -1655,7 +1671,7 @@ EXPORT_SYMBOL(full_name_hash);
60391 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
60392 {
60393 unsigned long a, b, adata, bdata, mask, hash, len;
60394- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
60395+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
60396
60397 hash = a = 0;
60398 len = -sizeof(unsigned long);
60399@@ -1939,6 +1955,8 @@ static int path_lookupat(int dfd, const char *name,
60400 if (err)
60401 break;
60402 err = lookup_last(nd, &path);
60403+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
60404+ err = -EACCES;
60405 put_link(nd, &link, cookie);
60406 }
60407 }
60408@@ -1946,6 +1964,13 @@ static int path_lookupat(int dfd, const char *name,
60409 if (!err)
60410 err = complete_walk(nd);
60411
60412+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
60413+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
60414+ path_put(&nd->path);
60415+ err = -ENOENT;
60416+ }
60417+ }
60418+
60419 if (!err && nd->flags & LOOKUP_DIRECTORY) {
60420 if (!d_is_directory(nd->path.dentry)) {
60421 path_put(&nd->path);
60422@@ -1973,8 +1998,15 @@ static int filename_lookup(int dfd, struct filename *name,
60423 retval = path_lookupat(dfd, name->name,
60424 flags | LOOKUP_REVAL, nd);
60425
60426- if (likely(!retval))
60427+ if (likely(!retval)) {
60428 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
60429+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
60430+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
60431+ path_put(&nd->path);
60432+ return -ENOENT;
60433+ }
60434+ }
60435+ }
60436 return retval;
60437 }
60438
60439@@ -2548,6 +2580,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
60440 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
60441 return -EPERM;
60442
60443+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
60444+ return -EPERM;
60445+ if (gr_handle_rawio(inode))
60446+ return -EPERM;
60447+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
60448+ return -EACCES;
60449+
60450 return 0;
60451 }
60452
60453@@ -2779,7 +2818,7 @@ looked_up:
60454 * cleared otherwise prior to returning.
60455 */
60456 static int lookup_open(struct nameidata *nd, struct path *path,
60457- struct file *file,
60458+ struct path *link, struct file *file,
60459 const struct open_flags *op,
60460 bool got_write, int *opened)
60461 {
60462@@ -2814,6 +2853,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
60463 /* Negative dentry, just create the file */
60464 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
60465 umode_t mode = op->mode;
60466+
60467+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
60468+ error = -EACCES;
60469+ goto out_dput;
60470+ }
60471+
60472+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
60473+ error = -EACCES;
60474+ goto out_dput;
60475+ }
60476+
60477 if (!IS_POSIXACL(dir->d_inode))
60478 mode &= ~current_umask();
60479 /*
60480@@ -2835,6 +2885,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
60481 nd->flags & LOOKUP_EXCL);
60482 if (error)
60483 goto out_dput;
60484+ else
60485+ gr_handle_create(dentry, nd->path.mnt);
60486 }
60487 out_no_open:
60488 path->dentry = dentry;
60489@@ -2849,7 +2901,7 @@ out_dput:
60490 /*
60491 * Handle the last step of open()
60492 */
60493-static int do_last(struct nameidata *nd, struct path *path,
60494+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
60495 struct file *file, const struct open_flags *op,
60496 int *opened, struct filename *name)
60497 {
60498@@ -2899,6 +2951,15 @@ static int do_last(struct nameidata *nd, struct path *path,
60499 if (error)
60500 return error;
60501
60502+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
60503+ error = -ENOENT;
60504+ goto out;
60505+ }
60506+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
60507+ error = -EACCES;
60508+ goto out;
60509+ }
60510+
60511 audit_inode(name, dir, LOOKUP_PARENT);
60512 error = -EISDIR;
60513 /* trailing slashes? */
60514@@ -2918,7 +2979,7 @@ retry_lookup:
60515 */
60516 }
60517 mutex_lock(&dir->d_inode->i_mutex);
60518- error = lookup_open(nd, path, file, op, got_write, opened);
60519+ error = lookup_open(nd, path, link, file, op, got_write, opened);
60520 mutex_unlock(&dir->d_inode->i_mutex);
60521
60522 if (error <= 0) {
60523@@ -2942,11 +3003,28 @@ retry_lookup:
60524 goto finish_open_created;
60525 }
60526
60527+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
60528+ error = -ENOENT;
60529+ goto exit_dput;
60530+ }
60531+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
60532+ error = -EACCES;
60533+ goto exit_dput;
60534+ }
60535+
60536 /*
60537 * create/update audit record if it already exists.
60538 */
60539- if (d_is_positive(path->dentry))
60540+ if (d_is_positive(path->dentry)) {
60541+ /* only check if O_CREAT is specified, all other checks need to go
60542+ into may_open */
60543+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
60544+ error = -EACCES;
60545+ goto exit_dput;
60546+ }
60547+
60548 audit_inode(name, path->dentry, 0);
60549+ }
60550
60551 /*
60552 * If atomic_open() acquired write access it is dropped now due to
60553@@ -2987,6 +3065,11 @@ finish_lookup:
60554 }
60555 }
60556 BUG_ON(inode != path->dentry->d_inode);
60557+ /* if we're resolving a symlink to another symlink */
60558+ if (link && gr_handle_symlink_owner(link, inode)) {
60559+ error = -EACCES;
60560+ goto out;
60561+ }
60562 return 1;
60563 }
60564
60565@@ -2996,7 +3079,6 @@ finish_lookup:
60566 save_parent.dentry = nd->path.dentry;
60567 save_parent.mnt = mntget(path->mnt);
60568 nd->path.dentry = path->dentry;
60569-
60570 }
60571 nd->inode = inode;
60572 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
60573@@ -3006,7 +3088,18 @@ finish_open:
60574 path_put(&save_parent);
60575 return error;
60576 }
60577+
60578+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
60579+ error = -ENOENT;
60580+ goto out;
60581+ }
60582+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
60583+ error = -EACCES;
60584+ goto out;
60585+ }
60586+
60587 audit_inode(name, nd->path.dentry, 0);
60588+
60589 error = -EISDIR;
60590 if ((open_flag & O_CREAT) &&
60591 (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
60592@@ -3170,7 +3263,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
60593 if (unlikely(error))
60594 goto out;
60595
60596- error = do_last(nd, &path, file, op, &opened, pathname);
60597+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
60598 while (unlikely(error > 0)) { /* trailing symlink */
60599 struct path link = path;
60600 void *cookie;
60601@@ -3188,7 +3281,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
60602 error = follow_link(&link, nd, &cookie);
60603 if (unlikely(error))
60604 break;
60605- error = do_last(nd, &path, file, op, &opened, pathname);
60606+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
60607 put_link(nd, &link, cookie);
60608 }
60609 out:
60610@@ -3288,9 +3381,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
60611 goto unlock;
60612
60613 error = -EEXIST;
60614- if (d_is_positive(dentry))
60615+ if (d_is_positive(dentry)) {
60616+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
60617+ error = -ENOENT;
60618 goto fail;
60619-
60620+ }
60621 /*
60622 * Special case - lookup gave negative, but... we had foo/bar/
60623 * From the vfs_mknod() POV we just have a negative dentry -
60624@@ -3342,6 +3437,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
60625 }
60626 EXPORT_SYMBOL(user_path_create);
60627
60628+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
60629+{
60630+ struct filename *tmp = getname(pathname);
60631+ struct dentry *res;
60632+ if (IS_ERR(tmp))
60633+ return ERR_CAST(tmp);
60634+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
60635+ if (IS_ERR(res))
60636+ putname(tmp);
60637+ else
60638+ *to = tmp;
60639+ return res;
60640+}
60641+
60642 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
60643 {
60644 int error = may_create(dir, dentry);
60645@@ -3404,6 +3513,17 @@ retry:
60646
60647 if (!IS_POSIXACL(path.dentry->d_inode))
60648 mode &= ~current_umask();
60649+
60650+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
60651+ error = -EPERM;
60652+ goto out;
60653+ }
60654+
60655+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
60656+ error = -EACCES;
60657+ goto out;
60658+ }
60659+
60660 error = security_path_mknod(&path, dentry, mode, dev);
60661 if (error)
60662 goto out;
60663@@ -3420,6 +3540,8 @@ retry:
60664 break;
60665 }
60666 out:
60667+ if (!error)
60668+ gr_handle_create(dentry, path.mnt);
60669 done_path_create(&path, dentry);
60670 if (retry_estale(error, lookup_flags)) {
60671 lookup_flags |= LOOKUP_REVAL;
60672@@ -3472,9 +3594,16 @@ retry:
60673
60674 if (!IS_POSIXACL(path.dentry->d_inode))
60675 mode &= ~current_umask();
60676+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
60677+ error = -EACCES;
60678+ goto out;
60679+ }
60680 error = security_path_mkdir(&path, dentry, mode);
60681 if (!error)
60682 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
60683+ if (!error)
60684+ gr_handle_create(dentry, path.mnt);
60685+out:
60686 done_path_create(&path, dentry);
60687 if (retry_estale(error, lookup_flags)) {
60688 lookup_flags |= LOOKUP_REVAL;
60689@@ -3555,6 +3684,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
60690 struct filename *name;
60691 struct dentry *dentry;
60692 struct nameidata nd;
60693+ ino_t saved_ino = 0;
60694+ dev_t saved_dev = 0;
60695 unsigned int lookup_flags = 0;
60696 retry:
60697 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
60698@@ -3587,10 +3718,21 @@ retry:
60699 error = -ENOENT;
60700 goto exit3;
60701 }
60702+
60703+ saved_ino = dentry->d_inode->i_ino;
60704+ saved_dev = gr_get_dev_from_dentry(dentry);
60705+
60706+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
60707+ error = -EACCES;
60708+ goto exit3;
60709+ }
60710+
60711 error = security_path_rmdir(&nd.path, dentry);
60712 if (error)
60713 goto exit3;
60714 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
60715+ if (!error && (saved_dev || saved_ino))
60716+ gr_handle_delete(saved_ino, saved_dev);
60717 exit3:
60718 dput(dentry);
60719 exit2:
60720@@ -3680,6 +3822,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
60721 struct nameidata nd;
60722 struct inode *inode = NULL;
60723 struct inode *delegated_inode = NULL;
60724+ ino_t saved_ino = 0;
60725+ dev_t saved_dev = 0;
60726 unsigned int lookup_flags = 0;
60727 retry:
60728 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
60729@@ -3706,10 +3850,22 @@ retry_deleg:
60730 if (d_is_negative(dentry))
60731 goto slashes;
60732 ihold(inode);
60733+
60734+ if (inode->i_nlink <= 1) {
60735+ saved_ino = inode->i_ino;
60736+ saved_dev = gr_get_dev_from_dentry(dentry);
60737+ }
60738+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
60739+ error = -EACCES;
60740+ goto exit2;
60741+ }
60742+
60743 error = security_path_unlink(&nd.path, dentry);
60744 if (error)
60745 goto exit2;
60746 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
60747+ if (!error && (saved_ino || saved_dev))
60748+ gr_handle_delete(saved_ino, saved_dev);
60749 exit2:
60750 dput(dentry);
60751 }
60752@@ -3797,9 +3953,17 @@ retry:
60753 if (IS_ERR(dentry))
60754 goto out_putname;
60755
60756+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
60757+ error = -EACCES;
60758+ goto out;
60759+ }
60760+
60761 error = security_path_symlink(&path, dentry, from->name);
60762 if (!error)
60763 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
60764+ if (!error)
60765+ gr_handle_create(dentry, path.mnt);
60766+out:
60767 done_path_create(&path, dentry);
60768 if (retry_estale(error, lookup_flags)) {
60769 lookup_flags |= LOOKUP_REVAL;
60770@@ -3902,6 +4066,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
60771 struct dentry *new_dentry;
60772 struct path old_path, new_path;
60773 struct inode *delegated_inode = NULL;
60774+ struct filename *to = NULL;
60775 int how = 0;
60776 int error;
60777
60778@@ -3925,7 +4090,7 @@ retry:
60779 if (error)
60780 return error;
60781
60782- new_dentry = user_path_create(newdfd, newname, &new_path,
60783+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
60784 (how & LOOKUP_REVAL));
60785 error = PTR_ERR(new_dentry);
60786 if (IS_ERR(new_dentry))
60787@@ -3937,11 +4102,28 @@ retry:
60788 error = may_linkat(&old_path);
60789 if (unlikely(error))
60790 goto out_dput;
60791+
60792+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
60793+ old_path.dentry->d_inode,
60794+ old_path.dentry->d_inode->i_mode, to)) {
60795+ error = -EACCES;
60796+ goto out_dput;
60797+ }
60798+
60799+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
60800+ old_path.dentry, old_path.mnt, to)) {
60801+ error = -EACCES;
60802+ goto out_dput;
60803+ }
60804+
60805 error = security_path_link(old_path.dentry, &new_path, new_dentry);
60806 if (error)
60807 goto out_dput;
60808 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
60809+ if (!error)
60810+ gr_handle_create(new_dentry, new_path.mnt);
60811 out_dput:
60812+ putname(to);
60813 done_path_create(&new_path, new_dentry);
60814 if (delegated_inode) {
60815 error = break_deleg_wait(&delegated_inode);
60816@@ -4225,6 +4407,12 @@ retry_deleg:
60817 if (new_dentry == trap)
60818 goto exit5;
60819
60820+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
60821+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
60822+ to);
60823+ if (error)
60824+ goto exit5;
60825+
60826 error = security_path_rename(&oldnd.path, old_dentry,
60827 &newnd.path, new_dentry);
60828 if (error)
60829@@ -4232,6 +4420,9 @@ retry_deleg:
60830 error = vfs_rename(old_dir->d_inode, old_dentry,
60831 new_dir->d_inode, new_dentry,
60832 &delegated_inode);
60833+ if (!error)
60834+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
60835+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
60836 exit5:
60837 dput(new_dentry);
60838 exit4:
60839@@ -4268,6 +4459,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
60840
60841 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
60842 {
60843+ char tmpbuf[64];
60844+ const char *newlink;
60845 int len;
60846
60847 len = PTR_ERR(link);
60848@@ -4277,7 +4470,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
60849 len = strlen(link);
60850 if (len > (unsigned) buflen)
60851 len = buflen;
60852- if (copy_to_user(buffer, link, len))
60853+
60854+ if (len < sizeof(tmpbuf)) {
60855+ memcpy(tmpbuf, link, len);
60856+ newlink = tmpbuf;
60857+ } else
60858+ newlink = link;
60859+
60860+ if (copy_to_user(buffer, newlink, len))
60861 len = -EFAULT;
60862 out:
60863 return len;
60864diff --git a/fs/namespace.c b/fs/namespace.c
60865index be32ebc..c595734 100644
60866--- a/fs/namespace.c
60867+++ b/fs/namespace.c
60868@@ -1293,6 +1293,9 @@ static int do_umount(struct mount *mnt, int flags)
60869 if (!(sb->s_flags & MS_RDONLY))
60870 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
60871 up_write(&sb->s_umount);
60872+
60873+ gr_log_remount(mnt->mnt_devname, retval);
60874+
60875 return retval;
60876 }
60877
60878@@ -1315,6 +1318,9 @@ static int do_umount(struct mount *mnt, int flags)
60879 }
60880 unlock_mount_hash();
60881 namespace_unlock();
60882+
60883+ gr_log_unmount(mnt->mnt_devname, retval);
60884+
60885 return retval;
60886 }
60887
60888@@ -1334,7 +1340,7 @@ static inline bool may_mount(void)
60889 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
60890 */
60891
60892-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
60893+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
60894 {
60895 struct path path;
60896 struct mount *mnt;
60897@@ -1376,7 +1382,7 @@ out:
60898 /*
60899 * The 2.0 compatible umount. No flags.
60900 */
60901-SYSCALL_DEFINE1(oldumount, char __user *, name)
60902+SYSCALL_DEFINE1(oldumount, const char __user *, name)
60903 {
60904 return sys_umount(name, 0);
60905 }
60906@@ -2379,6 +2385,16 @@ long do_mount(const char *dev_name, const char *dir_name,
60907 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
60908 MS_STRICTATIME);
60909
60910+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
60911+ retval = -EPERM;
60912+ goto dput_out;
60913+ }
60914+
60915+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
60916+ retval = -EPERM;
60917+ goto dput_out;
60918+ }
60919+
60920 if (flags & MS_REMOUNT)
60921 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
60922 data_page);
60923@@ -2393,6 +2409,9 @@ long do_mount(const char *dev_name, const char *dir_name,
60924 dev_name, data_page);
60925 dput_out:
60926 path_put(&path);
60927+
60928+ gr_log_mount(dev_name, dir_name, retval);
60929+
60930 return retval;
60931 }
60932
60933@@ -2410,7 +2429,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
60934 * number incrementing at 10Ghz will take 12,427 years to wrap which
60935 * is effectively never, so we can ignore the possibility.
60936 */
60937-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
60938+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
60939
60940 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
60941 {
60942@@ -2425,7 +2444,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
60943 kfree(new_ns);
60944 return ERR_PTR(ret);
60945 }
60946- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
60947+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
60948 atomic_set(&new_ns->count, 1);
60949 new_ns->root = NULL;
60950 INIT_LIST_HEAD(&new_ns->list);
60951@@ -2435,7 +2454,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
60952 return new_ns;
60953 }
60954
60955-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
60956+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
60957 struct user_namespace *user_ns, struct fs_struct *new_fs)
60958 {
60959 struct mnt_namespace *new_ns;
60960@@ -2556,8 +2575,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
60961 }
60962 EXPORT_SYMBOL(mount_subtree);
60963
60964-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
60965- char __user *, type, unsigned long, flags, void __user *, data)
60966+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
60967+ const char __user *, type, unsigned long, flags, void __user *, data)
60968 {
60969 int ret;
60970 char *kernel_type;
60971@@ -2670,6 +2689,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
60972 if (error)
60973 goto out2;
60974
60975+ if (gr_handle_chroot_pivot()) {
60976+ error = -EPERM;
60977+ goto out2;
60978+ }
60979+
60980 get_fs_root(current->fs, &root);
60981 old_mp = lock_mount(&old);
60982 error = PTR_ERR(old_mp);
60983@@ -2930,7 +2954,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
60984 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
60985 return -EPERM;
60986
60987- if (fs->users != 1)
60988+ if (atomic_read(&fs->users) != 1)
60989 return -EINVAL;
60990
60991 get_mnt_ns(mnt_ns);
60992diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
60993index f4ccfe6..a5cf064 100644
60994--- a/fs/nfs/callback_xdr.c
60995+++ b/fs/nfs/callback_xdr.c
60996@@ -51,7 +51,7 @@ struct callback_op {
60997 callback_decode_arg_t decode_args;
60998 callback_encode_res_t encode_res;
60999 long res_maxsize;
61000-};
61001+} __do_const;
61002
61003 static struct callback_op callback_ops[];
61004
61005diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
61006index 00ad1c2..2fde15e 100644
61007--- a/fs/nfs/inode.c
61008+++ b/fs/nfs/inode.c
61009@@ -1146,16 +1146,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
61010 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
61011 }
61012
61013-static atomic_long_t nfs_attr_generation_counter;
61014+static atomic_long_unchecked_t nfs_attr_generation_counter;
61015
61016 static unsigned long nfs_read_attr_generation_counter(void)
61017 {
61018- return atomic_long_read(&nfs_attr_generation_counter);
61019+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
61020 }
61021
61022 unsigned long nfs_inc_attr_generation_counter(void)
61023 {
61024- return atomic_long_inc_return(&nfs_attr_generation_counter);
61025+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
61026 }
61027
61028 void nfs_fattr_init(struct nfs_fattr *fattr)
61029diff --git a/fs/nfs/nfs4client.c b/fs/nfs/nfs4client.c
61030index b4a160a..2b9bfba 100644
61031--- a/fs/nfs/nfs4client.c
61032+++ b/fs/nfs/nfs4client.c
61033@@ -409,13 +409,11 @@ struct nfs_client *nfs4_init_client(struct nfs_client *clp,
61034 error = nfs4_discover_server_trunking(clp, &old);
61035 if (error < 0)
61036 goto error;
61037- nfs_put_client(clp);
61038- if (clp != old) {
61039+
61040+ if (clp != old)
61041 clp->cl_preserve_clid = true;
61042- clp = old;
61043- }
61044-
61045- return clp;
61046+ nfs_put_client(clp);
61047+ return old;
61048
61049 error:
61050 nfs_mark_client_ready(clp, error);
61051@@ -493,9 +491,10 @@ int nfs40_walk_client_list(struct nfs_client *new,
61052 prev = pos;
61053
61054 status = nfs_wait_client_init_complete(pos);
61055- spin_lock(&nn->nfs_client_lock);
61056 if (status < 0)
61057- continue;
61058+ goto out;
61059+ status = -NFS4ERR_STALE_CLIENTID;
61060+ spin_lock(&nn->nfs_client_lock);
61061 }
61062 if (pos->cl_cons_state != NFS_CS_READY)
61063 continue;
61064@@ -633,7 +632,8 @@ int nfs41_walk_client_list(struct nfs_client *new,
61065 }
61066 spin_lock(&nn->nfs_client_lock);
61067 if (status < 0)
61068- continue;
61069+ break;
61070+ status = -NFS4ERR_STALE_CLIENTID;
61071 }
61072 if (pos->cl_cons_state != NFS_CS_READY)
61073 continue;
61074diff --git a/fs/nfs/write.c b/fs/nfs/write.c
61075index c1d5482..6a85038 100644
61076--- a/fs/nfs/write.c
61077+++ b/fs/nfs/write.c
61078@@ -922,19 +922,20 @@ out:
61079 * extend the write to cover the entire page in order to avoid fragmentation
61080 * inefficiencies.
61081 *
61082- * If the file is opened for synchronous writes or if we have a write delegation
61083- * from the server then we can just skip the rest of the checks.
61084+ * If the file is opened for synchronous writes then we can just skip the rest
61085+ * of the checks.
61086 */
61087 static int nfs_can_extend_write(struct file *file, struct page *page, struct inode *inode)
61088 {
61089 if (file->f_flags & O_DSYNC)
61090 return 0;
61091+ if (!nfs_write_pageuptodate(page, inode))
61092+ return 0;
61093 if (NFS_PROTO(inode)->have_delegation(inode, FMODE_WRITE))
61094 return 1;
61095- if (nfs_write_pageuptodate(page, inode) && (inode->i_flock == NULL ||
61096- (inode->i_flock->fl_start == 0 &&
61097+ if (inode->i_flock == NULL || (inode->i_flock->fl_start == 0 &&
61098 inode->i_flock->fl_end == OFFSET_MAX &&
61099- inode->i_flock->fl_type != F_RDLCK)))
61100+ inode->i_flock->fl_type != F_RDLCK))
61101 return 1;
61102 return 0;
61103 }
61104diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
61105index 419572f..5414a23 100644
61106--- a/fs/nfsd/nfs4proc.c
61107+++ b/fs/nfsd/nfs4proc.c
61108@@ -1168,7 +1168,7 @@ struct nfsd4_operation {
61109 nfsd4op_rsize op_rsize_bop;
61110 stateid_getter op_get_currentstateid;
61111 stateid_setter op_set_currentstateid;
61112-};
61113+} __do_const;
61114
61115 static struct nfsd4_operation nfsd4_ops[];
61116
61117diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
61118index ee7237f..e3ae60a 100644
61119--- a/fs/nfsd/nfs4xdr.c
61120+++ b/fs/nfsd/nfs4xdr.c
61121@@ -1523,7 +1523,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
61122
61123 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
61124
61125-static nfsd4_dec nfsd4_dec_ops[] = {
61126+static const nfsd4_dec nfsd4_dec_ops[] = {
61127 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
61128 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
61129 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
61130diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
61131index b6af150..f6ec5e3 100644
61132--- a/fs/nfsd/nfscache.c
61133+++ b/fs/nfsd/nfscache.c
61134@@ -547,14 +547,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
61135 {
61136 struct svc_cacherep *rp = rqstp->rq_cacherep;
61137 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
61138- int len;
61139+ long len;
61140 size_t bufsize = 0;
61141
61142 if (!rp)
61143 return;
61144
61145- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
61146- len >>= 2;
61147+ if (statp) {
61148+ len = (char*)statp - (char*)resv->iov_base;
61149+ len = resv->iov_len - len;
61150+ len >>= 2;
61151+ }
61152
61153 /* Don't cache excessive amounts of data and XDR failures */
61154 if (!statp || len > (256 >> 2)) {
61155diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
61156index 7eea63c..a35f4fb 100644
61157--- a/fs/nfsd/vfs.c
61158+++ b/fs/nfsd/vfs.c
61159@@ -993,7 +993,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
61160 } else {
61161 oldfs = get_fs();
61162 set_fs(KERNEL_DS);
61163- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
61164+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
61165 set_fs(oldfs);
61166 }
61167
61168@@ -1084,7 +1084,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
61169
61170 /* Write the data. */
61171 oldfs = get_fs(); set_fs(KERNEL_DS);
61172- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
61173+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
61174 set_fs(oldfs);
61175 if (host_err < 0)
61176 goto out_nfserr;
61177@@ -1629,7 +1629,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
61178 */
61179
61180 oldfs = get_fs(); set_fs(KERNEL_DS);
61181- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
61182+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
61183 set_fs(oldfs);
61184
61185 if (host_err < 0)
61186diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
61187index fea6bd5..8ee9d81 100644
61188--- a/fs/nls/nls_base.c
61189+++ b/fs/nls/nls_base.c
61190@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
61191
61192 int register_nls(struct nls_table * nls)
61193 {
61194- struct nls_table ** tmp = &tables;
61195+ struct nls_table *tmp = tables;
61196
61197 if (nls->next)
61198 return -EBUSY;
61199
61200 spin_lock(&nls_lock);
61201- while (*tmp) {
61202- if (nls == *tmp) {
61203+ while (tmp) {
61204+ if (nls == tmp) {
61205 spin_unlock(&nls_lock);
61206 return -EBUSY;
61207 }
61208- tmp = &(*tmp)->next;
61209+ tmp = tmp->next;
61210 }
61211- nls->next = tables;
61212+ pax_open_kernel();
61213+ *(struct nls_table **)&nls->next = tables;
61214+ pax_close_kernel();
61215 tables = nls;
61216 spin_unlock(&nls_lock);
61217 return 0;
61218@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
61219
61220 int unregister_nls(struct nls_table * nls)
61221 {
61222- struct nls_table ** tmp = &tables;
61223+ struct nls_table * const * tmp = &tables;
61224
61225 spin_lock(&nls_lock);
61226 while (*tmp) {
61227 if (nls == *tmp) {
61228- *tmp = nls->next;
61229+ pax_open_kernel();
61230+ *(struct nls_table **)tmp = nls->next;
61231+ pax_close_kernel();
61232 spin_unlock(&nls_lock);
61233 return 0;
61234 }
61235diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
61236index 7424929..35f6be5 100644
61237--- a/fs/nls/nls_euc-jp.c
61238+++ b/fs/nls/nls_euc-jp.c
61239@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
61240 p_nls = load_nls("cp932");
61241
61242 if (p_nls) {
61243- table.charset2upper = p_nls->charset2upper;
61244- table.charset2lower = p_nls->charset2lower;
61245+ pax_open_kernel();
61246+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
61247+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
61248+ pax_close_kernel();
61249 return register_nls(&table);
61250 }
61251
61252diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
61253index e7bc1d7..06bd4bb 100644
61254--- a/fs/nls/nls_koi8-ru.c
61255+++ b/fs/nls/nls_koi8-ru.c
61256@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
61257 p_nls = load_nls("koi8-u");
61258
61259 if (p_nls) {
61260- table.charset2upper = p_nls->charset2upper;
61261- table.charset2lower = p_nls->charset2lower;
61262+ pax_open_kernel();
61263+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
61264+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
61265+ pax_close_kernel();
61266 return register_nls(&table);
61267 }
61268
61269diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
61270index e44cb64..7668ca4 100644
61271--- a/fs/notify/fanotify/fanotify_user.c
61272+++ b/fs/notify/fanotify/fanotify_user.c
61273@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
61274
61275 fd = fanotify_event_metadata.fd;
61276 ret = -EFAULT;
61277- if (copy_to_user(buf, &fanotify_event_metadata,
61278- fanotify_event_metadata.event_len))
61279+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
61280+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
61281 goto out_close_fd;
61282
61283 ret = prepare_for_access_response(group, event, fd);
61284@@ -888,9 +888,9 @@ COMPAT_SYSCALL_DEFINE6(fanotify_mark,
61285 {
61286 return sys_fanotify_mark(fanotify_fd, flags,
61287 #ifdef __BIG_ENDIAN
61288- ((__u64)mask1 << 32) | mask0,
61289-#else
61290 ((__u64)mask0 << 32) | mask1,
61291+#else
61292+ ((__u64)mask1 << 32) | mask0,
61293 #endif
61294 dfd, pathname);
61295 }
61296diff --git a/fs/notify/notification.c b/fs/notify/notification.c
61297index 7b51b05..5ea5ef6 100644
61298--- a/fs/notify/notification.c
61299+++ b/fs/notify/notification.c
61300@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
61301 * get set to 0 so it will never get 'freed'
61302 */
61303 static struct fsnotify_event *q_overflow_event;
61304-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
61305+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
61306
61307 /**
61308 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
61309@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
61310 */
61311 u32 fsnotify_get_cookie(void)
61312 {
61313- return atomic_inc_return(&fsnotify_sync_cookie);
61314+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
61315 }
61316 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
61317
61318diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
61319index 9e38daf..5727cae 100644
61320--- a/fs/ntfs/dir.c
61321+++ b/fs/ntfs/dir.c
61322@@ -1310,7 +1310,7 @@ find_next_index_buffer:
61323 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
61324 ~(s64)(ndir->itype.index.block_size - 1)));
61325 /* Bounds checks. */
61326- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
61327+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
61328 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
61329 "inode 0x%lx or driver bug.", vdir->i_ino);
61330 goto err_out;
61331diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
61332index ea4ba9d..1e13d34 100644
61333--- a/fs/ntfs/file.c
61334+++ b/fs/ntfs/file.c
61335@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
61336 char *addr;
61337 size_t total = 0;
61338 unsigned len;
61339- int left;
61340+ unsigned left;
61341
61342 do {
61343 len = PAGE_CACHE_SIZE - ofs;
61344diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
61345index 82650d5..db37dcf 100644
61346--- a/fs/ntfs/super.c
61347+++ b/fs/ntfs/super.c
61348@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
61349 if (!silent)
61350 ntfs_error(sb, "Primary boot sector is invalid.");
61351 } else if (!silent)
61352- ntfs_error(sb, read_err_str, "primary");
61353+ ntfs_error(sb, read_err_str, "%s", "primary");
61354 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
61355 if (bh_primary)
61356 brelse(bh_primary);
61357@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
61358 goto hotfix_primary_boot_sector;
61359 brelse(bh_backup);
61360 } else if (!silent)
61361- ntfs_error(sb, read_err_str, "backup");
61362+ ntfs_error(sb, read_err_str, "%s", "backup");
61363 /* Try to read NT3.51- backup boot sector. */
61364 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
61365 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
61366@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
61367 "sector.");
61368 brelse(bh_backup);
61369 } else if (!silent)
61370- ntfs_error(sb, read_err_str, "backup");
61371+ ntfs_error(sb, read_err_str, "%s", "backup");
61372 /* We failed. Cleanup and return. */
61373 if (bh_primary)
61374 brelse(bh_primary);
61375diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
61376index cd5496b..26a1055 100644
61377--- a/fs/ocfs2/localalloc.c
61378+++ b/fs/ocfs2/localalloc.c
61379@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
61380 goto bail;
61381 }
61382
61383- atomic_inc(&osb->alloc_stats.moves);
61384+ atomic_inc_unchecked(&osb->alloc_stats.moves);
61385
61386 bail:
61387 if (handle)
61388diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
61389index 3a90347..c40bef8 100644
61390--- a/fs/ocfs2/ocfs2.h
61391+++ b/fs/ocfs2/ocfs2.h
61392@@ -235,11 +235,11 @@ enum ocfs2_vol_state
61393
61394 struct ocfs2_alloc_stats
61395 {
61396- atomic_t moves;
61397- atomic_t local_data;
61398- atomic_t bitmap_data;
61399- atomic_t bg_allocs;
61400- atomic_t bg_extends;
61401+ atomic_unchecked_t moves;
61402+ atomic_unchecked_t local_data;
61403+ atomic_unchecked_t bitmap_data;
61404+ atomic_unchecked_t bg_allocs;
61405+ atomic_unchecked_t bg_extends;
61406 };
61407
61408 enum ocfs2_local_alloc_state
61409diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
61410index 2c91452..77a3cd2 100644
61411--- a/fs/ocfs2/suballoc.c
61412+++ b/fs/ocfs2/suballoc.c
61413@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
61414 mlog_errno(status);
61415 goto bail;
61416 }
61417- atomic_inc(&osb->alloc_stats.bg_extends);
61418+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
61419
61420 /* You should never ask for this much metadata */
61421 BUG_ON(bits_wanted >
61422@@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
61423 mlog_errno(status);
61424 goto bail;
61425 }
61426- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61427+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61428
61429 *suballoc_loc = res.sr_bg_blkno;
61430 *suballoc_bit_start = res.sr_bit_offset;
61431@@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
61432 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
61433 res->sr_bits);
61434
61435- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61436+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61437
61438 BUG_ON(res->sr_bits != 1);
61439
61440@@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
61441 mlog_errno(status);
61442 goto bail;
61443 }
61444- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61445+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61446
61447 BUG_ON(res.sr_bits != 1);
61448
61449@@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
61450 cluster_start,
61451 num_clusters);
61452 if (!status)
61453- atomic_inc(&osb->alloc_stats.local_data);
61454+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
61455 } else {
61456 if (min_clusters > (osb->bitmap_cpg - 1)) {
61457 /* The only paths asking for contiguousness
61458@@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
61459 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
61460 res.sr_bg_blkno,
61461 res.sr_bit_offset);
61462- atomic_inc(&osb->alloc_stats.bitmap_data);
61463+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
61464 *num_clusters = res.sr_bits;
61465 }
61466 }
61467diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
61468index c414929..5c9ee542 100644
61469--- a/fs/ocfs2/super.c
61470+++ b/fs/ocfs2/super.c
61471@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
61472 "%10s => GlobalAllocs: %d LocalAllocs: %d "
61473 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
61474 "Stats",
61475- atomic_read(&osb->alloc_stats.bitmap_data),
61476- atomic_read(&osb->alloc_stats.local_data),
61477- atomic_read(&osb->alloc_stats.bg_allocs),
61478- atomic_read(&osb->alloc_stats.moves),
61479- atomic_read(&osb->alloc_stats.bg_extends));
61480+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
61481+ atomic_read_unchecked(&osb->alloc_stats.local_data),
61482+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
61483+ atomic_read_unchecked(&osb->alloc_stats.moves),
61484+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
61485
61486 out += snprintf(buf + out, len - out,
61487 "%10s => State: %u Descriptor: %llu Size: %u bits "
61488@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
61489 spin_lock_init(&osb->osb_xattr_lock);
61490 ocfs2_init_steal_slots(osb);
61491
61492- atomic_set(&osb->alloc_stats.moves, 0);
61493- atomic_set(&osb->alloc_stats.local_data, 0);
61494- atomic_set(&osb->alloc_stats.bitmap_data, 0);
61495- atomic_set(&osb->alloc_stats.bg_allocs, 0);
61496- atomic_set(&osb->alloc_stats.bg_extends, 0);
61497+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
61498+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
61499+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
61500+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
61501+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
61502
61503 /* Copy the blockcheck stats from the superblock probe */
61504 osb->osb_ecc_stats = *stats;
61505diff --git a/fs/open.c b/fs/open.c
61506index 4b3e1ed..1c84599 100644
61507--- a/fs/open.c
61508+++ b/fs/open.c
61509@@ -32,6 +32,8 @@
61510 #include <linux/dnotify.h>
61511 #include <linux/compat.h>
61512
61513+#define CREATE_TRACE_POINTS
61514+#include <trace/events/fs.h>
61515 #include "internal.h"
61516
61517 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
61518@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
61519 error = locks_verify_truncate(inode, NULL, length);
61520 if (!error)
61521 error = security_path_truncate(path);
61522+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
61523+ error = -EACCES;
61524 if (!error)
61525 error = do_truncate(path->dentry, length, 0, NULL);
61526
61527@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
61528 error = locks_verify_truncate(inode, f.file, length);
61529 if (!error)
61530 error = security_path_truncate(&f.file->f_path);
61531+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
61532+ error = -EACCES;
61533 if (!error)
61534 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
61535 sb_end_write(inode->i_sb);
61536@@ -361,6 +367,9 @@ retry:
61537 if (__mnt_is_readonly(path.mnt))
61538 res = -EROFS;
61539
61540+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
61541+ res = -EACCES;
61542+
61543 out_path_release:
61544 path_put(&path);
61545 if (retry_estale(res, lookup_flags)) {
61546@@ -392,6 +401,8 @@ retry:
61547 if (error)
61548 goto dput_and_out;
61549
61550+ gr_log_chdir(path.dentry, path.mnt);
61551+
61552 set_fs_pwd(current->fs, &path);
61553
61554 dput_and_out:
61555@@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
61556 goto out_putf;
61557
61558 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
61559+
61560+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
61561+ error = -EPERM;
61562+
61563+ if (!error)
61564+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
61565+
61566 if (!error)
61567 set_fs_pwd(current->fs, &f.file->f_path);
61568 out_putf:
61569@@ -450,7 +468,13 @@ retry:
61570 if (error)
61571 goto dput_and_out;
61572
61573+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
61574+ goto dput_and_out;
61575+
61576 set_fs_root(current->fs, &path);
61577+
61578+ gr_handle_chroot_chdir(&path);
61579+
61580 error = 0;
61581 dput_and_out:
61582 path_put(&path);
61583@@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
61584 return error;
61585 retry_deleg:
61586 mutex_lock(&inode->i_mutex);
61587+
61588+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
61589+ error = -EACCES;
61590+ goto out_unlock;
61591+ }
61592+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
61593+ error = -EACCES;
61594+ goto out_unlock;
61595+ }
61596+
61597 error = security_path_chmod(path, mode);
61598 if (error)
61599 goto out_unlock;
61600@@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
61601 uid = make_kuid(current_user_ns(), user);
61602 gid = make_kgid(current_user_ns(), group);
61603
61604+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
61605+ return -EACCES;
61606+
61607 newattrs.ia_valid = ATTR_CTIME;
61608 if (user != (uid_t) -1) {
61609 if (!uid_valid(uid))
61610@@ -990,6 +1027,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
61611 } else {
61612 fsnotify_open(f);
61613 fd_install(fd, f);
61614+ trace_do_sys_open(tmp->name, flags, mode);
61615 }
61616 }
61617 putname(tmp);
61618diff --git a/fs/pipe.c b/fs/pipe.c
61619index 0e0752e..7cfdd50 100644
61620--- a/fs/pipe.c
61621+++ b/fs/pipe.c
61622@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
61623
61624 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
61625 {
61626- if (pipe->files)
61627+ if (atomic_read(&pipe->files))
61628 mutex_lock_nested(&pipe->mutex, subclass);
61629 }
61630
61631@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
61632
61633 void pipe_unlock(struct pipe_inode_info *pipe)
61634 {
61635- if (pipe->files)
61636+ if (atomic_read(&pipe->files))
61637 mutex_unlock(&pipe->mutex);
61638 }
61639 EXPORT_SYMBOL(pipe_unlock);
61640@@ -449,9 +449,9 @@ redo:
61641 }
61642 if (bufs) /* More to do? */
61643 continue;
61644- if (!pipe->writers)
61645+ if (!atomic_read(&pipe->writers))
61646 break;
61647- if (!pipe->waiting_writers) {
61648+ if (!atomic_read(&pipe->waiting_writers)) {
61649 /* syscall merging: Usually we must not sleep
61650 * if O_NONBLOCK is set, or if we got some data.
61651 * But if a writer sleeps in kernel space, then
61652@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
61653 ret = 0;
61654 __pipe_lock(pipe);
61655
61656- if (!pipe->readers) {
61657+ if (!atomic_read(&pipe->readers)) {
61658 send_sig(SIGPIPE, current, 0);
61659 ret = -EPIPE;
61660 goto out;
61661@@ -562,7 +562,7 @@ redo1:
61662 for (;;) {
61663 int bufs;
61664
61665- if (!pipe->readers) {
61666+ if (!atomic_read(&pipe->readers)) {
61667 send_sig(SIGPIPE, current, 0);
61668 if (!ret)
61669 ret = -EPIPE;
61670@@ -653,9 +653,9 @@ redo2:
61671 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
61672 do_wakeup = 0;
61673 }
61674- pipe->waiting_writers++;
61675+ atomic_inc(&pipe->waiting_writers);
61676 pipe_wait(pipe);
61677- pipe->waiting_writers--;
61678+ atomic_dec(&pipe->waiting_writers);
61679 }
61680 out:
61681 __pipe_unlock(pipe);
61682@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
61683 mask = 0;
61684 if (filp->f_mode & FMODE_READ) {
61685 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
61686- if (!pipe->writers && filp->f_version != pipe->w_counter)
61687+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
61688 mask |= POLLHUP;
61689 }
61690
61691@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
61692 * Most Unices do not set POLLERR for FIFOs but on Linux they
61693 * behave exactly like pipes for poll().
61694 */
61695- if (!pipe->readers)
61696+ if (!atomic_read(&pipe->readers))
61697 mask |= POLLERR;
61698 }
61699
61700@@ -731,7 +731,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
61701 int kill = 0;
61702
61703 spin_lock(&inode->i_lock);
61704- if (!--pipe->files) {
61705+ if (atomic_dec_and_test(&pipe->files)) {
61706 inode->i_pipe = NULL;
61707 kill = 1;
61708 }
61709@@ -748,11 +748,11 @@ pipe_release(struct inode *inode, struct file *file)
61710
61711 __pipe_lock(pipe);
61712 if (file->f_mode & FMODE_READ)
61713- pipe->readers--;
61714+ atomic_dec(&pipe->readers);
61715 if (file->f_mode & FMODE_WRITE)
61716- pipe->writers--;
61717+ atomic_dec(&pipe->writers);
61718
61719- if (pipe->readers || pipe->writers) {
61720+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
61721 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
61722 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
61723 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
61724@@ -817,7 +817,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
61725 kfree(pipe);
61726 }
61727
61728-static struct vfsmount *pipe_mnt __read_mostly;
61729+struct vfsmount *pipe_mnt __read_mostly;
61730
61731 /*
61732 * pipefs_dname() is called from d_path().
61733@@ -847,8 +847,9 @@ static struct inode * get_pipe_inode(void)
61734 goto fail_iput;
61735
61736 inode->i_pipe = pipe;
61737- pipe->files = 2;
61738- pipe->readers = pipe->writers = 1;
61739+ atomic_set(&pipe->files, 2);
61740+ atomic_set(&pipe->readers, 1);
61741+ atomic_set(&pipe->writers, 1);
61742 inode->i_fop = &pipefifo_fops;
61743
61744 /*
61745@@ -1027,17 +1028,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
61746 spin_lock(&inode->i_lock);
61747 if (inode->i_pipe) {
61748 pipe = inode->i_pipe;
61749- pipe->files++;
61750+ atomic_inc(&pipe->files);
61751 spin_unlock(&inode->i_lock);
61752 } else {
61753 spin_unlock(&inode->i_lock);
61754 pipe = alloc_pipe_info();
61755 if (!pipe)
61756 return -ENOMEM;
61757- pipe->files = 1;
61758+ atomic_set(&pipe->files, 1);
61759 spin_lock(&inode->i_lock);
61760 if (unlikely(inode->i_pipe)) {
61761- inode->i_pipe->files++;
61762+ atomic_inc(&inode->i_pipe->files);
61763 spin_unlock(&inode->i_lock);
61764 free_pipe_info(pipe);
61765 pipe = inode->i_pipe;
61766@@ -1062,10 +1063,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
61767 * opened, even when there is no process writing the FIFO.
61768 */
61769 pipe->r_counter++;
61770- if (pipe->readers++ == 0)
61771+ if (atomic_inc_return(&pipe->readers) == 1)
61772 wake_up_partner(pipe);
61773
61774- if (!is_pipe && !pipe->writers) {
61775+ if (!is_pipe && !atomic_read(&pipe->writers)) {
61776 if ((filp->f_flags & O_NONBLOCK)) {
61777 /* suppress POLLHUP until we have
61778 * seen a writer */
61779@@ -1084,14 +1085,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
61780 * errno=ENXIO when there is no process reading the FIFO.
61781 */
61782 ret = -ENXIO;
61783- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
61784+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
61785 goto err;
61786
61787 pipe->w_counter++;
61788- if (!pipe->writers++)
61789+ if (atomic_inc_return(&pipe->writers) == 1)
61790 wake_up_partner(pipe);
61791
61792- if (!is_pipe && !pipe->readers) {
61793+ if (!is_pipe && !atomic_read(&pipe->readers)) {
61794 if (wait_for_partner(pipe, &pipe->r_counter))
61795 goto err_wr;
61796 }
61797@@ -1105,11 +1106,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
61798 * the process can at least talk to itself.
61799 */
61800
61801- pipe->readers++;
61802- pipe->writers++;
61803+ atomic_inc(&pipe->readers);
61804+ atomic_inc(&pipe->writers);
61805 pipe->r_counter++;
61806 pipe->w_counter++;
61807- if (pipe->readers == 1 || pipe->writers == 1)
61808+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
61809 wake_up_partner(pipe);
61810 break;
61811
61812@@ -1123,13 +1124,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
61813 return 0;
61814
61815 err_rd:
61816- if (!--pipe->readers)
61817+ if (atomic_dec_and_test(&pipe->readers))
61818 wake_up_interruptible(&pipe->wait);
61819 ret = -ERESTARTSYS;
61820 goto err;
61821
61822 err_wr:
61823- if (!--pipe->writers)
61824+ if (atomic_dec_and_test(&pipe->writers))
61825 wake_up_interruptible(&pipe->wait);
61826 ret = -ERESTARTSYS;
61827 goto err;
61828diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
61829index 2183fcf..3c32a98 100644
61830--- a/fs/proc/Kconfig
61831+++ b/fs/proc/Kconfig
61832@@ -30,7 +30,7 @@ config PROC_FS
61833
61834 config PROC_KCORE
61835 bool "/proc/kcore support" if !ARM
61836- depends on PROC_FS && MMU
61837+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
61838 help
61839 Provides a virtual ELF core file of the live kernel. This can
61840 be read with gdb and other ELF tools. No modifications can be
61841@@ -38,8 +38,8 @@ config PROC_KCORE
61842
61843 config PROC_VMCORE
61844 bool "/proc/vmcore support"
61845- depends on PROC_FS && CRASH_DUMP
61846- default y
61847+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
61848+ default n
61849 help
61850 Exports the dump image of crashed kernel in ELF format.
61851
61852@@ -63,8 +63,8 @@ config PROC_SYSCTL
61853 limited in memory.
61854
61855 config PROC_PAGE_MONITOR
61856- default y
61857- depends on PROC_FS && MMU
61858+ default n
61859+ depends on PROC_FS && MMU && !GRKERNSEC
61860 bool "Enable /proc page monitoring" if EXPERT
61861 help
61862 Various /proc files exist to monitor process memory utilization:
61863diff --git a/fs/proc/array.c b/fs/proc/array.c
61864index 1bd2077..2f7cfd5 100644
61865--- a/fs/proc/array.c
61866+++ b/fs/proc/array.c
61867@@ -60,6 +60,7 @@
61868 #include <linux/tty.h>
61869 #include <linux/string.h>
61870 #include <linux/mman.h>
61871+#include <linux/grsecurity.h>
61872 #include <linux/proc_fs.h>
61873 #include <linux/ioport.h>
61874 #include <linux/uaccess.h>
61875@@ -365,6 +366,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
61876 seq_putc(m, '\n');
61877 }
61878
61879+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
61880+static inline void task_pax(struct seq_file *m, struct task_struct *p)
61881+{
61882+ if (p->mm)
61883+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
61884+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
61885+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
61886+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
61887+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
61888+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
61889+ else
61890+ seq_printf(m, "PaX:\t-----\n");
61891+}
61892+#endif
61893+
61894 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
61895 struct pid *pid, struct task_struct *task)
61896 {
61897@@ -383,9 +399,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
61898 task_cpus_allowed(m, task);
61899 cpuset_task_status_allowed(m, task);
61900 task_context_switch_counts(m, task);
61901+
61902+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
61903+ task_pax(m, task);
61904+#endif
61905+
61906+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
61907+ task_grsec_rbac(m, task);
61908+#endif
61909+
61910 return 0;
61911 }
61912
61913+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61914+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
61915+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
61916+ _mm->pax_flags & MF_PAX_SEGMEXEC))
61917+#endif
61918+
61919 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61920 struct pid *pid, struct task_struct *task, int whole)
61921 {
61922@@ -407,6 +438,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61923 char tcomm[sizeof(task->comm)];
61924 unsigned long flags;
61925
61926+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61927+ if (current->exec_id != m->exec_id) {
61928+ gr_log_badprocpid("stat");
61929+ return 0;
61930+ }
61931+#endif
61932+
61933 state = *get_task_state(task);
61934 vsize = eip = esp = 0;
61935 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
61936@@ -478,6 +516,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61937 gtime = task_gtime(task);
61938 }
61939
61940+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61941+ if (PAX_RAND_FLAGS(mm)) {
61942+ eip = 0;
61943+ esp = 0;
61944+ wchan = 0;
61945+ }
61946+#endif
61947+#ifdef CONFIG_GRKERNSEC_HIDESYM
61948+ wchan = 0;
61949+ eip =0;
61950+ esp =0;
61951+#endif
61952+
61953 /* scale priority and nice values from timeslices to -20..20 */
61954 /* to make it look like a "normal" Unix priority/nice value */
61955 priority = task_prio(task);
61956@@ -514,9 +565,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61957 seq_put_decimal_ull(m, ' ', vsize);
61958 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
61959 seq_put_decimal_ull(m, ' ', rsslim);
61960+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61961+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
61962+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
61963+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
61964+#else
61965 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
61966 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
61967 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
61968+#endif
61969 seq_put_decimal_ull(m, ' ', esp);
61970 seq_put_decimal_ull(m, ' ', eip);
61971 /* The signal information here is obsolete.
61972@@ -538,7 +595,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61973 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
61974 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
61975
61976- if (mm && permitted) {
61977+ if (mm && permitted
61978+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61979+ && !PAX_RAND_FLAGS(mm)
61980+#endif
61981+ ) {
61982 seq_put_decimal_ull(m, ' ', mm->start_data);
61983 seq_put_decimal_ull(m, ' ', mm->end_data);
61984 seq_put_decimal_ull(m, ' ', mm->start_brk);
61985@@ -576,8 +637,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
61986 struct pid *pid, struct task_struct *task)
61987 {
61988 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
61989- struct mm_struct *mm = get_task_mm(task);
61990+ struct mm_struct *mm;
61991
61992+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61993+ if (current->exec_id != m->exec_id) {
61994+ gr_log_badprocpid("statm");
61995+ return 0;
61996+ }
61997+#endif
61998+ mm = get_task_mm(task);
61999 if (mm) {
62000 size = task_statm(mm, &shared, &text, &data, &resident);
62001 mmput(mm);
62002@@ -600,6 +668,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
62003 return 0;
62004 }
62005
62006+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
62007+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
62008+{
62009+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
62010+}
62011+#endif
62012+
62013 #ifdef CONFIG_CHECKPOINT_RESTORE
62014 static struct pid *
62015 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
62016diff --git a/fs/proc/base.c b/fs/proc/base.c
62017index 03c8d74..4efb575 100644
62018--- a/fs/proc/base.c
62019+++ b/fs/proc/base.c
62020@@ -113,6 +113,14 @@ struct pid_entry {
62021 union proc_op op;
62022 };
62023
62024+struct getdents_callback {
62025+ struct linux_dirent __user * current_dir;
62026+ struct linux_dirent __user * previous;
62027+ struct file * file;
62028+ int count;
62029+ int error;
62030+};
62031+
62032 #define NOD(NAME, MODE, IOP, FOP, OP) { \
62033 .name = (NAME), \
62034 .len = sizeof(NAME) - 1, \
62035@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
62036 if (!mm->arg_end)
62037 goto out_mm; /* Shh! No looking before we're done */
62038
62039+ if (gr_acl_handle_procpidmem(task))
62040+ goto out_mm;
62041+
62042 len = mm->arg_end - mm->arg_start;
62043
62044 if (len > PAGE_SIZE)
62045@@ -237,12 +248,28 @@ out:
62046 return res;
62047 }
62048
62049+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62050+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62051+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
62052+ _mm->pax_flags & MF_PAX_SEGMEXEC))
62053+#endif
62054+
62055 static int proc_pid_auxv(struct task_struct *task, char *buffer)
62056 {
62057 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
62058 int res = PTR_ERR(mm);
62059 if (mm && !IS_ERR(mm)) {
62060 unsigned int nwords = 0;
62061+
62062+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62063+ /* allow if we're currently ptracing this task */
62064+ if (PAX_RAND_FLAGS(mm) &&
62065+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
62066+ mmput(mm);
62067+ return 0;
62068+ }
62069+#endif
62070+
62071 do {
62072 nwords += 2;
62073 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
62074@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
62075 }
62076
62077
62078-#ifdef CONFIG_KALLSYMS
62079+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62080 /*
62081 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
62082 * Returns the resolved symbol. If that fails, simply return the address.
62083@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
62084 mutex_unlock(&task->signal->cred_guard_mutex);
62085 }
62086
62087-#ifdef CONFIG_STACKTRACE
62088+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62089
62090 #define MAX_STACK_TRACE_DEPTH 64
62091
62092@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
62093 return count;
62094 }
62095
62096-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
62097+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
62098 static int proc_pid_syscall(struct task_struct *task, char *buffer)
62099 {
62100 long nr;
62101@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
62102 /************************************************************************/
62103
62104 /* permission checks */
62105-static int proc_fd_access_allowed(struct inode *inode)
62106+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
62107 {
62108 struct task_struct *task;
62109 int allowed = 0;
62110@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
62111 */
62112 task = get_proc_task(inode);
62113 if (task) {
62114- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
62115+ if (log)
62116+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
62117+ else
62118+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
62119 put_task_struct(task);
62120 }
62121 return allowed;
62122@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
62123 struct task_struct *task,
62124 int hide_pid_min)
62125 {
62126+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
62127+ return false;
62128+
62129+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62130+ rcu_read_lock();
62131+ {
62132+ const struct cred *tmpcred = current_cred();
62133+ const struct cred *cred = __task_cred(task);
62134+
62135+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
62136+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62137+ || in_group_p(grsec_proc_gid)
62138+#endif
62139+ ) {
62140+ rcu_read_unlock();
62141+ return true;
62142+ }
62143+ }
62144+ rcu_read_unlock();
62145+
62146+ if (!pid->hide_pid)
62147+ return false;
62148+#endif
62149+
62150 if (pid->hide_pid < hide_pid_min)
62151 return true;
62152 if (in_group_p(pid->pid_gid))
62153 return true;
62154+
62155 return ptrace_may_access(task, PTRACE_MODE_READ);
62156 }
62157
62158@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
62159 put_task_struct(task);
62160
62161 if (!has_perms) {
62162+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62163+ {
62164+#else
62165 if (pid->hide_pid == 2) {
62166+#endif
62167 /*
62168 * Let's make getdents(), stat(), and open()
62169 * consistent with each other. If a process
62170@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
62171 if (!task)
62172 return -ESRCH;
62173
62174+ if (gr_acl_handle_procpidmem(task)) {
62175+ put_task_struct(task);
62176+ return -EPERM;
62177+ }
62178+
62179 mm = mm_access(task, mode);
62180 put_task_struct(task);
62181
62182@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
62183
62184 file->private_data = mm;
62185
62186+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62187+ file->f_version = current->exec_id;
62188+#endif
62189+
62190 return 0;
62191 }
62192
62193@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
62194 ssize_t copied;
62195 char *page;
62196
62197+#ifdef CONFIG_GRKERNSEC
62198+ if (write)
62199+ return -EPERM;
62200+#endif
62201+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62202+ if (file->f_version != current->exec_id) {
62203+ gr_log_badprocpid("mem");
62204+ return 0;
62205+ }
62206+#endif
62207+
62208 if (!mm)
62209 return 0;
62210
62211@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
62212 goto free;
62213
62214 while (count > 0) {
62215- int this_len = min_t(int, count, PAGE_SIZE);
62216+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
62217
62218 if (write && copy_from_user(page, buf, this_len)) {
62219 copied = -EFAULT;
62220@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
62221 if (!mm)
62222 return 0;
62223
62224+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62225+ if (file->f_version != current->exec_id) {
62226+ gr_log_badprocpid("environ");
62227+ return 0;
62228+ }
62229+#endif
62230+
62231 page = (char *)__get_free_page(GFP_TEMPORARY);
62232 if (!page)
62233 return -ENOMEM;
62234@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
62235 goto free;
62236 while (count > 0) {
62237 size_t this_len, max_len;
62238- int retval;
62239+ ssize_t retval;
62240
62241 if (src >= (mm->env_end - mm->env_start))
62242 break;
62243@@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
62244 int error = -EACCES;
62245
62246 /* Are we allowed to snoop on the tasks file descriptors? */
62247- if (!proc_fd_access_allowed(inode))
62248+ if (!proc_fd_access_allowed(inode, 0))
62249 goto out;
62250
62251 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
62252@@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
62253 struct path path;
62254
62255 /* Are we allowed to snoop on the tasks file descriptors? */
62256- if (!proc_fd_access_allowed(inode))
62257- goto out;
62258+ /* logging this is needed for learning on chromium to work properly,
62259+ but we don't want to flood the logs from 'ps' which does a readlink
62260+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
62261+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
62262+ */
62263+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
62264+ if (!proc_fd_access_allowed(inode,0))
62265+ goto out;
62266+ } else {
62267+ if (!proc_fd_access_allowed(inode,1))
62268+ goto out;
62269+ }
62270
62271 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
62272 if (error)
62273@@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
62274 rcu_read_lock();
62275 cred = __task_cred(task);
62276 inode->i_uid = cred->euid;
62277+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62278+ inode->i_gid = grsec_proc_gid;
62279+#else
62280 inode->i_gid = cred->egid;
62281+#endif
62282 rcu_read_unlock();
62283 }
62284 security_task_to_inode(task, inode);
62285@@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
62286 return -ENOENT;
62287 }
62288 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
62289+#ifdef CONFIG_GRKERNSEC_PROC_USER
62290+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
62291+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62292+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
62293+#endif
62294 task_dumpable(task)) {
62295 cred = __task_cred(task);
62296 stat->uid = cred->euid;
62297+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62298+ stat->gid = grsec_proc_gid;
62299+#else
62300 stat->gid = cred->egid;
62301+#endif
62302 }
62303 }
62304 rcu_read_unlock();
62305@@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
62306
62307 if (task) {
62308 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
62309+#ifdef CONFIG_GRKERNSEC_PROC_USER
62310+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
62311+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62312+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
62313+#endif
62314 task_dumpable(task)) {
62315 rcu_read_lock();
62316 cred = __task_cred(task);
62317 inode->i_uid = cred->euid;
62318+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62319+ inode->i_gid = grsec_proc_gid;
62320+#else
62321 inode->i_gid = cred->egid;
62322+#endif
62323 rcu_read_unlock();
62324 } else {
62325 inode->i_uid = GLOBAL_ROOT_UID;
62326@@ -2172,6 +2290,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
62327 if (!task)
62328 goto out_no_task;
62329
62330+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
62331+ goto out;
62332+
62333 /*
62334 * Yes, it does not scale. And it should not. Don't add
62335 * new entries into /proc/<tgid>/ without very good reasons.
62336@@ -2202,6 +2323,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
62337 if (!task)
62338 return -ENOENT;
62339
62340+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
62341+ goto out;
62342+
62343 if (!dir_emit_dots(file, ctx))
62344 goto out;
62345
62346@@ -2591,7 +2715,7 @@ static const struct pid_entry tgid_base_stuff[] = {
62347 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
62348 #endif
62349 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
62350-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
62351+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
62352 INF("syscall", S_IRUGO, proc_pid_syscall),
62353 #endif
62354 INF("cmdline", S_IRUGO, proc_pid_cmdline),
62355@@ -2616,10 +2740,10 @@ static const struct pid_entry tgid_base_stuff[] = {
62356 #ifdef CONFIG_SECURITY
62357 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
62358 #endif
62359-#ifdef CONFIG_KALLSYMS
62360+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62361 INF("wchan", S_IRUGO, proc_pid_wchan),
62362 #endif
62363-#ifdef CONFIG_STACKTRACE
62364+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62365 ONE("stack", S_IRUGO, proc_pid_stack),
62366 #endif
62367 #ifdef CONFIG_SCHEDSTATS
62368@@ -2653,6 +2777,9 @@ static const struct pid_entry tgid_base_stuff[] = {
62369 #ifdef CONFIG_HARDWALL
62370 INF("hardwall", S_IRUGO, proc_pid_hardwall),
62371 #endif
62372+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
62373+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
62374+#endif
62375 #ifdef CONFIG_USER_NS
62376 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
62377 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
62378@@ -2783,7 +2910,14 @@ static int proc_pid_instantiate(struct inode *dir,
62379 if (!inode)
62380 goto out;
62381
62382+#ifdef CONFIG_GRKERNSEC_PROC_USER
62383+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
62384+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62385+ inode->i_gid = grsec_proc_gid;
62386+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
62387+#else
62388 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
62389+#endif
62390 inode->i_op = &proc_tgid_base_inode_operations;
62391 inode->i_fop = &proc_tgid_base_operations;
62392 inode->i_flags|=S_IMMUTABLE;
62393@@ -2821,7 +2955,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
62394 if (!task)
62395 goto out;
62396
62397+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
62398+ goto out_put_task;
62399+
62400 result = proc_pid_instantiate(dir, dentry, task, NULL);
62401+out_put_task:
62402 put_task_struct(task);
62403 out:
62404 return ERR_PTR(result);
62405@@ -2927,7 +3065,7 @@ static const struct pid_entry tid_base_stuff[] = {
62406 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
62407 #endif
62408 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
62409-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
62410+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
62411 INF("syscall", S_IRUGO, proc_pid_syscall),
62412 #endif
62413 INF("cmdline", S_IRUGO, proc_pid_cmdline),
62414@@ -2954,10 +3092,10 @@ static const struct pid_entry tid_base_stuff[] = {
62415 #ifdef CONFIG_SECURITY
62416 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
62417 #endif
62418-#ifdef CONFIG_KALLSYMS
62419+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62420 INF("wchan", S_IRUGO, proc_pid_wchan),
62421 #endif
62422-#ifdef CONFIG_STACKTRACE
62423+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62424 ONE("stack", S_IRUGO, proc_pid_stack),
62425 #endif
62426 #ifdef CONFIG_SCHEDSTATS
62427diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
62428index 82676e3..5f8518a 100644
62429--- a/fs/proc/cmdline.c
62430+++ b/fs/proc/cmdline.c
62431@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
62432
62433 static int __init proc_cmdline_init(void)
62434 {
62435+#ifdef CONFIG_GRKERNSEC_PROC_ADD
62436+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
62437+#else
62438 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
62439+#endif
62440 return 0;
62441 }
62442 module_init(proc_cmdline_init);
62443diff --git a/fs/proc/devices.c b/fs/proc/devices.c
62444index b143471..bb105e5 100644
62445--- a/fs/proc/devices.c
62446+++ b/fs/proc/devices.c
62447@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
62448
62449 static int __init proc_devices_init(void)
62450 {
62451+#ifdef CONFIG_GRKERNSEC_PROC_ADD
62452+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
62453+#else
62454 proc_create("devices", 0, NULL, &proc_devinfo_operations);
62455+#endif
62456 return 0;
62457 }
62458 module_init(proc_devices_init);
62459diff --git a/fs/proc/fd.c b/fs/proc/fd.c
62460index 985ea88..d118a0a 100644
62461--- a/fs/proc/fd.c
62462+++ b/fs/proc/fd.c
62463@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
62464 if (!task)
62465 return -ENOENT;
62466
62467- files = get_files_struct(task);
62468+ if (!gr_acl_handle_procpidmem(task))
62469+ files = get_files_struct(task);
62470 put_task_struct(task);
62471
62472 if (files) {
62473@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
62474 */
62475 int proc_fd_permission(struct inode *inode, int mask)
62476 {
62477+ struct task_struct *task;
62478 int rv = generic_permission(inode, mask);
62479- if (rv == 0)
62480- return 0;
62481+
62482 if (task_tgid(current) == proc_pid(inode))
62483 rv = 0;
62484+
62485+ task = get_proc_task(inode);
62486+ if (task == NULL)
62487+ return rv;
62488+
62489+ if (gr_acl_handle_procpidmem(task))
62490+ rv = -EACCES;
62491+
62492+ put_task_struct(task);
62493+
62494 return rv;
62495 }
62496
62497diff --git a/fs/proc/inode.c b/fs/proc/inode.c
62498index 124fc43..8afbb02 100644
62499--- a/fs/proc/inode.c
62500+++ b/fs/proc/inode.c
62501@@ -23,11 +23,17 @@
62502 #include <linux/slab.h>
62503 #include <linux/mount.h>
62504 #include <linux/magic.h>
62505+#include <linux/grsecurity.h>
62506
62507 #include <asm/uaccess.h>
62508
62509 #include "internal.h"
62510
62511+#ifdef CONFIG_PROC_SYSCTL
62512+extern const struct inode_operations proc_sys_inode_operations;
62513+extern const struct inode_operations proc_sys_dir_operations;
62514+#endif
62515+
62516 static void proc_evict_inode(struct inode *inode)
62517 {
62518 struct proc_dir_entry *de;
62519@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
62520 ns = PROC_I(inode)->ns.ns;
62521 if (ns_ops && ns)
62522 ns_ops->put(ns);
62523+
62524+#ifdef CONFIG_PROC_SYSCTL
62525+ if (inode->i_op == &proc_sys_inode_operations ||
62526+ inode->i_op == &proc_sys_dir_operations)
62527+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
62528+#endif
62529+
62530 }
62531
62532 static struct kmem_cache * proc_inode_cachep;
62533@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
62534 if (de->mode) {
62535 inode->i_mode = de->mode;
62536 inode->i_uid = de->uid;
62537+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62538+ inode->i_gid = grsec_proc_gid;
62539+#else
62540 inode->i_gid = de->gid;
62541+#endif
62542 }
62543 if (de->size)
62544 inode->i_size = de->size;
62545diff --git a/fs/proc/internal.h b/fs/proc/internal.h
62546index 651d09a..3d7f0bf 100644
62547--- a/fs/proc/internal.h
62548+++ b/fs/proc/internal.h
62549@@ -48,7 +48,7 @@ struct proc_dir_entry {
62550 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
62551 u8 namelen;
62552 char name[];
62553-};
62554+} __randomize_layout;
62555
62556 union proc_op {
62557 int (*proc_get_link)(struct dentry *, struct path *);
62558@@ -67,7 +67,7 @@ struct proc_inode {
62559 struct ctl_table *sysctl_entry;
62560 struct proc_ns ns;
62561 struct inode vfs_inode;
62562-};
62563+} __randomize_layout;
62564
62565 /*
62566 * General functions
62567@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
62568 struct pid *, struct task_struct *);
62569 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
62570 struct pid *, struct task_struct *);
62571+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
62572+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
62573+#endif
62574
62575 /*
62576 * base.c
62577diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
62578index 05029c0..7ea1987 100644
62579--- a/fs/proc/interrupts.c
62580+++ b/fs/proc/interrupts.c
62581@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
62582
62583 static int __init proc_interrupts_init(void)
62584 {
62585+#ifdef CONFIG_GRKERNSEC_PROC_ADD
62586+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
62587+#else
62588 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
62589+#endif
62590 return 0;
62591 }
62592 module_init(proc_interrupts_init);
62593diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
62594index 5ed0e52..a1c1f2e 100644
62595--- a/fs/proc/kcore.c
62596+++ b/fs/proc/kcore.c
62597@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
62598 * the addresses in the elf_phdr on our list.
62599 */
62600 start = kc_offset_to_vaddr(*fpos - elf_buflen);
62601- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
62602+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
62603+ if (tsz > buflen)
62604 tsz = buflen;
62605-
62606+
62607 while (buflen) {
62608 struct kcore_list *m;
62609
62610@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
62611 kfree(elf_buf);
62612 } else {
62613 if (kern_addr_valid(start)) {
62614- unsigned long n;
62615+ char *elf_buf;
62616+ mm_segment_t oldfs;
62617
62618- n = copy_to_user(buffer, (char *)start, tsz);
62619- /*
62620- * We cannot distinguish between fault on source
62621- * and fault on destination. When this happens
62622- * we clear too and hope it will trigger the
62623- * EFAULT again.
62624- */
62625- if (n) {
62626- if (clear_user(buffer + tsz - n,
62627- n))
62628+ elf_buf = kmalloc(tsz, GFP_KERNEL);
62629+ if (!elf_buf)
62630+ return -ENOMEM;
62631+ oldfs = get_fs();
62632+ set_fs(KERNEL_DS);
62633+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
62634+ set_fs(oldfs);
62635+ if (copy_to_user(buffer, elf_buf, tsz)) {
62636+ kfree(elf_buf);
62637 return -EFAULT;
62638+ }
62639 }
62640+ set_fs(oldfs);
62641+ kfree(elf_buf);
62642 } else {
62643 if (clear_user(buffer, tsz))
62644 return -EFAULT;
62645@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
62646
62647 static int open_kcore(struct inode *inode, struct file *filp)
62648 {
62649+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
62650+ return -EPERM;
62651+#endif
62652 if (!capable(CAP_SYS_RAWIO))
62653 return -EPERM;
62654 if (kcore_need_update)
62655diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
62656index a77d2b2..a9153f0 100644
62657--- a/fs/proc/meminfo.c
62658+++ b/fs/proc/meminfo.c
62659@@ -150,7 +150,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
62660 vmi.used >> 10,
62661 vmi.largest_chunk >> 10
62662 #ifdef CONFIG_MEMORY_FAILURE
62663- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
62664+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
62665 #endif
62666 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
62667 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
62668diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
62669index 5f9bc8a..5c35f08 100644
62670--- a/fs/proc/nommu.c
62671+++ b/fs/proc/nommu.c
62672@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
62673
62674 if (file) {
62675 seq_pad(m, ' ');
62676- seq_path(m, &file->f_path, "");
62677+ seq_path(m, &file->f_path, "\n\\");
62678 }
62679
62680 seq_putc(m, '\n');
62681diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
62682index 4677bb7..408e936 100644
62683--- a/fs/proc/proc_net.c
62684+++ b/fs/proc/proc_net.c
62685@@ -23,6 +23,7 @@
62686 #include <linux/nsproxy.h>
62687 #include <net/net_namespace.h>
62688 #include <linux/seq_file.h>
62689+#include <linux/grsecurity.h>
62690
62691 #include "internal.h"
62692
62693@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
62694 struct task_struct *task;
62695 struct nsproxy *ns;
62696 struct net *net = NULL;
62697+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62698+ const struct cred *cred = current_cred();
62699+#endif
62700+
62701+#ifdef CONFIG_GRKERNSEC_PROC_USER
62702+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
62703+ return net;
62704+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62705+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
62706+ return net;
62707+#endif
62708
62709 rcu_read_lock();
62710 task = pid_task(proc_pid(dir), PIDTYPE_PID);
62711diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
62712index 7129046..6914844 100644
62713--- a/fs/proc/proc_sysctl.c
62714+++ b/fs/proc/proc_sysctl.c
62715@@ -11,13 +11,21 @@
62716 #include <linux/namei.h>
62717 #include <linux/mm.h>
62718 #include <linux/module.h>
62719+#include <linux/nsproxy.h>
62720+#ifdef CONFIG_GRKERNSEC
62721+#include <net/net_namespace.h>
62722+#endif
62723 #include "internal.h"
62724
62725+extern int gr_handle_chroot_sysctl(const int op);
62726+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
62727+ const int op);
62728+
62729 static const struct dentry_operations proc_sys_dentry_operations;
62730 static const struct file_operations proc_sys_file_operations;
62731-static const struct inode_operations proc_sys_inode_operations;
62732+const struct inode_operations proc_sys_inode_operations;
62733 static const struct file_operations proc_sys_dir_file_operations;
62734-static const struct inode_operations proc_sys_dir_operations;
62735+const struct inode_operations proc_sys_dir_operations;
62736
62737 void proc_sys_poll_notify(struct ctl_table_poll *poll)
62738 {
62739@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
62740
62741 err = NULL;
62742 d_set_d_op(dentry, &proc_sys_dentry_operations);
62743+
62744+ gr_handle_proc_create(dentry, inode);
62745+
62746 d_add(dentry, inode);
62747
62748 out:
62749@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
62750 struct inode *inode = file_inode(filp);
62751 struct ctl_table_header *head = grab_header(inode);
62752 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
62753+ int op = write ? MAY_WRITE : MAY_READ;
62754 ssize_t error;
62755 size_t res;
62756
62757@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
62758 * and won't be until we finish.
62759 */
62760 error = -EPERM;
62761- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
62762+ if (sysctl_perm(head, table, op))
62763 goto out;
62764
62765 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
62766@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
62767 if (!table->proc_handler)
62768 goto out;
62769
62770+#ifdef CONFIG_GRKERNSEC
62771+ error = -EPERM;
62772+ if (gr_handle_chroot_sysctl(op))
62773+ goto out;
62774+ dget(filp->f_path.dentry);
62775+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
62776+ dput(filp->f_path.dentry);
62777+ goto out;
62778+ }
62779+ dput(filp->f_path.dentry);
62780+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
62781+ goto out;
62782+ if (write) {
62783+ if (current->nsproxy->net_ns != table->extra2) {
62784+ if (!capable(CAP_SYS_ADMIN))
62785+ goto out;
62786+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
62787+ goto out;
62788+ }
62789+#endif
62790+
62791 /* careful: calling conventions are nasty here */
62792 res = count;
62793 error = table->proc_handler(table, write, buf, &res, ppos);
62794@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
62795 return false;
62796 } else {
62797 d_set_d_op(child, &proc_sys_dentry_operations);
62798+
62799+ gr_handle_proc_create(child, inode);
62800+
62801 d_add(child, inode);
62802 }
62803 } else {
62804@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
62805 if ((*pos)++ < ctx->pos)
62806 return true;
62807
62808+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
62809+ return 0;
62810+
62811 if (unlikely(S_ISLNK(table->mode)))
62812 res = proc_sys_link_fill_cache(file, ctx, head, table);
62813 else
62814@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
62815 if (IS_ERR(head))
62816 return PTR_ERR(head);
62817
62818+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
62819+ return -ENOENT;
62820+
62821 generic_fillattr(inode, stat);
62822 if (table)
62823 stat->mode = (stat->mode & S_IFMT) | table->mode;
62824@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
62825 .llseek = generic_file_llseek,
62826 };
62827
62828-static const struct inode_operations proc_sys_inode_operations = {
62829+const struct inode_operations proc_sys_inode_operations = {
62830 .permission = proc_sys_permission,
62831 .setattr = proc_sys_setattr,
62832 .getattr = proc_sys_getattr,
62833 };
62834
62835-static const struct inode_operations proc_sys_dir_operations = {
62836+const struct inode_operations proc_sys_dir_operations = {
62837 .lookup = proc_sys_lookup,
62838 .permission = proc_sys_permission,
62839 .setattr = proc_sys_setattr,
62840@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
62841 static struct ctl_dir *new_dir(struct ctl_table_set *set,
62842 const char *name, int namelen)
62843 {
62844- struct ctl_table *table;
62845+ ctl_table_no_const *table;
62846 struct ctl_dir *new;
62847 struct ctl_node *node;
62848 char *new_name;
62849@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
62850 return NULL;
62851
62852 node = (struct ctl_node *)(new + 1);
62853- table = (struct ctl_table *)(node + 1);
62854+ table = (ctl_table_no_const *)(node + 1);
62855 new_name = (char *)(table + 2);
62856 memcpy(new_name, name, namelen);
62857 new_name[namelen] = '\0';
62858@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
62859 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
62860 struct ctl_table_root *link_root)
62861 {
62862- struct ctl_table *link_table, *entry, *link;
62863+ ctl_table_no_const *link_table, *link;
62864+ struct ctl_table *entry;
62865 struct ctl_table_header *links;
62866 struct ctl_node *node;
62867 char *link_name;
62868@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
62869 return NULL;
62870
62871 node = (struct ctl_node *)(links + 1);
62872- link_table = (struct ctl_table *)(node + nr_entries);
62873+ link_table = (ctl_table_no_const *)(node + nr_entries);
62874 link_name = (char *)&link_table[nr_entries + 1];
62875
62876 for (link = link_table, entry = table; entry->procname; link++, entry++) {
62877@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
62878 struct ctl_table_header ***subheader, struct ctl_table_set *set,
62879 struct ctl_table *table)
62880 {
62881- struct ctl_table *ctl_table_arg = NULL;
62882- struct ctl_table *entry, *files;
62883+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
62884+ struct ctl_table *entry;
62885 int nr_files = 0;
62886 int nr_dirs = 0;
62887 int err = -ENOMEM;
62888@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
62889 nr_files++;
62890 }
62891
62892- files = table;
62893 /* If there are mixed files and directories we need a new table */
62894 if (nr_dirs && nr_files) {
62895- struct ctl_table *new;
62896+ ctl_table_no_const *new;
62897 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
62898 GFP_KERNEL);
62899 if (!files)
62900@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
62901 /* Register everything except a directory full of subdirectories */
62902 if (nr_files || !nr_dirs) {
62903 struct ctl_table_header *header;
62904- header = __register_sysctl_table(set, path, files);
62905+ header = __register_sysctl_table(set, path, files ? files : table);
62906 if (!header) {
62907 kfree(ctl_table_arg);
62908 goto out;
62909diff --git a/fs/proc/root.c b/fs/proc/root.c
62910index 87dbcbe..55e1b4d 100644
62911--- a/fs/proc/root.c
62912+++ b/fs/proc/root.c
62913@@ -186,7 +186,15 @@ void __init proc_root_init(void)
62914 #ifdef CONFIG_PROC_DEVICETREE
62915 proc_device_tree_init();
62916 #endif
62917+#ifdef CONFIG_GRKERNSEC_PROC_ADD
62918+#ifdef CONFIG_GRKERNSEC_PROC_USER
62919+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
62920+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62921+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
62922+#endif
62923+#else
62924 proc_mkdir("bus", NULL);
62925+#endif
62926 proc_sys_init();
62927 }
62928
62929diff --git a/fs/proc/stat.c b/fs/proc/stat.c
62930index 1cf86c0..0ee1ca5 100644
62931--- a/fs/proc/stat.c
62932+++ b/fs/proc/stat.c
62933@@ -11,6 +11,7 @@
62934 #include <linux/irqnr.h>
62935 #include <asm/cputime.h>
62936 #include <linux/tick.h>
62937+#include <linux/grsecurity.h>
62938
62939 #ifndef arch_irq_stat_cpu
62940 #define arch_irq_stat_cpu(cpu) 0
62941@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
62942 u64 sum_softirq = 0;
62943 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
62944 struct timespec boottime;
62945+ int unrestricted = 1;
62946+
62947+#ifdef CONFIG_GRKERNSEC_PROC_ADD
62948+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62949+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
62950+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62951+ && !in_group_p(grsec_proc_gid)
62952+#endif
62953+ )
62954+ unrestricted = 0;
62955+#endif
62956+#endif
62957
62958 user = nice = system = idle = iowait =
62959 irq = softirq = steal = 0;
62960@@ -94,6 +107,7 @@ static int show_stat(struct seq_file *p, void *v)
62961 getboottime(&boottime);
62962 jif = boottime.tv_sec;
62963
62964+ if (unrestricted) {
62965 for_each_possible_cpu(i) {
62966 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
62967 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
62968@@ -116,6 +130,7 @@ static int show_stat(struct seq_file *p, void *v)
62969 }
62970 }
62971 sum += arch_irq_stat();
62972+ }
62973
62974 seq_puts(p, "cpu ");
62975 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
62976@@ -131,6 +146,7 @@ static int show_stat(struct seq_file *p, void *v)
62977 seq_putc(p, '\n');
62978
62979 for_each_online_cpu(i) {
62980+ if (unrestricted) {
62981 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
62982 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
62983 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
62984@@ -142,6 +158,7 @@ static int show_stat(struct seq_file *p, void *v)
62985 steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
62986 guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
62987 guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
62988+ }
62989 seq_printf(p, "cpu%d", i);
62990 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
62991 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
62992@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
62993
62994 /* sum again ? it could be updated? */
62995 for_each_irq_nr(j)
62996- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
62997+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
62998
62999 seq_printf(p,
63000 "\nctxt %llu\n"
63001@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
63002 "processes %lu\n"
63003 "procs_running %lu\n"
63004 "procs_blocked %lu\n",
63005- nr_context_switches(),
63006+ unrestricted ? nr_context_switches() : 0ULL,
63007 (unsigned long)jif,
63008- total_forks,
63009- nr_running(),
63010- nr_iowait());
63011+ unrestricted ? total_forks : 0UL,
63012+ unrestricted ? nr_running() : 0UL,
63013+ unrestricted ? nr_iowait() : 0UL);
63014
63015 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
63016
63017diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
63018index fb52b54..5fc7c14 100644
63019--- a/fs/proc/task_mmu.c
63020+++ b/fs/proc/task_mmu.c
63021@@ -12,12 +12,19 @@
63022 #include <linux/swap.h>
63023 #include <linux/swapops.h>
63024 #include <linux/mmu_notifier.h>
63025+#include <linux/grsecurity.h>
63026
63027 #include <asm/elf.h>
63028 #include <asm/uaccess.h>
63029 #include <asm/tlbflush.h>
63030 #include "internal.h"
63031
63032+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63033+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63034+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63035+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63036+#endif
63037+
63038 void task_mem(struct seq_file *m, struct mm_struct *mm)
63039 {
63040 unsigned long data, text, lib, swap;
63041@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63042 "VmExe:\t%8lu kB\n"
63043 "VmLib:\t%8lu kB\n"
63044 "VmPTE:\t%8lu kB\n"
63045- "VmSwap:\t%8lu kB\n",
63046- hiwater_vm << (PAGE_SHIFT-10),
63047+ "VmSwap:\t%8lu kB\n"
63048+
63049+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63050+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
63051+#endif
63052+
63053+ ,hiwater_vm << (PAGE_SHIFT-10),
63054 total_vm << (PAGE_SHIFT-10),
63055 mm->locked_vm << (PAGE_SHIFT-10),
63056 mm->pinned_vm << (PAGE_SHIFT-10),
63057@@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63058 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
63059 (PTRS_PER_PTE * sizeof(pte_t) *
63060 atomic_long_read(&mm->nr_ptes)) >> 10,
63061- swap << (PAGE_SHIFT-10));
63062+ swap << (PAGE_SHIFT-10)
63063+
63064+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63065+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63066+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
63067+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
63068+#else
63069+ , mm->context.user_cs_base
63070+ , mm->context.user_cs_limit
63071+#endif
63072+#endif
63073+
63074+ );
63075 }
63076
63077 unsigned long task_vsize(struct mm_struct *mm)
63078@@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63079 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
63080 }
63081
63082- /* We don't show the stack guard page in /proc/maps */
63083+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63084+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
63085+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
63086+#else
63087 start = vma->vm_start;
63088- if (stack_guard_page_start(vma, start))
63089- start += PAGE_SIZE;
63090 end = vma->vm_end;
63091- if (stack_guard_page_end(vma, end))
63092- end -= PAGE_SIZE;
63093+#endif
63094
63095 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
63096 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
63097@@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63098 flags & VM_WRITE ? 'w' : '-',
63099 flags & VM_EXEC ? 'x' : '-',
63100 flags & VM_MAYSHARE ? 's' : 'p',
63101+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63102+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
63103+#else
63104 pgoff,
63105+#endif
63106 MAJOR(dev), MINOR(dev), ino);
63107
63108 /*
63109@@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63110 */
63111 if (file) {
63112 seq_pad(m, ' ');
63113- seq_path(m, &file->f_path, "\n");
63114+ seq_path(m, &file->f_path, "\n\\");
63115 goto done;
63116 }
63117
63118@@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63119 * Thread stack in /proc/PID/task/TID/maps or
63120 * the main process stack.
63121 */
63122- if (!is_pid || (vma->vm_start <= mm->start_stack &&
63123- vma->vm_end >= mm->start_stack)) {
63124+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
63125+ (vma->vm_start <= mm->start_stack &&
63126+ vma->vm_end >= mm->start_stack)) {
63127 name = "[stack]";
63128 } else {
63129 /* Thread stack in /proc/PID/maps */
63130@@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
63131 struct proc_maps_private *priv = m->private;
63132 struct task_struct *task = priv->task;
63133
63134+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63135+ if (current->exec_id != m->exec_id) {
63136+ gr_log_badprocpid("maps");
63137+ return 0;
63138+ }
63139+#endif
63140+
63141 show_map_vma(m, vma, is_pid);
63142
63143 if (m->count < m->size) /* vma is copied successfully */
63144@@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
63145 .private = &mss,
63146 };
63147
63148+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63149+ if (current->exec_id != m->exec_id) {
63150+ gr_log_badprocpid("smaps");
63151+ return 0;
63152+ }
63153+#endif
63154 memset(&mss, 0, sizeof mss);
63155- mss.vma = vma;
63156- /* mmap_sem is held in m_start */
63157- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
63158- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
63159-
63160+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63161+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
63162+#endif
63163+ mss.vma = vma;
63164+ /* mmap_sem is held in m_start */
63165+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
63166+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
63167+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63168+ }
63169+#endif
63170 show_map_vma(m, vma, is_pid);
63171
63172 seq_printf(m,
63173@@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
63174 "KernelPageSize: %8lu kB\n"
63175 "MMUPageSize: %8lu kB\n"
63176 "Locked: %8lu kB\n",
63177+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63178+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
63179+#else
63180 (vma->vm_end - vma->vm_start) >> 10,
63181+#endif
63182 mss.resident >> 10,
63183 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
63184 mss.shared_clean >> 10,
63185@@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
63186 char buffer[64];
63187 int nid;
63188
63189+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63190+ if (current->exec_id != m->exec_id) {
63191+ gr_log_badprocpid("numa_maps");
63192+ return 0;
63193+ }
63194+#endif
63195+
63196 if (!mm)
63197 return 0;
63198
63199@@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
63200 mpol_to_str(buffer, sizeof(buffer), pol);
63201 mpol_cond_put(pol);
63202
63203+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63204+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
63205+#else
63206 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
63207+#endif
63208
63209 if (file) {
63210 seq_printf(m, " file=");
63211- seq_path(m, &file->f_path, "\n\t= ");
63212+ seq_path(m, &file->f_path, "\n\t\\= ");
63213 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
63214 seq_printf(m, " heap");
63215 } else {
63216diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
63217index 678455d..ebd3245 100644
63218--- a/fs/proc/task_nommu.c
63219+++ b/fs/proc/task_nommu.c
63220@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63221 else
63222 bytes += kobjsize(mm);
63223
63224- if (current->fs && current->fs->users > 1)
63225+ if (current->fs && atomic_read(&current->fs->users) > 1)
63226 sbytes += kobjsize(current->fs);
63227 else
63228 bytes += kobjsize(current->fs);
63229@@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
63230
63231 if (file) {
63232 seq_pad(m, ' ');
63233- seq_path(m, &file->f_path, "");
63234+ seq_path(m, &file->f_path, "\n\\");
63235 } else if (mm) {
63236 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
63237
63238diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
63239index 9100d69..51cd925 100644
63240--- a/fs/proc/vmcore.c
63241+++ b/fs/proc/vmcore.c
63242@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
63243 nr_bytes = count;
63244
63245 /* If pfn is not ram, return zeros for sparse dump files */
63246- if (pfn_is_ram(pfn) == 0)
63247- memset(buf, 0, nr_bytes);
63248- else {
63249+ if (pfn_is_ram(pfn) == 0) {
63250+ if (userbuf) {
63251+ if (clear_user((char __force_user *)buf, nr_bytes))
63252+ return -EFAULT;
63253+ } else
63254+ memset(buf, 0, nr_bytes);
63255+ } else {
63256 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
63257 offset, userbuf);
63258 if (tmp < 0)
63259@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
63260 static int copy_to(void *target, void *src, size_t size, int userbuf)
63261 {
63262 if (userbuf) {
63263- if (copy_to_user((char __user *) target, src, size))
63264+ if (copy_to_user((char __force_user *) target, src, size))
63265 return -EFAULT;
63266 } else {
63267 memcpy(target, src, size);
63268@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
63269 if (*fpos < m->offset + m->size) {
63270 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
63271 start = m->paddr + *fpos - m->offset;
63272- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
63273+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
63274 if (tmp < 0)
63275 return tmp;
63276 buflen -= tsz;
63277@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
63278 static ssize_t read_vmcore(struct file *file, char __user *buffer,
63279 size_t buflen, loff_t *fpos)
63280 {
63281- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
63282+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
63283 }
63284
63285 /*
63286diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
63287index b00fcc9..e0c6381 100644
63288--- a/fs/qnx6/qnx6.h
63289+++ b/fs/qnx6/qnx6.h
63290@@ -74,7 +74,7 @@ enum {
63291 BYTESEX_BE,
63292 };
63293
63294-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
63295+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
63296 {
63297 if (sbi->s_bytesex == BYTESEX_LE)
63298 return le64_to_cpu((__force __le64)n);
63299@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
63300 return (__force __fs64)cpu_to_be64(n);
63301 }
63302
63303-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
63304+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
63305 {
63306 if (sbi->s_bytesex == BYTESEX_LE)
63307 return le32_to_cpu((__force __le32)n);
63308diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
63309index 72d2917..c917c12 100644
63310--- a/fs/quota/netlink.c
63311+++ b/fs/quota/netlink.c
63312@@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
63313 void quota_send_warning(struct kqid qid, dev_t dev,
63314 const char warntype)
63315 {
63316- static atomic_t seq;
63317+ static atomic_unchecked_t seq;
63318 struct sk_buff *skb;
63319 void *msg_head;
63320 int ret;
63321@@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
63322 "VFS: Not enough memory to send quota warning.\n");
63323 return;
63324 }
63325- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
63326+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
63327 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
63328 if (!msg_head) {
63329 printk(KERN_ERR
63330diff --git a/fs/read_write.c b/fs/read_write.c
63331index 58e440d..8ec2838 100644
63332--- a/fs/read_write.c
63333+++ b/fs/read_write.c
63334@@ -438,7 +438,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
63335
63336 old_fs = get_fs();
63337 set_fs(get_ds());
63338- p = (__force const char __user *)buf;
63339+ p = (const char __force_user *)buf;
63340 if (count > MAX_RW_COUNT)
63341 count = MAX_RW_COUNT;
63342 if (file->f_op->write)
63343diff --git a/fs/readdir.c b/fs/readdir.c
63344index 5b53d99..a6c3049 100644
63345--- a/fs/readdir.c
63346+++ b/fs/readdir.c
63347@@ -17,6 +17,7 @@
63348 #include <linux/security.h>
63349 #include <linux/syscalls.h>
63350 #include <linux/unistd.h>
63351+#include <linux/namei.h>
63352
63353 #include <asm/uaccess.h>
63354
63355@@ -69,6 +70,7 @@ struct old_linux_dirent {
63356 struct readdir_callback {
63357 struct dir_context ctx;
63358 struct old_linux_dirent __user * dirent;
63359+ struct file * file;
63360 int result;
63361 };
63362
63363@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
63364 buf->result = -EOVERFLOW;
63365 return -EOVERFLOW;
63366 }
63367+
63368+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
63369+ return 0;
63370+
63371 buf->result++;
63372 dirent = buf->dirent;
63373 if (!access_ok(VERIFY_WRITE, dirent,
63374@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
63375 if (!f.file)
63376 return -EBADF;
63377
63378+ buf.file = f.file;
63379 error = iterate_dir(f.file, &buf.ctx);
63380 if (buf.result)
63381 error = buf.result;
63382@@ -142,6 +149,7 @@ struct getdents_callback {
63383 struct dir_context ctx;
63384 struct linux_dirent __user * current_dir;
63385 struct linux_dirent __user * previous;
63386+ struct file * file;
63387 int count;
63388 int error;
63389 };
63390@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
63391 buf->error = -EOVERFLOW;
63392 return -EOVERFLOW;
63393 }
63394+
63395+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
63396+ return 0;
63397+
63398 dirent = buf->previous;
63399 if (dirent) {
63400 if (__put_user(offset, &dirent->d_off))
63401@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
63402 if (!f.file)
63403 return -EBADF;
63404
63405+ buf.file = f.file;
63406 error = iterate_dir(f.file, &buf.ctx);
63407 if (error >= 0)
63408 error = buf.error;
63409@@ -226,6 +239,7 @@ struct getdents_callback64 {
63410 struct dir_context ctx;
63411 struct linux_dirent64 __user * current_dir;
63412 struct linux_dirent64 __user * previous;
63413+ struct file *file;
63414 int count;
63415 int error;
63416 };
63417@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
63418 buf->error = -EINVAL; /* only used if we fail.. */
63419 if (reclen > buf->count)
63420 return -EINVAL;
63421+
63422+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
63423+ return 0;
63424+
63425 dirent = buf->previous;
63426 if (dirent) {
63427 if (__put_user(offset, &dirent->d_off))
63428@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
63429 if (!f.file)
63430 return -EBADF;
63431
63432+ buf.file = f.file;
63433 error = iterate_dir(f.file, &buf.ctx);
63434 if (error >= 0)
63435 error = buf.error;
63436diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
63437index 2b7882b..1c5ef48 100644
63438--- a/fs/reiserfs/do_balan.c
63439+++ b/fs/reiserfs/do_balan.c
63440@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
63441 return;
63442 }
63443
63444- atomic_inc(&(fs_generation(tb->tb_sb)));
63445+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
63446 do_balance_starts(tb);
63447
63448 /* balance leaf returns 0 except if combining L R and S into
63449diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
63450index ee382ef..f4eb6eb5 100644
63451--- a/fs/reiserfs/item_ops.c
63452+++ b/fs/reiserfs/item_ops.c
63453@@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
63454 }
63455
63456 static struct item_operations errcatch_ops = {
63457- errcatch_bytes_number,
63458- errcatch_decrement_key,
63459- errcatch_is_left_mergeable,
63460- errcatch_print_item,
63461- errcatch_check_item,
63462+ .bytes_number = errcatch_bytes_number,
63463+ .decrement_key = errcatch_decrement_key,
63464+ .is_left_mergeable = errcatch_is_left_mergeable,
63465+ .print_item = errcatch_print_item,
63466+ .check_item = errcatch_check_item,
63467
63468- errcatch_create_vi,
63469- errcatch_check_left,
63470- errcatch_check_right,
63471- errcatch_part_size,
63472- errcatch_unit_num,
63473- errcatch_print_vi
63474+ .create_vi = errcatch_create_vi,
63475+ .check_left = errcatch_check_left,
63476+ .check_right = errcatch_check_right,
63477+ .part_size = errcatch_part_size,
63478+ .unit_num = errcatch_unit_num,
63479+ .print_vi = errcatch_print_vi
63480 };
63481
63482 //////////////////////////////////////////////////////////////////////////////
63483diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
63484index a958444..42b2323 100644
63485--- a/fs/reiserfs/procfs.c
63486+++ b/fs/reiserfs/procfs.c
63487@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
63488 "SMALL_TAILS " : "NO_TAILS ",
63489 replay_only(sb) ? "REPLAY_ONLY " : "",
63490 convert_reiserfs(sb) ? "CONV " : "",
63491- atomic_read(&r->s_generation_counter),
63492+ atomic_read_unchecked(&r->s_generation_counter),
63493 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
63494 SF(s_do_balance), SF(s_unneeded_left_neighbor),
63495 SF(s_good_search_by_key_reada), SF(s_bmaps),
63496diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
63497index f8adaee..0eeeeca 100644
63498--- a/fs/reiserfs/reiserfs.h
63499+++ b/fs/reiserfs/reiserfs.h
63500@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
63501 /* Comment? -Hans */
63502 wait_queue_head_t s_wait;
63503 /* To be obsoleted soon by per buffer seals.. -Hans */
63504- atomic_t s_generation_counter; // increased by one every time the
63505+ atomic_unchecked_t s_generation_counter; // increased by one every time the
63506 // tree gets re-balanced
63507 unsigned long s_properties; /* File system properties. Currently holds
63508 on-disk FS format */
63509@@ -1982,7 +1982,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
63510 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
63511
63512 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
63513-#define get_generation(s) atomic_read (&fs_generation(s))
63514+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
63515 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
63516 #define __fs_changed(gen,s) (gen != get_generation (s))
63517 #define fs_changed(gen,s) \
63518diff --git a/fs/select.c b/fs/select.c
63519index 467bb1c..cf9d65a 100644
63520--- a/fs/select.c
63521+++ b/fs/select.c
63522@@ -20,6 +20,7 @@
63523 #include <linux/export.h>
63524 #include <linux/slab.h>
63525 #include <linux/poll.h>
63526+#include <linux/security.h>
63527 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
63528 #include <linux/file.h>
63529 #include <linux/fdtable.h>
63530@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
63531 struct poll_list *walk = head;
63532 unsigned long todo = nfds;
63533
63534+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
63535 if (nfds > rlimit(RLIMIT_NOFILE))
63536 return -EINVAL;
63537
63538diff --git a/fs/seq_file.c b/fs/seq_file.c
63539index 1d641bb..e600623 100644
63540--- a/fs/seq_file.c
63541+++ b/fs/seq_file.c
63542@@ -10,6 +10,7 @@
63543 #include <linux/seq_file.h>
63544 #include <linux/slab.h>
63545 #include <linux/cred.h>
63546+#include <linux/sched.h>
63547
63548 #include <asm/uaccess.h>
63549 #include <asm/page.h>
63550@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
63551 #ifdef CONFIG_USER_NS
63552 p->user_ns = file->f_cred->user_ns;
63553 #endif
63554+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63555+ p->exec_id = current->exec_id;
63556+#endif
63557
63558 /*
63559 * Wrappers around seq_open(e.g. swaps_open) need to be
63560@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
63561 return 0;
63562 }
63563 if (!m->buf) {
63564- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
63565+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
63566 if (!m->buf)
63567 return -ENOMEM;
63568 }
63569@@ -137,7 +141,7 @@ Eoverflow:
63570 m->op->stop(m, p);
63571 kfree(m->buf);
63572 m->count = 0;
63573- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
63574+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
63575 return !m->buf ? -ENOMEM : -EAGAIN;
63576 }
63577
63578@@ -153,7 +157,7 @@ Eoverflow:
63579 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
63580 {
63581 struct seq_file *m = file->private_data;
63582- size_t copied = 0;
63583+ ssize_t copied = 0;
63584 loff_t pos;
63585 size_t n;
63586 void *p;
63587@@ -192,7 +196,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
63588
63589 /* grab buffer if we didn't have one */
63590 if (!m->buf) {
63591- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
63592+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
63593 if (!m->buf)
63594 goto Enomem;
63595 }
63596@@ -234,7 +238,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
63597 m->op->stop(m, p);
63598 kfree(m->buf);
63599 m->count = 0;
63600- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
63601+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
63602 if (!m->buf)
63603 goto Enomem;
63604 m->version = 0;
63605@@ -584,7 +588,7 @@ static void single_stop(struct seq_file *p, void *v)
63606 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
63607 void *data)
63608 {
63609- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
63610+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
63611 int res = -ENOMEM;
63612
63613 if (op) {
63614diff --git a/fs/splice.c b/fs/splice.c
63615index 46a08f7..bb163cc 100644
63616--- a/fs/splice.c
63617+++ b/fs/splice.c
63618@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
63619 pipe_lock(pipe);
63620
63621 for (;;) {
63622- if (!pipe->readers) {
63623+ if (!atomic_read(&pipe->readers)) {
63624 send_sig(SIGPIPE, current, 0);
63625 if (!ret)
63626 ret = -EPIPE;
63627@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
63628 page_nr++;
63629 ret += buf->len;
63630
63631- if (pipe->files)
63632+ if (atomic_read(&pipe->files))
63633 do_wakeup = 1;
63634
63635 if (!--spd->nr_pages)
63636@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
63637 do_wakeup = 0;
63638 }
63639
63640- pipe->waiting_writers++;
63641+ atomic_inc(&pipe->waiting_writers);
63642 pipe_wait(pipe);
63643- pipe->waiting_writers--;
63644+ atomic_dec(&pipe->waiting_writers);
63645 }
63646
63647 pipe_unlock(pipe);
63648@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
63649 old_fs = get_fs();
63650 set_fs(get_ds());
63651 /* The cast to a user pointer is valid due to the set_fs() */
63652- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
63653+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
63654 set_fs(old_fs);
63655
63656 return res;
63657@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
63658 old_fs = get_fs();
63659 set_fs(get_ds());
63660 /* The cast to a user pointer is valid due to the set_fs() */
63661- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
63662+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
63663 set_fs(old_fs);
63664
63665 return res;
63666@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
63667 goto err;
63668
63669 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
63670- vec[i].iov_base = (void __user *) page_address(page);
63671+ vec[i].iov_base = (void __force_user *) page_address(page);
63672 vec[i].iov_len = this_len;
63673 spd.pages[i] = page;
63674 spd.nr_pages++;
63675@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
63676 ops->release(pipe, buf);
63677 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
63678 pipe->nrbufs--;
63679- if (pipe->files)
63680+ if (atomic_read(&pipe->files))
63681 sd->need_wakeup = true;
63682 }
63683
63684@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
63685 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
63686 {
63687 while (!pipe->nrbufs) {
63688- if (!pipe->writers)
63689+ if (!atomic_read(&pipe->writers))
63690 return 0;
63691
63692- if (!pipe->waiting_writers && sd->num_spliced)
63693+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
63694 return 0;
63695
63696 if (sd->flags & SPLICE_F_NONBLOCK)
63697@@ -1179,7 +1179,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
63698 * out of the pipe right after the splice_to_pipe(). So set
63699 * PIPE_READERS appropriately.
63700 */
63701- pipe->readers = 1;
63702+ atomic_set(&pipe->readers, 1);
63703
63704 current->splice_pipe = pipe;
63705 }
63706@@ -1475,6 +1475,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
63707
63708 partial[buffers].offset = off;
63709 partial[buffers].len = plen;
63710+ partial[buffers].private = 0;
63711
63712 off = 0;
63713 len -= plen;
63714@@ -1777,9 +1778,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
63715 ret = -ERESTARTSYS;
63716 break;
63717 }
63718- if (!pipe->writers)
63719+ if (!atomic_read(&pipe->writers))
63720 break;
63721- if (!pipe->waiting_writers) {
63722+ if (!atomic_read(&pipe->waiting_writers)) {
63723 if (flags & SPLICE_F_NONBLOCK) {
63724 ret = -EAGAIN;
63725 break;
63726@@ -1811,7 +1812,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
63727 pipe_lock(pipe);
63728
63729 while (pipe->nrbufs >= pipe->buffers) {
63730- if (!pipe->readers) {
63731+ if (!atomic_read(&pipe->readers)) {
63732 send_sig(SIGPIPE, current, 0);
63733 ret = -EPIPE;
63734 break;
63735@@ -1824,9 +1825,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
63736 ret = -ERESTARTSYS;
63737 break;
63738 }
63739- pipe->waiting_writers++;
63740+ atomic_inc(&pipe->waiting_writers);
63741 pipe_wait(pipe);
63742- pipe->waiting_writers--;
63743+ atomic_dec(&pipe->waiting_writers);
63744 }
63745
63746 pipe_unlock(pipe);
63747@@ -1862,14 +1863,14 @@ retry:
63748 pipe_double_lock(ipipe, opipe);
63749
63750 do {
63751- if (!opipe->readers) {
63752+ if (!atomic_read(&opipe->readers)) {
63753 send_sig(SIGPIPE, current, 0);
63754 if (!ret)
63755 ret = -EPIPE;
63756 break;
63757 }
63758
63759- if (!ipipe->nrbufs && !ipipe->writers)
63760+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
63761 break;
63762
63763 /*
63764@@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
63765 pipe_double_lock(ipipe, opipe);
63766
63767 do {
63768- if (!opipe->readers) {
63769+ if (!atomic_read(&opipe->readers)) {
63770 send_sig(SIGPIPE, current, 0);
63771 if (!ret)
63772 ret = -EPIPE;
63773@@ -2011,7 +2012,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
63774 * return EAGAIN if we have the potential of some data in the
63775 * future, otherwise just return 0
63776 */
63777- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
63778+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
63779 ret = -EAGAIN;
63780
63781 pipe_unlock(ipipe);
63782diff --git a/fs/stat.c b/fs/stat.c
63783index ae0c3ce..9ee641c 100644
63784--- a/fs/stat.c
63785+++ b/fs/stat.c
63786@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
63787 stat->gid = inode->i_gid;
63788 stat->rdev = inode->i_rdev;
63789 stat->size = i_size_read(inode);
63790- stat->atime = inode->i_atime;
63791- stat->mtime = inode->i_mtime;
63792+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
63793+ stat->atime = inode->i_ctime;
63794+ stat->mtime = inode->i_ctime;
63795+ } else {
63796+ stat->atime = inode->i_atime;
63797+ stat->mtime = inode->i_mtime;
63798+ }
63799 stat->ctime = inode->i_ctime;
63800 stat->blksize = (1 << inode->i_blkbits);
63801 stat->blocks = inode->i_blocks;
63802@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
63803 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
63804 {
63805 struct inode *inode = path->dentry->d_inode;
63806+ int retval;
63807
63808- if (inode->i_op->getattr)
63809- return inode->i_op->getattr(path->mnt, path->dentry, stat);
63810+ if (inode->i_op->getattr) {
63811+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
63812+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
63813+ stat->atime = stat->ctime;
63814+ stat->mtime = stat->ctime;
63815+ }
63816+ return retval;
63817+ }
63818
63819 generic_fillattr(inode, stat);
63820 return 0;
63821diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
63822index 5e73d66..4f165fd 100644
63823--- a/fs/sysfs/dir.c
63824+++ b/fs/sysfs/dir.c
63825@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
63826 *
63827 * Returns 31 bit hash of ns + name (so it fits in an off_t )
63828 */
63829-static unsigned int sysfs_name_hash(const char *name, const void *ns)
63830+static unsigned int sysfs_name_hash(const unsigned char *name, const void *ns)
63831 {
63832 unsigned long hash = init_name_hash();
63833 unsigned int len = strlen(name);
63834@@ -676,6 +676,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
63835 struct sysfs_dirent *sd;
63836 int rc;
63837
63838+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
63839+ const char *parent_name = parent_sd->s_name;
63840+
63841+ mode = S_IFDIR | S_IRWXU;
63842+
63843+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
63844+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
63845+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
63846+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
63847+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
63848+#endif
63849+
63850 /* allocate */
63851 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
63852 if (!sd)
63853diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
63854index 35e7d08..4d6e676 100644
63855--- a/fs/sysfs/file.c
63856+++ b/fs/sysfs/file.c
63857@@ -42,7 +42,7 @@ static DEFINE_MUTEX(sysfs_open_file_mutex);
63858
63859 struct sysfs_open_dirent {
63860 atomic_t refcnt;
63861- atomic_t event;
63862+ atomic_unchecked_t event;
63863 wait_queue_head_t poll;
63864 struct list_head files; /* goes through sysfs_open_file.list */
63865 };
63866@@ -112,7 +112,7 @@ static int sysfs_seq_show(struct seq_file *sf, void *v)
63867 return -ENODEV;
63868 }
63869
63870- of->event = atomic_read(&of->sd->s_attr.open->event);
63871+ of->event = atomic_read_unchecked(&of->sd->s_attr.open->event);
63872
63873 /*
63874 * Lookup @ops and invoke show(). Control may reach here via seq
63875@@ -365,12 +365,12 @@ static int sysfs_bin_page_mkwrite(struct vm_area_struct *vma,
63876 return ret;
63877 }
63878
63879-static int sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
63880- void *buf, int len, int write)
63881+static ssize_t sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
63882+ void *buf, size_t len, int write)
63883 {
63884 struct file *file = vma->vm_file;
63885 struct sysfs_open_file *of = sysfs_of(file);
63886- int ret;
63887+ ssize_t ret;
63888
63889 if (!of->vm_ops)
63890 return -EINVAL;
63891@@ -564,7 +564,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
63892 return -ENOMEM;
63893
63894 atomic_set(&new_od->refcnt, 0);
63895- atomic_set(&new_od->event, 1);
63896+ atomic_set_unchecked(&new_od->event, 1);
63897 init_waitqueue_head(&new_od->poll);
63898 INIT_LIST_HEAD(&new_od->files);
63899 goto retry;
63900@@ -768,7 +768,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
63901
63902 sysfs_put_active(attr_sd);
63903
63904- if (of->event != atomic_read(&od->event))
63905+ if (of->event != atomic_read_unchecked(&od->event))
63906 goto trigger;
63907
63908 return DEFAULT_POLLMASK;
63909@@ -787,7 +787,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
63910 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
63911 od = sd->s_attr.open;
63912 if (od) {
63913- atomic_inc(&od->event);
63914+ atomic_inc_unchecked(&od->event);
63915 wake_up_interruptible(&od->poll);
63916 }
63917 }
63918diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
63919index 3ae3f1b..081a26c 100644
63920--- a/fs/sysfs/symlink.c
63921+++ b/fs/sysfs/symlink.c
63922@@ -314,7 +314,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
63923 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd,
63924 void *cookie)
63925 {
63926- char *page = nd_get_link(nd);
63927+ const char *page = nd_get_link(nd);
63928 if (!IS_ERR(page))
63929 free_page((unsigned long)page);
63930 }
63931diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
63932index 69d4889..a810bd4 100644
63933--- a/fs/sysv/sysv.h
63934+++ b/fs/sysv/sysv.h
63935@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
63936 #endif
63937 }
63938
63939-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
63940+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
63941 {
63942 if (sbi->s_bytesex == BYTESEX_PDP)
63943 return PDP_swab((__force __u32)n);
63944diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
63945index e18b988..f1d4ad0f 100644
63946--- a/fs/ubifs/io.c
63947+++ b/fs/ubifs/io.c
63948@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
63949 return err;
63950 }
63951
63952-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
63953+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
63954 {
63955 int err;
63956
63957diff --git a/fs/udf/misc.c b/fs/udf/misc.c
63958index c175b4d..8f36a16 100644
63959--- a/fs/udf/misc.c
63960+++ b/fs/udf/misc.c
63961@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
63962
63963 u8 udf_tag_checksum(const struct tag *t)
63964 {
63965- u8 *data = (u8 *)t;
63966+ const u8 *data = (const u8 *)t;
63967 u8 checksum = 0;
63968 int i;
63969 for (i = 0; i < sizeof(struct tag); ++i)
63970diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
63971index 8d974c4..b82f6ec 100644
63972--- a/fs/ufs/swab.h
63973+++ b/fs/ufs/swab.h
63974@@ -22,7 +22,7 @@ enum {
63975 BYTESEX_BE
63976 };
63977
63978-static inline u64
63979+static inline u64 __intentional_overflow(-1)
63980 fs64_to_cpu(struct super_block *sbp, __fs64 n)
63981 {
63982 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
63983@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
63984 return (__force __fs64)cpu_to_be64(n);
63985 }
63986
63987-static inline u32
63988+static inline u32 __intentional_overflow(-1)
63989 fs32_to_cpu(struct super_block *sbp, __fs32 n)
63990 {
63991 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
63992diff --git a/fs/utimes.c b/fs/utimes.c
63993index aa138d6..5f3a811 100644
63994--- a/fs/utimes.c
63995+++ b/fs/utimes.c
63996@@ -1,6 +1,7 @@
63997 #include <linux/compiler.h>
63998 #include <linux/file.h>
63999 #include <linux/fs.h>
64000+#include <linux/security.h>
64001 #include <linux/linkage.h>
64002 #include <linux/mount.h>
64003 #include <linux/namei.h>
64004@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
64005 }
64006 }
64007 retry_deleg:
64008+
64009+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
64010+ error = -EACCES;
64011+ goto mnt_drop_write_and_out;
64012+ }
64013+
64014 mutex_lock(&inode->i_mutex);
64015 error = notify_change(path->dentry, &newattrs, &delegated_inode);
64016 mutex_unlock(&inode->i_mutex);
64017diff --git a/fs/xattr.c b/fs/xattr.c
64018index 3377dff..f394815 100644
64019--- a/fs/xattr.c
64020+++ b/fs/xattr.c
64021@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
64022 return rc;
64023 }
64024
64025+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
64026+ssize_t
64027+pax_getxattr(struct dentry *dentry, void *value, size_t size)
64028+{
64029+ struct inode *inode = dentry->d_inode;
64030+ ssize_t error;
64031+
64032+ error = inode_permission(inode, MAY_EXEC);
64033+ if (error)
64034+ return error;
64035+
64036+ if (inode->i_op->getxattr)
64037+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
64038+ else
64039+ error = -EOPNOTSUPP;
64040+
64041+ return error;
64042+}
64043+EXPORT_SYMBOL(pax_getxattr);
64044+#endif
64045+
64046 ssize_t
64047 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
64048 {
64049@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
64050 * Extended attribute SET operations
64051 */
64052 static long
64053-setxattr(struct dentry *d, const char __user *name, const void __user *value,
64054+setxattr(struct path *path, const char __user *name, const void __user *value,
64055 size_t size, int flags)
64056 {
64057 int error;
64058@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
64059 posix_acl_fix_xattr_from_user(kvalue, size);
64060 }
64061
64062- error = vfs_setxattr(d, kname, kvalue, size, flags);
64063+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
64064+ error = -EACCES;
64065+ goto out;
64066+ }
64067+
64068+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
64069 out:
64070 if (vvalue)
64071 vfree(vvalue);
64072@@ -377,7 +403,7 @@ retry:
64073 return error;
64074 error = mnt_want_write(path.mnt);
64075 if (!error) {
64076- error = setxattr(path.dentry, name, value, size, flags);
64077+ error = setxattr(&path, name, value, size, flags);
64078 mnt_drop_write(path.mnt);
64079 }
64080 path_put(&path);
64081@@ -401,7 +427,7 @@ retry:
64082 return error;
64083 error = mnt_want_write(path.mnt);
64084 if (!error) {
64085- error = setxattr(path.dentry, name, value, size, flags);
64086+ error = setxattr(&path, name, value, size, flags);
64087 mnt_drop_write(path.mnt);
64088 }
64089 path_put(&path);
64090@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
64091 const void __user *,value, size_t, size, int, flags)
64092 {
64093 struct fd f = fdget(fd);
64094- struct dentry *dentry;
64095 int error = -EBADF;
64096
64097 if (!f.file)
64098 return error;
64099- dentry = f.file->f_path.dentry;
64100- audit_inode(NULL, dentry, 0);
64101+ audit_inode(NULL, f.file->f_path.dentry, 0);
64102 error = mnt_want_write_file(f.file);
64103 if (!error) {
64104- error = setxattr(dentry, name, value, size, flags);
64105+ error = setxattr(&f.file->f_path, name, value, size, flags);
64106 mnt_drop_write_file(f.file);
64107 }
64108 fdput(f);
64109@@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
64110 * Extended attribute REMOVE operations
64111 */
64112 static long
64113-removexattr(struct dentry *d, const char __user *name)
64114+removexattr(struct path *path, const char __user *name)
64115 {
64116 int error;
64117 char kname[XATTR_NAME_MAX + 1];
64118@@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
64119 if (error < 0)
64120 return error;
64121
64122- return vfs_removexattr(d, kname);
64123+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
64124+ return -EACCES;
64125+
64126+ return vfs_removexattr(path->dentry, kname);
64127 }
64128
64129 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
64130@@ -652,7 +679,7 @@ retry:
64131 return error;
64132 error = mnt_want_write(path.mnt);
64133 if (!error) {
64134- error = removexattr(path.dentry, name);
64135+ error = removexattr(&path, name);
64136 mnt_drop_write(path.mnt);
64137 }
64138 path_put(&path);
64139@@ -675,7 +702,7 @@ retry:
64140 return error;
64141 error = mnt_want_write(path.mnt);
64142 if (!error) {
64143- error = removexattr(path.dentry, name);
64144+ error = removexattr(&path, name);
64145 mnt_drop_write(path.mnt);
64146 }
64147 path_put(&path);
64148@@ -689,16 +716,16 @@ retry:
64149 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
64150 {
64151 struct fd f = fdget(fd);
64152- struct dentry *dentry;
64153+ struct path *path;
64154 int error = -EBADF;
64155
64156 if (!f.file)
64157 return error;
64158- dentry = f.file->f_path.dentry;
64159- audit_inode(NULL, dentry, 0);
64160+ path = &f.file->f_path;
64161+ audit_inode(NULL, path->dentry, 0);
64162 error = mnt_want_write_file(f.file);
64163 if (!error) {
64164- error = removexattr(dentry, name);
64165+ error = removexattr(path, name);
64166 mnt_drop_write_file(f.file);
64167 }
64168 fdput(f);
64169diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
64170index 9fbea87..6b19972 100644
64171--- a/fs/xattr_acl.c
64172+++ b/fs/xattr_acl.c
64173@@ -76,8 +76,8 @@ struct posix_acl *
64174 posix_acl_from_xattr(struct user_namespace *user_ns,
64175 const void *value, size_t size)
64176 {
64177- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
64178- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
64179+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
64180+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
64181 int count;
64182 struct posix_acl *acl;
64183 struct posix_acl_entry *acl_e;
64184diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
64185index 3b2c14b..de031fe 100644
64186--- a/fs/xfs/xfs_bmap.c
64187+++ b/fs/xfs/xfs_bmap.c
64188@@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
64189
64190 #else
64191 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
64192-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
64193+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
64194 #endif /* DEBUG */
64195
64196 /*
64197diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
64198index c4e50c6..8ba93e3 100644
64199--- a/fs/xfs/xfs_dir2_readdir.c
64200+++ b/fs/xfs/xfs_dir2_readdir.c
64201@@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
64202 ino = dp->d_ops->sf_get_ino(sfp, sfep);
64203 filetype = dp->d_ops->sf_get_ftype(sfep);
64204 ctx->pos = off & 0x7fffffff;
64205- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
64206+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
64207+ char name[sfep->namelen];
64208+ memcpy(name, sfep->name, sfep->namelen);
64209+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
64210+ return 0;
64211+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
64212 xfs_dir3_get_dtype(mp, filetype)))
64213 return 0;
64214 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
64215diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
64216index 33ad9a7..82c18ba 100644
64217--- a/fs/xfs/xfs_ioctl.c
64218+++ b/fs/xfs/xfs_ioctl.c
64219@@ -126,7 +126,7 @@ xfs_find_handle(
64220 }
64221
64222 error = -EFAULT;
64223- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
64224+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
64225 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
64226 goto out_put;
64227
64228diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
64229index 104455b..764c512 100644
64230--- a/fs/xfs/xfs_iops.c
64231+++ b/fs/xfs/xfs_iops.c
64232@@ -397,7 +397,7 @@ xfs_vn_put_link(
64233 struct nameidata *nd,
64234 void *p)
64235 {
64236- char *s = nd_get_link(nd);
64237+ const char *s = nd_get_link(nd);
64238
64239 if (!IS_ERR(s))
64240 kfree(s);
64241diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
64242new file mode 100644
64243index 0000000..e98584b
64244--- /dev/null
64245+++ b/grsecurity/Kconfig
64246@@ -0,0 +1,1147 @@
64247+#
64248+# grecurity configuration
64249+#
64250+menu "Memory Protections"
64251+depends on GRKERNSEC
64252+
64253+config GRKERNSEC_KMEM
64254+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
64255+ default y if GRKERNSEC_CONFIG_AUTO
64256+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
64257+ help
64258+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
64259+ be written to or read from to modify or leak the contents of the running
64260+ kernel. /dev/port will also not be allowed to be opened, and support
64261+ for /dev/cpu/*/msr and kexec will be removed. If you have module
64262+ support disabled, enabling this will close up six ways that are
64263+ currently used to insert malicious code into the running kernel.
64264+
64265+ Even with this feature enabled, we still highly recommend that
64266+ you use the RBAC system, as it is still possible for an attacker to
64267+ modify the running kernel through other more obscure methods.
64268+
64269+ Enabling this feature will prevent the "cpupower" and "powertop" tools
64270+ from working.
64271+
64272+ It is highly recommended that you say Y here if you meet all the
64273+ conditions above.
64274+
64275+config GRKERNSEC_VM86
64276+ bool "Restrict VM86 mode"
64277+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
64278+ depends on X86_32
64279+
64280+ help
64281+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
64282+ make use of a special execution mode on 32bit x86 processors called
64283+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
64284+ video cards and will still work with this option enabled. The purpose
64285+ of the option is to prevent exploitation of emulation errors in
64286+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
64287+ Nearly all users should be able to enable this option.
64288+
64289+config GRKERNSEC_IO
64290+ bool "Disable privileged I/O"
64291+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
64292+ depends on X86
64293+ select RTC_CLASS
64294+ select RTC_INTF_DEV
64295+ select RTC_DRV_CMOS
64296+
64297+ help
64298+ If you say Y here, all ioperm and iopl calls will return an error.
64299+ Ioperm and iopl can be used to modify the running kernel.
64300+ Unfortunately, some programs need this access to operate properly,
64301+ the most notable of which are XFree86 and hwclock. hwclock can be
64302+ remedied by having RTC support in the kernel, so real-time
64303+ clock support is enabled if this option is enabled, to ensure
64304+ that hwclock operates correctly.
64305+
64306+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
64307+ you may not be able to boot into a graphical environment with this
64308+ option enabled. In this case, you should use the RBAC system instead.
64309+
64310+config GRKERNSEC_JIT_HARDEN
64311+ bool "Harden BPF JIT against spray attacks"
64312+ default y if GRKERNSEC_CONFIG_AUTO
64313+ depends on BPF_JIT && X86
64314+ help
64315+ If you say Y here, the native code generated by the kernel's Berkeley
64316+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
64317+ attacks that attempt to fit attacker-beneficial instructions in
64318+ 32bit immediate fields of JIT-generated native instructions. The
64319+ attacker will generally aim to cause an unintended instruction sequence
64320+ of JIT-generated native code to execute by jumping into the middle of
64321+ a generated instruction. This feature effectively randomizes the 32bit
64322+ immediate constants present in the generated code to thwart such attacks.
64323+
64324+ If you're using KERNEXEC, it's recommended that you enable this option
64325+ to supplement the hardening of the kernel.
64326+
64327+config GRKERNSEC_PERF_HARDEN
64328+ bool "Disable unprivileged PERF_EVENTS usage by default"
64329+ default y if GRKERNSEC_CONFIG_AUTO
64330+ depends on PERF_EVENTS
64331+ help
64332+ If you say Y here, the range of acceptable values for the
64333+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
64334+ default to a new value: 3. When the sysctl is set to this value, no
64335+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
64336+
64337+ Though PERF_EVENTS can be used legitimately for performance monitoring
64338+ and low-level application profiling, it is forced on regardless of
64339+ configuration, has been at fault for several vulnerabilities, and
64340+ creates new opportunities for side channels and other information leaks.
64341+
64342+ This feature puts PERF_EVENTS into a secure default state and permits
64343+ the administrator to change out of it temporarily if unprivileged
64344+ application profiling is needed.
64345+
64346+config GRKERNSEC_RAND_THREADSTACK
64347+ bool "Insert random gaps between thread stacks"
64348+ default y if GRKERNSEC_CONFIG_AUTO
64349+ depends on PAX_RANDMMAP && !PPC
64350+ help
64351+ If you say Y here, a random-sized gap will be enforced between allocated
64352+ thread stacks. Glibc's NPTL and other threading libraries that
64353+ pass MAP_STACK to the kernel for thread stack allocation are supported.
64354+ The implementation currently provides 8 bits of entropy for the gap.
64355+
64356+ Many distributions do not compile threaded remote services with the
64357+ -fstack-check argument to GCC, causing the variable-sized stack-based
64358+ allocator, alloca(), to not probe the stack on allocation. This
64359+ permits an unbounded alloca() to skip over any guard page and potentially
64360+ modify another thread's stack reliably. An enforced random gap
64361+ reduces the reliability of such an attack and increases the chance
64362+ that such a read/write to another thread's stack instead lands in
64363+ an unmapped area, causing a crash and triggering grsecurity's
64364+ anti-bruteforcing logic.
64365+
64366+config GRKERNSEC_PROC_MEMMAP
64367+ bool "Harden ASLR against information leaks and entropy reduction"
64368+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
64369+ depends on PAX_NOEXEC || PAX_ASLR
64370+ help
64371+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
64372+ give no information about the addresses of its mappings if
64373+ PaX features that rely on random addresses are enabled on the task.
64374+ In addition to sanitizing this information and disabling other
64375+ dangerous sources of information, this option causes reads of sensitive
64376+ /proc/<pid> entries where the file descriptor was opened in a different
64377+ task than the one performing the read. Such attempts are logged.
64378+ This option also limits argv/env strings for suid/sgid binaries
64379+ to 512KB to prevent a complete exhaustion of the stack entropy provided
64380+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
64381+ binaries to prevent alternative mmap layouts from being abused.
64382+
64383+ If you use PaX it is essential that you say Y here as it closes up
64384+ several holes that make full ASLR useless locally.
64385+
64386+config GRKERNSEC_BRUTE
64387+ bool "Deter exploit bruteforcing"
64388+ default y if GRKERNSEC_CONFIG_AUTO
64389+ help
64390+ If you say Y here, attempts to bruteforce exploits against forking
64391+ daemons such as apache or sshd, as well as against suid/sgid binaries
64392+ will be deterred. When a child of a forking daemon is killed by PaX
64393+ or crashes due to an illegal instruction or other suspicious signal,
64394+ the parent process will be delayed 30 seconds upon every subsequent
64395+ fork until the administrator is able to assess the situation and
64396+ restart the daemon.
64397+ In the suid/sgid case, the attempt is logged, the user has all their
64398+ existing instances of the suid/sgid binary terminated and will
64399+ be unable to execute any suid/sgid binaries for 15 minutes.
64400+
64401+ It is recommended that you also enable signal logging in the auditing
64402+ section so that logs are generated when a process triggers a suspicious
64403+ signal.
64404+ If the sysctl option is enabled, a sysctl option with name
64405+ "deter_bruteforce" is created.
64406+
64407+config GRKERNSEC_MODHARDEN
64408+ bool "Harden module auto-loading"
64409+ default y if GRKERNSEC_CONFIG_AUTO
64410+ depends on MODULES
64411+ help
64412+ If you say Y here, module auto-loading in response to use of some
64413+ feature implemented by an unloaded module will be restricted to
64414+ root users. Enabling this option helps defend against attacks
64415+ by unprivileged users who abuse the auto-loading behavior to
64416+ cause a vulnerable module to load that is then exploited.
64417+
64418+ If this option prevents a legitimate use of auto-loading for a
64419+ non-root user, the administrator can execute modprobe manually
64420+ with the exact name of the module mentioned in the alert log.
64421+ Alternatively, the administrator can add the module to the list
64422+ of modules loaded at boot by modifying init scripts.
64423+
64424+ Modification of init scripts will most likely be needed on
64425+ Ubuntu servers with encrypted home directory support enabled,
64426+ as the first non-root user logging in will cause the ecb(aes),
64427+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
64428+
64429+config GRKERNSEC_HIDESYM
64430+ bool "Hide kernel symbols"
64431+ default y if GRKERNSEC_CONFIG_AUTO
64432+ select PAX_USERCOPY_SLABS
64433+ help
64434+ If you say Y here, getting information on loaded modules, and
64435+ displaying all kernel symbols through a syscall will be restricted
64436+ to users with CAP_SYS_MODULE. For software compatibility reasons,
64437+ /proc/kallsyms will be restricted to the root user. The RBAC
64438+ system can hide that entry even from root.
64439+
64440+ This option also prevents leaking of kernel addresses through
64441+ several /proc entries.
64442+
64443+ Note that this option is only effective provided the following
64444+ conditions are met:
64445+ 1) The kernel using grsecurity is not precompiled by some distribution
64446+ 2) You have also enabled GRKERNSEC_DMESG
64447+ 3) You are using the RBAC system and hiding other files such as your
64448+ kernel image and System.map. Alternatively, enabling this option
64449+ causes the permissions on /boot, /lib/modules, and the kernel
64450+ source directory to change at compile time to prevent
64451+ reading by non-root users.
64452+ If the above conditions are met, this option will aid in providing a
64453+ useful protection against local kernel exploitation of overflows
64454+ and arbitrary read/write vulnerabilities.
64455+
64456+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
64457+ in addition to this feature.
64458+
64459+config GRKERNSEC_RANDSTRUCT
64460+ bool "Randomize layout of sensitive kernel structures"
64461+ default y if GRKERNSEC_CONFIG_AUTO
64462+ select GRKERNSEC_HIDESYM
64463+ select MODVERSIONS if MODULES
64464+ help
64465+ If you say Y here, the layouts of a number of sensitive kernel
64466+ structures (task, fs, cred, etc) and all structures composed entirely
64467+ of function pointers (aka "ops" structs) will be randomized at compile-time.
64468+ This can introduce the requirement of an additional infoleak
64469+ vulnerability for exploits targeting these structure types.
64470+
64471+ Enabling this feature will introduce some performance impact, slightly
64472+ increase memory usage, and prevent the use of forensic tools like
64473+ Volatility against the system (unless the kernel source tree isn't
64474+ cleaned after kernel installation).
64475+
64476+ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
64477+ It remains after a make clean to allow for external modules to be compiled
64478+ with the existing seed and will be removed by a make mrproper or
64479+ make distclean.
64480+
64481+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
64482+ bool "Use cacheline-aware structure randomization"
64483+ depends on GRKERNSEC_RANDSTRUCT
64484+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
64485+ help
64486+ If you say Y here, the RANDSTRUCT randomization will make a best effort
64487+ at restricting randomization to cacheline-sized groups of elements. It
64488+ will further not randomize bitfields in structures. This reduces the
64489+ performance hit of RANDSTRUCT at the cost of weakened randomization.
64490+
64491+config GRKERNSEC_KERN_LOCKOUT
64492+ bool "Active kernel exploit response"
64493+ default y if GRKERNSEC_CONFIG_AUTO
64494+ depends on X86 || ARM || PPC || SPARC
64495+ help
64496+ If you say Y here, when a PaX alert is triggered due to suspicious
64497+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
64498+ or an OOPS occurs due to bad memory accesses, instead of just
64499+ terminating the offending process (and potentially allowing
64500+ a subsequent exploit from the same user), we will take one of two
64501+ actions:
64502+ If the user was root, we will panic the system
64503+ If the user was non-root, we will log the attempt, terminate
64504+ all processes owned by the user, then prevent them from creating
64505+ any new processes until the system is restarted
64506+ This deters repeated kernel exploitation/bruteforcing attempts
64507+ and is useful for later forensics.
64508+
64509+config GRKERNSEC_OLD_ARM_USERLAND
64510+ bool "Old ARM userland compatibility"
64511+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
64512+ help
64513+ If you say Y here, stubs of executable code to perform such operations
64514+ as "compare-exchange" will be placed at fixed locations in the ARM vector
64515+ table. This is unfortunately needed for old ARM userland meant to run
64516+ across a wide range of processors. Without this option enabled,
64517+ the get_tls and data memory barrier stubs will be emulated by the kernel,
64518+ which is enough for Linaro userlands or other userlands designed for v6
64519+ and newer ARM CPUs. It's recommended that you try without this option enabled
64520+ first, and only enable it if your userland does not boot (it will likely fail
64521+ at init time).
64522+
64523+endmenu
64524+menu "Role Based Access Control Options"
64525+depends on GRKERNSEC
64526+
64527+config GRKERNSEC_RBAC_DEBUG
64528+ bool
64529+
64530+config GRKERNSEC_NO_RBAC
64531+ bool "Disable RBAC system"
64532+ help
64533+ If you say Y here, the /dev/grsec device will be removed from the kernel,
64534+ preventing the RBAC system from being enabled. You should only say Y
64535+ here if you have no intention of using the RBAC system, so as to prevent
64536+ an attacker with root access from misusing the RBAC system to hide files
64537+ and processes when loadable module support and /dev/[k]mem have been
64538+ locked down.
64539+
64540+config GRKERNSEC_ACL_HIDEKERN
64541+ bool "Hide kernel processes"
64542+ help
64543+ If you say Y here, all kernel threads will be hidden to all
64544+ processes but those whose subject has the "view hidden processes"
64545+ flag.
64546+
64547+config GRKERNSEC_ACL_MAXTRIES
64548+ int "Maximum tries before password lockout"
64549+ default 3
64550+ help
64551+ This option enforces the maximum number of times a user can attempt
64552+ to authorize themselves with the grsecurity RBAC system before being
64553+ denied the ability to attempt authorization again for a specified time.
64554+ The lower the number, the harder it will be to brute-force a password.
64555+
64556+config GRKERNSEC_ACL_TIMEOUT
64557+ int "Time to wait after max password tries, in seconds"
64558+ default 30
64559+ help
64560+ This option specifies the time the user must wait after attempting to
64561+ authorize to the RBAC system with the maximum number of invalid
64562+ passwords. The higher the number, the harder it will be to brute-force
64563+ a password.
64564+
64565+endmenu
64566+menu "Filesystem Protections"
64567+depends on GRKERNSEC
64568+
64569+config GRKERNSEC_PROC
64570+ bool "Proc restrictions"
64571+ default y if GRKERNSEC_CONFIG_AUTO
64572+ help
64573+ If you say Y here, the permissions of the /proc filesystem
64574+ will be altered to enhance system security and privacy. You MUST
64575+ choose either a user only restriction or a user and group restriction.
64576+ Depending upon the option you choose, you can either restrict users to
64577+ see only the processes they themselves run, or choose a group that can
64578+ view all processes and files normally restricted to root if you choose
64579+ the "restrict to user only" option. NOTE: If you're running identd or
64580+ ntpd as a non-root user, you will have to run it as the group you
64581+ specify here.
64582+
64583+config GRKERNSEC_PROC_USER
64584+ bool "Restrict /proc to user only"
64585+ depends on GRKERNSEC_PROC
64586+ help
64587+ If you say Y here, non-root users will only be able to view their own
64588+ processes, and restricts them from viewing network-related information,
64589+ and viewing kernel symbol and module information.
64590+
64591+config GRKERNSEC_PROC_USERGROUP
64592+ bool "Allow special group"
64593+ default y if GRKERNSEC_CONFIG_AUTO
64594+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
64595+ help
64596+ If you say Y here, you will be able to select a group that will be
64597+ able to view all processes and network-related information. If you've
64598+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
64599+ remain hidden. This option is useful if you want to run identd as
64600+ a non-root user. The group you select may also be chosen at boot time
64601+ via "grsec_proc_gid=" on the kernel commandline.
64602+
64603+config GRKERNSEC_PROC_GID
64604+ int "GID for special group"
64605+ depends on GRKERNSEC_PROC_USERGROUP
64606+ default 1001
64607+
64608+config GRKERNSEC_PROC_ADD
64609+ bool "Additional restrictions"
64610+ default y if GRKERNSEC_CONFIG_AUTO
64611+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
64612+ help
64613+ If you say Y here, additional restrictions will be placed on
64614+ /proc that keep normal users from viewing device information and
64615+ slabinfo information that could be useful for exploits.
64616+
64617+config GRKERNSEC_LINK
64618+ bool "Linking restrictions"
64619+ default y if GRKERNSEC_CONFIG_AUTO
64620+ help
64621+ If you say Y here, /tmp race exploits will be prevented, since users
64622+ will no longer be able to follow symlinks owned by other users in
64623+ world-writable +t directories (e.g. /tmp), unless the owner of the
64624+ symlink is the owner of the directory. users will also not be
64625+ able to hardlink to files they do not own. If the sysctl option is
64626+ enabled, a sysctl option with name "linking_restrictions" is created.
64627+
64628+config GRKERNSEC_SYMLINKOWN
64629+ bool "Kernel-enforced SymlinksIfOwnerMatch"
64630+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
64631+ help
64632+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
64633+ that prevents it from being used as a security feature. As Apache
64634+ verifies the symlink by performing a stat() against the target of
64635+ the symlink before it is followed, an attacker can setup a symlink
64636+ to point to a same-owned file, then replace the symlink with one
64637+ that targets another user's file just after Apache "validates" the
64638+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
64639+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
64640+ will be in place for the group you specify. If the sysctl option
64641+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
64642+ created.
64643+
64644+config GRKERNSEC_SYMLINKOWN_GID
64645+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
64646+ depends on GRKERNSEC_SYMLINKOWN
64647+ default 1006
64648+ help
64649+ Setting this GID determines what group kernel-enforced
64650+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
64651+ is enabled, a sysctl option with name "symlinkown_gid" is created.
64652+
64653+config GRKERNSEC_FIFO
64654+ bool "FIFO restrictions"
64655+ default y if GRKERNSEC_CONFIG_AUTO
64656+ help
64657+ If you say Y here, users will not be able to write to FIFOs they don't
64658+ own in world-writable +t directories (e.g. /tmp), unless the owner of
64659+ the FIFO is the same owner of the directory it's held in. If the sysctl
64660+ option is enabled, a sysctl option with name "fifo_restrictions" is
64661+ created.
64662+
64663+config GRKERNSEC_SYSFS_RESTRICT
64664+ bool "Sysfs/debugfs restriction"
64665+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
64666+ depends on SYSFS
64667+ help
64668+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
64669+ any filesystem normally mounted under it (e.g. debugfs) will be
64670+ mostly accessible only by root. These filesystems generally provide access
64671+ to hardware and debug information that isn't appropriate for unprivileged
64672+ users of the system. Sysfs and debugfs have also become a large source
64673+ of new vulnerabilities, ranging from infoleaks to local compromise.
64674+ There has been very little oversight with an eye toward security involved
64675+ in adding new exporters of information to these filesystems, so their
64676+ use is discouraged.
64677+ For reasons of compatibility, a few directories have been whitelisted
64678+ for access by non-root users:
64679+ /sys/fs/selinux
64680+ /sys/fs/fuse
64681+ /sys/devices/system/cpu
64682+
64683+config GRKERNSEC_ROFS
64684+ bool "Runtime read-only mount protection"
64685+ depends on SYSCTL
64686+ help
64687+ If you say Y here, a sysctl option with name "romount_protect" will
64688+ be created. By setting this option to 1 at runtime, filesystems
64689+ will be protected in the following ways:
64690+ * No new writable mounts will be allowed
64691+ * Existing read-only mounts won't be able to be remounted read/write
64692+ * Write operations will be denied on all block devices
64693+ This option acts independently of grsec_lock: once it is set to 1,
64694+ it cannot be turned off. Therefore, please be mindful of the resulting
64695+ behavior if this option is enabled in an init script on a read-only
64696+ filesystem.
64697+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
64698+ and GRKERNSEC_IO should be enabled and module loading disabled via
64699+ config or at runtime.
64700+ This feature is mainly intended for secure embedded systems.
64701+
64702+
64703+config GRKERNSEC_DEVICE_SIDECHANNEL
64704+ bool "Eliminate stat/notify-based device sidechannels"
64705+ default y if GRKERNSEC_CONFIG_AUTO
64706+ help
64707+ If you say Y here, timing analyses on block or character
64708+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
64709+ will be thwarted for unprivileged users. If a process without
64710+ CAP_MKNOD stats such a device, the last access and last modify times
64711+ will match the device's create time. No access or modify events
64712+ will be triggered through inotify/dnotify/fanotify for such devices.
64713+ This feature will prevent attacks that may at a minimum
64714+ allow an attacker to determine the administrator's password length.
64715+
64716+config GRKERNSEC_CHROOT
64717+ bool "Chroot jail restrictions"
64718+ default y if GRKERNSEC_CONFIG_AUTO
64719+ help
64720+ If you say Y here, you will be able to choose several options that will
64721+ make breaking out of a chrooted jail much more difficult. If you
64722+ encounter no software incompatibilities with the following options, it
64723+ is recommended that you enable each one.
64724+
64725+config GRKERNSEC_CHROOT_MOUNT
64726+ bool "Deny mounts"
64727+ default y if GRKERNSEC_CONFIG_AUTO
64728+ depends on GRKERNSEC_CHROOT
64729+ help
64730+ If you say Y here, processes inside a chroot will not be able to
64731+ mount or remount filesystems. If the sysctl option is enabled, a
64732+ sysctl option with name "chroot_deny_mount" is created.
64733+
64734+config GRKERNSEC_CHROOT_DOUBLE
64735+ bool "Deny double-chroots"
64736+ default y if GRKERNSEC_CONFIG_AUTO
64737+ depends on GRKERNSEC_CHROOT
64738+ help
64739+ If you say Y here, processes inside a chroot will not be able to chroot
64740+ again outside the chroot. This is a widely used method of breaking
64741+ out of a chroot jail and should not be allowed. If the sysctl
64742+ option is enabled, a sysctl option with name
64743+ "chroot_deny_chroot" is created.
64744+
64745+config GRKERNSEC_CHROOT_PIVOT
64746+ bool "Deny pivot_root in chroot"
64747+ default y if GRKERNSEC_CONFIG_AUTO
64748+ depends on GRKERNSEC_CHROOT
64749+ help
64750+ If you say Y here, processes inside a chroot will not be able to use
64751+ a function called pivot_root() that was introduced in Linux 2.3.41. It
64752+ works similar to chroot in that it changes the root filesystem. This
64753+ function could be misused in a chrooted process to attempt to break out
64754+ of the chroot, and therefore should not be allowed. If the sysctl
64755+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
64756+ created.
64757+
64758+config GRKERNSEC_CHROOT_CHDIR
64759+ bool "Enforce chdir(\"/\") on all chroots"
64760+ default y if GRKERNSEC_CONFIG_AUTO
64761+ depends on GRKERNSEC_CHROOT
64762+ help
64763+ If you say Y here, the current working directory of all newly-chrooted
64764+ applications will be set to the the root directory of the chroot.
64765+ The man page on chroot(2) states:
64766+ Note that this call does not change the current working
64767+ directory, so that `.' can be outside the tree rooted at
64768+ `/'. In particular, the super-user can escape from a
64769+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
64770+
64771+ It is recommended that you say Y here, since it's not known to break
64772+ any software. If the sysctl option is enabled, a sysctl option with
64773+ name "chroot_enforce_chdir" is created.
64774+
64775+config GRKERNSEC_CHROOT_CHMOD
64776+ bool "Deny (f)chmod +s"
64777+ default y if GRKERNSEC_CONFIG_AUTO
64778+ depends on GRKERNSEC_CHROOT
64779+ help
64780+ If you say Y here, processes inside a chroot will not be able to chmod
64781+ or fchmod files to make them have suid or sgid bits. This protects
64782+ against another published method of breaking a chroot. If the sysctl
64783+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
64784+ created.
64785+
64786+config GRKERNSEC_CHROOT_FCHDIR
64787+ bool "Deny fchdir out of chroot"
64788+ default y if GRKERNSEC_CONFIG_AUTO
64789+ depends on GRKERNSEC_CHROOT
64790+ help
64791+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
64792+ to a file descriptor of the chrooting process that points to a directory
64793+ outside the filesystem will be stopped. If the sysctl option
64794+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
64795+
64796+config GRKERNSEC_CHROOT_MKNOD
64797+ bool "Deny mknod"
64798+ default y if GRKERNSEC_CONFIG_AUTO
64799+ depends on GRKERNSEC_CHROOT
64800+ help
64801+ If you say Y here, processes inside a chroot will not be allowed to
64802+ mknod. The problem with using mknod inside a chroot is that it
64803+ would allow an attacker to create a device entry that is the same
64804+ as one on the physical root of your system, which could range from
64805+ anything from the console device to a device for your harddrive (which
64806+ they could then use to wipe the drive or steal data). It is recommended
64807+ that you say Y here, unless you run into software incompatibilities.
64808+ If the sysctl option is enabled, a sysctl option with name
64809+ "chroot_deny_mknod" is created.
64810+
64811+config GRKERNSEC_CHROOT_SHMAT
64812+ bool "Deny shmat() out of chroot"
64813+ default y if GRKERNSEC_CONFIG_AUTO
64814+ depends on GRKERNSEC_CHROOT
64815+ help
64816+ If you say Y here, processes inside a chroot will not be able to attach
64817+ to shared memory segments that were created outside of the chroot jail.
64818+ It is recommended that you say Y here. If the sysctl option is enabled,
64819+ a sysctl option with name "chroot_deny_shmat" is created.
64820+
64821+config GRKERNSEC_CHROOT_UNIX
64822+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
64823+ default y if GRKERNSEC_CONFIG_AUTO
64824+ depends on GRKERNSEC_CHROOT
64825+ help
64826+ If you say Y here, processes inside a chroot will not be able to
64827+ connect to abstract (meaning not belonging to a filesystem) Unix
64828+ domain sockets that were bound outside of a chroot. It is recommended
64829+ that you say Y here. If the sysctl option is enabled, a sysctl option
64830+ with name "chroot_deny_unix" is created.
64831+
64832+config GRKERNSEC_CHROOT_FINDTASK
64833+ bool "Protect outside processes"
64834+ default y if GRKERNSEC_CONFIG_AUTO
64835+ depends on GRKERNSEC_CHROOT
64836+ help
64837+ If you say Y here, processes inside a chroot will not be able to
64838+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
64839+ getsid, or view any process outside of the chroot. If the sysctl
64840+ option is enabled, a sysctl option with name "chroot_findtask" is
64841+ created.
64842+
64843+config GRKERNSEC_CHROOT_NICE
64844+ bool "Restrict priority changes"
64845+ default y if GRKERNSEC_CONFIG_AUTO
64846+ depends on GRKERNSEC_CHROOT
64847+ help
64848+ If you say Y here, processes inside a chroot will not be able to raise
64849+ the priority of processes in the chroot, or alter the priority of
64850+ processes outside the chroot. This provides more security than simply
64851+ removing CAP_SYS_NICE from the process' capability set. If the
64852+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
64853+ is created.
64854+
64855+config GRKERNSEC_CHROOT_SYSCTL
64856+ bool "Deny sysctl writes"
64857+ default y if GRKERNSEC_CONFIG_AUTO
64858+ depends on GRKERNSEC_CHROOT
64859+ help
64860+ If you say Y here, an attacker in a chroot will not be able to
64861+ write to sysctl entries, either by sysctl(2) or through a /proc
64862+ interface. It is strongly recommended that you say Y here. If the
64863+ sysctl option is enabled, a sysctl option with name
64864+ "chroot_deny_sysctl" is created.
64865+
64866+config GRKERNSEC_CHROOT_CAPS
64867+ bool "Capability restrictions"
64868+ default y if GRKERNSEC_CONFIG_AUTO
64869+ depends on GRKERNSEC_CHROOT
64870+ help
64871+ If you say Y here, the capabilities on all processes within a
64872+ chroot jail will be lowered to stop module insertion, raw i/o,
64873+ system and net admin tasks, rebooting the system, modifying immutable
64874+ files, modifying IPC owned by another, and changing the system time.
64875+ This is left an option because it can break some apps. Disable this
64876+ if your chrooted apps are having problems performing those kinds of
64877+ tasks. If the sysctl option is enabled, a sysctl option with
64878+ name "chroot_caps" is created.
64879+
64880+config GRKERNSEC_CHROOT_INITRD
64881+ bool "Exempt initrd tasks from restrictions"
64882+ default y if GRKERNSEC_CONFIG_AUTO
64883+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
64884+ help
64885+ If you say Y here, tasks started prior to init will be exempted from
64886+ grsecurity's chroot restrictions. This option is mainly meant to
64887+ resolve Plymouth's performing privileged operations unnecessarily
64888+ in a chroot.
64889+
64890+endmenu
64891+menu "Kernel Auditing"
64892+depends on GRKERNSEC
64893+
64894+config GRKERNSEC_AUDIT_GROUP
64895+ bool "Single group for auditing"
64896+ help
64897+ If you say Y here, the exec and chdir logging features will only operate
64898+ on a group you specify. This option is recommended if you only want to
64899+ watch certain users instead of having a large amount of logs from the
64900+ entire system. If the sysctl option is enabled, a sysctl option with
64901+ name "audit_group" is created.
64902+
64903+config GRKERNSEC_AUDIT_GID
64904+ int "GID for auditing"
64905+ depends on GRKERNSEC_AUDIT_GROUP
64906+ default 1007
64907+
64908+config GRKERNSEC_EXECLOG
64909+ bool "Exec logging"
64910+ help
64911+ If you say Y here, all execve() calls will be logged (since the
64912+ other exec*() calls are frontends to execve(), all execution
64913+ will be logged). Useful for shell-servers that like to keep track
64914+ of their users. If the sysctl option is enabled, a sysctl option with
64915+ name "exec_logging" is created.
64916+ WARNING: This option when enabled will produce a LOT of logs, especially
64917+ on an active system.
64918+
64919+config GRKERNSEC_RESLOG
64920+ bool "Resource logging"
64921+ default y if GRKERNSEC_CONFIG_AUTO
64922+ help
64923+ If you say Y here, all attempts to overstep resource limits will
64924+ be logged with the resource name, the requested size, and the current
64925+ limit. It is highly recommended that you say Y here. If the sysctl
64926+ option is enabled, a sysctl option with name "resource_logging" is
64927+ created. If the RBAC system is enabled, the sysctl value is ignored.
64928+
64929+config GRKERNSEC_CHROOT_EXECLOG
64930+ bool "Log execs within chroot"
64931+ help
64932+ If you say Y here, all executions inside a chroot jail will be logged
64933+ to syslog. This can cause a large amount of logs if certain
64934+ applications (eg. djb's daemontools) are installed on the system, and
64935+ is therefore left as an option. If the sysctl option is enabled, a
64936+ sysctl option with name "chroot_execlog" is created.
64937+
64938+config GRKERNSEC_AUDIT_PTRACE
64939+ bool "Ptrace logging"
64940+ help
64941+ If you say Y here, all attempts to attach to a process via ptrace
64942+ will be logged. If the sysctl option is enabled, a sysctl option
64943+ with name "audit_ptrace" is created.
64944+
64945+config GRKERNSEC_AUDIT_CHDIR
64946+ bool "Chdir logging"
64947+ help
64948+ If you say Y here, all chdir() calls will be logged. If the sysctl
64949+ option is enabled, a sysctl option with name "audit_chdir" is created.
64950+
64951+config GRKERNSEC_AUDIT_MOUNT
64952+ bool "(Un)Mount logging"
64953+ help
64954+ If you say Y here, all mounts and unmounts will be logged. If the
64955+ sysctl option is enabled, a sysctl option with name "audit_mount" is
64956+ created.
64957+
64958+config GRKERNSEC_SIGNAL
64959+ bool "Signal logging"
64960+ default y if GRKERNSEC_CONFIG_AUTO
64961+ help
64962+ If you say Y here, certain important signals will be logged, such as
64963+ SIGSEGV, which will as a result inform you of when a error in a program
64964+ occurred, which in some cases could mean a possible exploit attempt.
64965+ If the sysctl option is enabled, a sysctl option with name
64966+ "signal_logging" is created.
64967+
64968+config GRKERNSEC_FORKFAIL
64969+ bool "Fork failure logging"
64970+ help
64971+ If you say Y here, all failed fork() attempts will be logged.
64972+ This could suggest a fork bomb, or someone attempting to overstep
64973+ their process limit. If the sysctl option is enabled, a sysctl option
64974+ with name "forkfail_logging" is created.
64975+
64976+config GRKERNSEC_TIME
64977+ bool "Time change logging"
64978+ default y if GRKERNSEC_CONFIG_AUTO
64979+ help
64980+ If you say Y here, any changes of the system clock will be logged.
64981+ If the sysctl option is enabled, a sysctl option with name
64982+ "timechange_logging" is created.
64983+
64984+config GRKERNSEC_PROC_IPADDR
64985+ bool "/proc/<pid>/ipaddr support"
64986+ default y if GRKERNSEC_CONFIG_AUTO
64987+ help
64988+ If you say Y here, a new entry will be added to each /proc/<pid>
64989+ directory that contains the IP address of the person using the task.
64990+ The IP is carried across local TCP and AF_UNIX stream sockets.
64991+ This information can be useful for IDS/IPSes to perform remote response
64992+ to a local attack. The entry is readable by only the owner of the
64993+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
64994+ the RBAC system), and thus does not create privacy concerns.
64995+
64996+config GRKERNSEC_RWXMAP_LOG
64997+ bool 'Denied RWX mmap/mprotect logging'
64998+ default y if GRKERNSEC_CONFIG_AUTO
64999+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
65000+ help
65001+ If you say Y here, calls to mmap() and mprotect() with explicit
65002+ usage of PROT_WRITE and PROT_EXEC together will be logged when
65003+ denied by the PAX_MPROTECT feature. This feature will also
65004+ log other problematic scenarios that can occur when PAX_MPROTECT
65005+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
65006+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
65007+ is created.
65008+
65009+endmenu
65010+
65011+menu "Executable Protections"
65012+depends on GRKERNSEC
65013+
65014+config GRKERNSEC_DMESG
65015+ bool "Dmesg(8) restriction"
65016+ default y if GRKERNSEC_CONFIG_AUTO
65017+ help
65018+ If you say Y here, non-root users will not be able to use dmesg(8)
65019+ to view the contents of the kernel's circular log buffer.
65020+ The kernel's log buffer often contains kernel addresses and other
65021+ identifying information useful to an attacker in fingerprinting a
65022+ system for a targeted exploit.
65023+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
65024+ created.
65025+
65026+config GRKERNSEC_HARDEN_PTRACE
65027+ bool "Deter ptrace-based process snooping"
65028+ default y if GRKERNSEC_CONFIG_AUTO
65029+ help
65030+ If you say Y here, TTY sniffers and other malicious monitoring
65031+ programs implemented through ptrace will be defeated. If you
65032+ have been using the RBAC system, this option has already been
65033+ enabled for several years for all users, with the ability to make
65034+ fine-grained exceptions.
65035+
65036+ This option only affects the ability of non-root users to ptrace
65037+ processes that are not a descendent of the ptracing process.
65038+ This means that strace ./binary and gdb ./binary will still work,
65039+ but attaching to arbitrary processes will not. If the sysctl
65040+ option is enabled, a sysctl option with name "harden_ptrace" is
65041+ created.
65042+
65043+config GRKERNSEC_PTRACE_READEXEC
65044+ bool "Require read access to ptrace sensitive binaries"
65045+ default y if GRKERNSEC_CONFIG_AUTO
65046+ help
65047+ If you say Y here, unprivileged users will not be able to ptrace unreadable
65048+ binaries. This option is useful in environments that
65049+ remove the read bits (e.g. file mode 4711) from suid binaries to
65050+ prevent infoleaking of their contents. This option adds
65051+ consistency to the use of that file mode, as the binary could normally
65052+ be read out when run without privileges while ptracing.
65053+
65054+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
65055+ is created.
65056+
65057+config GRKERNSEC_SETXID
65058+ bool "Enforce consistent multithreaded privileges"
65059+ default y if GRKERNSEC_CONFIG_AUTO
65060+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
65061+ help
65062+ If you say Y here, a change from a root uid to a non-root uid
65063+ in a multithreaded application will cause the resulting uids,
65064+ gids, supplementary groups, and capabilities in that thread
65065+ to be propagated to the other threads of the process. In most
65066+ cases this is unnecessary, as glibc will emulate this behavior
65067+ on behalf of the application. Other libcs do not act in the
65068+ same way, allowing the other threads of the process to continue
65069+ running with root privileges. If the sysctl option is enabled,
65070+ a sysctl option with name "consistent_setxid" is created.
65071+
65072+config GRKERNSEC_HARDEN_IPC
65073+ bool "Disallow access to overly-permissive IPC objects"
65074+ default y if GRKERNSEC_CONFIG_AUTO
65075+ depends on SYSVIPC
65076+ help
65077+ If you say Y here, access to overly-permissive IPC objects (shared
65078+ memory, message queues, and semaphores) will be denied for processes
65079+ given the following criteria beyond normal permission checks:
65080+ 1) If the IPC object is world-accessible and the euid doesn't match
65081+ that of the creator or current uid for the IPC object
65082+ 2) If the IPC object is group-accessible and the egid doesn't
65083+ match that of the creator or current gid for the IPC object
65084+ It's a common error to grant too much permission to these objects,
65085+ with impact ranging from denial of service and information leaking to
65086+ privilege escalation. This feature was developed in response to
65087+ research by Tim Brown:
65088+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
65089+ who found hundreds of such insecure usages. Processes with
65090+ CAP_IPC_OWNER are still permitted to access these IPC objects.
65091+ If the sysctl option is enabled, a sysctl option with name
65092+ "harden_ipc" is created.
65093+
65094+config GRKERNSEC_TPE
65095+ bool "Trusted Path Execution (TPE)"
65096+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65097+ help
65098+ If you say Y here, you will be able to choose a gid to add to the
65099+ supplementary groups of users you want to mark as "untrusted."
65100+ These users will not be able to execute any files that are not in
65101+ root-owned directories writable only by root. If the sysctl option
65102+ is enabled, a sysctl option with name "tpe" is created.
65103+
65104+config GRKERNSEC_TPE_ALL
65105+ bool "Partially restrict all non-root users"
65106+ depends on GRKERNSEC_TPE
65107+ help
65108+ If you say Y here, all non-root users will be covered under
65109+ a weaker TPE restriction. This is separate from, and in addition to,
65110+ the main TPE options that you have selected elsewhere. Thus, if a
65111+ "trusted" GID is chosen, this restriction applies to even that GID.
65112+ Under this restriction, all non-root users will only be allowed to
65113+ execute files in directories they own that are not group or
65114+ world-writable, or in directories owned by root and writable only by
65115+ root. If the sysctl option is enabled, a sysctl option with name
65116+ "tpe_restrict_all" is created.
65117+
65118+config GRKERNSEC_TPE_INVERT
65119+ bool "Invert GID option"
65120+ depends on GRKERNSEC_TPE
65121+ help
65122+ If you say Y here, the group you specify in the TPE configuration will
65123+ decide what group TPE restrictions will be *disabled* for. This
65124+ option is useful if you want TPE restrictions to be applied to most
65125+ users on the system. If the sysctl option is enabled, a sysctl option
65126+ with name "tpe_invert" is created. Unlike other sysctl options, this
65127+ entry will default to on for backward-compatibility.
65128+
65129+config GRKERNSEC_TPE_GID
65130+ int
65131+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
65132+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
65133+
65134+config GRKERNSEC_TPE_UNTRUSTED_GID
65135+ int "GID for TPE-untrusted users"
65136+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
65137+ default 1005
65138+ help
65139+ Setting this GID determines what group TPE restrictions will be
65140+ *enabled* for. If the sysctl option is enabled, a sysctl option
65141+ with name "tpe_gid" is created.
65142+
65143+config GRKERNSEC_TPE_TRUSTED_GID
65144+ int "GID for TPE-trusted users"
65145+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
65146+ default 1005
65147+ help
65148+ Setting this GID determines what group TPE restrictions will be
65149+ *disabled* for. If the sysctl option is enabled, a sysctl option
65150+ with name "tpe_gid" is created.
65151+
65152+endmenu
65153+menu "Network Protections"
65154+depends on GRKERNSEC
65155+
65156+config GRKERNSEC_RANDNET
65157+ bool "Larger entropy pools"
65158+ default y if GRKERNSEC_CONFIG_AUTO
65159+ help
65160+ If you say Y here, the entropy pools used for many features of Linux
65161+ and grsecurity will be doubled in size. Since several grsecurity
65162+ features use additional randomness, it is recommended that you say Y
65163+ here. Saying Y here has a similar effect as modifying
65164+ /proc/sys/kernel/random/poolsize.
65165+
65166+config GRKERNSEC_BLACKHOLE
65167+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
65168+ default y if GRKERNSEC_CONFIG_AUTO
65169+ depends on NET
65170+ help
65171+ If you say Y here, neither TCP resets nor ICMP
65172+ destination-unreachable packets will be sent in response to packets
65173+ sent to ports for which no associated listening process exists.
65174+ This feature supports both IPV4 and IPV6 and exempts the
65175+ loopback interface from blackholing. Enabling this feature
65176+ makes a host more resilient to DoS attacks and reduces network
65177+ visibility against scanners.
65178+
65179+ The blackhole feature as-implemented is equivalent to the FreeBSD
65180+ blackhole feature, as it prevents RST responses to all packets, not
65181+ just SYNs. Under most application behavior this causes no
65182+ problems, but applications (like haproxy) may not close certain
65183+ connections in a way that cleanly terminates them on the remote
65184+ end, leaving the remote host in LAST_ACK state. Because of this
65185+ side-effect and to prevent intentional LAST_ACK DoSes, this
65186+ feature also adds automatic mitigation against such attacks.
65187+ The mitigation drastically reduces the amount of time a socket
65188+ can spend in LAST_ACK state. If you're using haproxy and not
65189+ all servers it connects to have this option enabled, consider
65190+ disabling this feature on the haproxy host.
65191+
65192+ If the sysctl option is enabled, two sysctl options with names
65193+ "ip_blackhole" and "lastack_retries" will be created.
65194+ While "ip_blackhole" takes the standard zero/non-zero on/off
65195+ toggle, "lastack_retries" uses the same kinds of values as
65196+ "tcp_retries1" and "tcp_retries2". The default value of 4
65197+ prevents a socket from lasting more than 45 seconds in LAST_ACK
65198+ state.
65199+
65200+config GRKERNSEC_NO_SIMULT_CONNECT
65201+ bool "Disable TCP Simultaneous Connect"
65202+ default y if GRKERNSEC_CONFIG_AUTO
65203+ depends on NET
65204+ help
65205+ If you say Y here, a feature by Willy Tarreau will be enabled that
65206+ removes a weakness in Linux's strict implementation of TCP that
65207+ allows two clients to connect to each other without either entering
65208+ a listening state. The weakness allows an attacker to easily prevent
65209+ a client from connecting to a known server provided the source port
65210+ for the connection is guessed correctly.
65211+
65212+ As the weakness could be used to prevent an antivirus or IPS from
65213+ fetching updates, or prevent an SSL gateway from fetching a CRL,
65214+ it should be eliminated by enabling this option. Though Linux is
65215+ one of few operating systems supporting simultaneous connect, it
65216+ has no legitimate use in practice and is rarely supported by firewalls.
65217+
65218+config GRKERNSEC_SOCKET
65219+ bool "Socket restrictions"
65220+ depends on NET
65221+ help
65222+ If you say Y here, you will be able to choose from several options.
65223+ If you assign a GID on your system and add it to the supplementary
65224+ groups of users you want to restrict socket access to, this patch
65225+ will perform up to three things, based on the option(s) you choose.
65226+
65227+config GRKERNSEC_SOCKET_ALL
65228+ bool "Deny any sockets to group"
65229+ depends on GRKERNSEC_SOCKET
65230+ help
65231+ If you say Y here, you will be able to choose a GID of whose users will
65232+ be unable to connect to other hosts from your machine or run server
65233+ applications from your machine. If the sysctl option is enabled, a
65234+ sysctl option with name "socket_all" is created.
65235+
65236+config GRKERNSEC_SOCKET_ALL_GID
65237+ int "GID to deny all sockets for"
65238+ depends on GRKERNSEC_SOCKET_ALL
65239+ default 1004
65240+ help
65241+ Here you can choose the GID to disable socket access for. Remember to
65242+ add the users you want socket access disabled for to the GID
65243+ specified here. If the sysctl option is enabled, a sysctl option
65244+ with name "socket_all_gid" is created.
65245+
65246+config GRKERNSEC_SOCKET_CLIENT
65247+ bool "Deny client sockets to group"
65248+ depends on GRKERNSEC_SOCKET
65249+ help
65250+ If you say Y here, you will be able to choose a GID of whose users will
65251+ be unable to connect to other hosts from your machine, but will be
65252+ able to run servers. If this option is enabled, all users in the group
65253+ you specify will have to use passive mode when initiating ftp transfers
65254+ from the shell on your machine. If the sysctl option is enabled, a
65255+ sysctl option with name "socket_client" is created.
65256+
65257+config GRKERNSEC_SOCKET_CLIENT_GID
65258+ int "GID to deny client sockets for"
65259+ depends on GRKERNSEC_SOCKET_CLIENT
65260+ default 1003
65261+ help
65262+ Here you can choose the GID to disable client socket access for.
65263+ Remember to add the users you want client socket access disabled for to
65264+ the GID specified here. If the sysctl option is enabled, a sysctl
65265+ option with name "socket_client_gid" is created.
65266+
65267+config GRKERNSEC_SOCKET_SERVER
65268+ bool "Deny server sockets to group"
65269+ depends on GRKERNSEC_SOCKET
65270+ help
65271+ If you say Y here, you will be able to choose a GID of whose users will
65272+ be unable to run server applications from your machine. If the sysctl
65273+ option is enabled, a sysctl option with name "socket_server" is created.
65274+
65275+config GRKERNSEC_SOCKET_SERVER_GID
65276+ int "GID to deny server sockets for"
65277+ depends on GRKERNSEC_SOCKET_SERVER
65278+ default 1002
65279+ help
65280+ Here you can choose the GID to disable server socket access for.
65281+ Remember to add the users you want server socket access disabled for to
65282+ the GID specified here. If the sysctl option is enabled, a sysctl
65283+ option with name "socket_server_gid" is created.
65284+
65285+endmenu
65286+
65287+menu "Physical Protections"
65288+depends on GRKERNSEC
65289+
65290+config GRKERNSEC_DENYUSB
65291+ bool "Deny new USB connections after toggle"
65292+ default y if GRKERNSEC_CONFIG_AUTO
65293+ depends on SYSCTL && USB_SUPPORT
65294+ help
65295+ If you say Y here, a new sysctl option with name "deny_new_usb"
65296+ will be created. Setting its value to 1 will prevent any new
65297+ USB devices from being recognized by the OS. Any attempted USB
65298+ device insertion will be logged. This option is intended to be
65299+ used against custom USB devices designed to exploit vulnerabilities
65300+ in various USB device drivers.
65301+
65302+ For greatest effectiveness, this sysctl should be set after any
65303+ relevant init scripts. This option is safe to enable in distros
65304+ as each user can choose whether or not to toggle the sysctl.
65305+
65306+config GRKERNSEC_DENYUSB_FORCE
65307+ bool "Reject all USB devices not connected at boot"
65308+ select USB
65309+ depends on GRKERNSEC_DENYUSB
65310+ help
65311+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
65312+ that doesn't involve a sysctl entry. This option should only be
65313+ enabled if you're sure you want to deny all new USB connections
65314+ at runtime and don't want to modify init scripts. This should not
65315+ be enabled by distros. It forces the core USB code to be built
65316+ into the kernel image so that all devices connected at boot time
65317+ can be recognized and new USB device connections can be prevented
65318+ prior to init running.
65319+
65320+endmenu
65321+
65322+menu "Sysctl Support"
65323+depends on GRKERNSEC && SYSCTL
65324+
65325+config GRKERNSEC_SYSCTL
65326+ bool "Sysctl support"
65327+ default y if GRKERNSEC_CONFIG_AUTO
65328+ help
65329+ If you say Y here, you will be able to change the options that
65330+ grsecurity runs with at bootup, without having to recompile your
65331+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
65332+ to enable (1) or disable (0) various features. All the sysctl entries
65333+ are mutable until the "grsec_lock" entry is set to a non-zero value.
65334+ All features enabled in the kernel configuration are disabled at boot
65335+ if you do not say Y to the "Turn on features by default" option.
65336+ All options should be set at startup, and the grsec_lock entry should
65337+ be set to a non-zero value after all the options are set.
65338+ *THIS IS EXTREMELY IMPORTANT*
65339+
65340+config GRKERNSEC_SYSCTL_DISTRO
65341+ bool "Extra sysctl support for distro makers (READ HELP)"
65342+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
65343+ help
65344+ If you say Y here, additional sysctl options will be created
65345+ for features that affect processes running as root. Therefore,
65346+ it is critical when using this option that the grsec_lock entry be
65347+ enabled after boot. Only distros with prebuilt kernel packages
65348+ with this option enabled that can ensure grsec_lock is enabled
65349+ after boot should use this option.
65350+ *Failure to set grsec_lock after boot makes all grsec features
65351+ this option covers useless*
65352+
65353+ Currently this option creates the following sysctl entries:
65354+ "Disable Privileged I/O": "disable_priv_io"
65355+
65356+config GRKERNSEC_SYSCTL_ON
65357+ bool "Turn on features by default"
65358+ default y if GRKERNSEC_CONFIG_AUTO
65359+ depends on GRKERNSEC_SYSCTL
65360+ help
65361+ If you say Y here, instead of having all features enabled in the
65362+ kernel configuration disabled at boot time, the features will be
65363+ enabled at boot time. It is recommended you say Y here unless
65364+ there is some reason you would want all sysctl-tunable features to
65365+ be disabled by default. As mentioned elsewhere, it is important
65366+ to enable the grsec_lock entry once you have finished modifying
65367+ the sysctl entries.
65368+
65369+endmenu
65370+menu "Logging Options"
65371+depends on GRKERNSEC
65372+
65373+config GRKERNSEC_FLOODTIME
65374+ int "Seconds in between log messages (minimum)"
65375+ default 10
65376+ help
65377+ This option allows you to enforce the number of seconds between
65378+ grsecurity log messages. The default should be suitable for most
65379+ people, however, if you choose to change it, choose a value small enough
65380+ to allow informative logs to be produced, but large enough to
65381+ prevent flooding.
65382+
65383+config GRKERNSEC_FLOODBURST
65384+ int "Number of messages in a burst (maximum)"
65385+ default 6
65386+ help
65387+ This option allows you to choose the maximum number of messages allowed
65388+ within the flood time interval you chose in a separate option. The
65389+ default should be suitable for most people, however if you find that
65390+ many of your logs are being interpreted as flooding, you may want to
65391+ raise this value.
65392+
65393+endmenu
65394diff --git a/grsecurity/Makefile b/grsecurity/Makefile
65395new file mode 100644
65396index 0000000..5307c8a
65397--- /dev/null
65398+++ b/grsecurity/Makefile
65399@@ -0,0 +1,54 @@
65400+# grsecurity – access control and security hardening for Linux
65401+# All code in this directory and various hooks located throughout the Linux kernel are
65402+# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
65403+# http://www.grsecurity.net spender@grsecurity.net
65404+#
65405+# This program is free software; you can redistribute it and/or
65406+# modify it under the terms of the GNU General Public License version 2
65407+# as published by the Free Software Foundation.
65408+#
65409+# This program is distributed in the hope that it will be useful,
65410+# but WITHOUT ANY WARRANTY; without even the implied warranty of
65411+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
65412+# GNU General Public License for more details.
65413+#
65414+# You should have received a copy of the GNU General Public License
65415+# along with this program; if not, write to the Free Software
65416+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
65417+
65418+KBUILD_CFLAGS += -Werror
65419+
65420+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
65421+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
65422+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
65423+ grsec_usb.o grsec_ipc.o
65424+
65425+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
65426+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
65427+ gracl_learn.o grsec_log.o gracl_policy.o
65428+ifdef CONFIG_COMPAT
65429+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
65430+endif
65431+
65432+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
65433+
65434+ifdef CONFIG_NET
65435+obj-y += grsec_sock.o
65436+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
65437+endif
65438+
65439+ifndef CONFIG_GRKERNSEC
65440+obj-y += grsec_disabled.o
65441+endif
65442+
65443+ifdef CONFIG_GRKERNSEC_HIDESYM
65444+extra-y := grsec_hidesym.o
65445+$(obj)/grsec_hidesym.o:
65446+ @-chmod -f 500 /boot
65447+ @-chmod -f 500 /lib/modules
65448+ @-chmod -f 500 /lib64/modules
65449+ @-chmod -f 500 /lib32/modules
65450+ @-chmod -f 700 .
65451+ @-chmod -f 700 $(objtree)
65452+ @echo ' grsec: protected kernel image paths'
65453+endif
65454diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
65455new file mode 100644
65456index 0000000..19a5b7c
65457--- /dev/null
65458+++ b/grsecurity/gracl.c
65459@@ -0,0 +1,2678 @@
65460+#include <linux/kernel.h>
65461+#include <linux/module.h>
65462+#include <linux/sched.h>
65463+#include <linux/mm.h>
65464+#include <linux/file.h>
65465+#include <linux/fs.h>
65466+#include <linux/namei.h>
65467+#include <linux/mount.h>
65468+#include <linux/tty.h>
65469+#include <linux/proc_fs.h>
65470+#include <linux/lglock.h>
65471+#include <linux/slab.h>
65472+#include <linux/vmalloc.h>
65473+#include <linux/types.h>
65474+#include <linux/sysctl.h>
65475+#include <linux/netdevice.h>
65476+#include <linux/ptrace.h>
65477+#include <linux/gracl.h>
65478+#include <linux/gralloc.h>
65479+#include <linux/security.h>
65480+#include <linux/grinternal.h>
65481+#include <linux/pid_namespace.h>
65482+#include <linux/stop_machine.h>
65483+#include <linux/fdtable.h>
65484+#include <linux/percpu.h>
65485+#include <linux/lglock.h>
65486+#include <linux/hugetlb.h>
65487+#include <linux/posix-timers.h>
65488+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
65489+#include <linux/magic.h>
65490+#include <linux/pagemap.h>
65491+#include "../fs/btrfs/async-thread.h"
65492+#include "../fs/btrfs/ctree.h"
65493+#include "../fs/btrfs/btrfs_inode.h"
65494+#endif
65495+#include "../fs/mount.h"
65496+
65497+#include <asm/uaccess.h>
65498+#include <asm/errno.h>
65499+#include <asm/mman.h>
65500+
65501+#define FOR_EACH_ROLE_START(role) \
65502+ role = running_polstate.role_list; \
65503+ while (role) {
65504+
65505+#define FOR_EACH_ROLE_END(role) \
65506+ role = role->prev; \
65507+ }
65508+
65509+extern struct path gr_real_root;
65510+
65511+static struct gr_policy_state running_polstate;
65512+struct gr_policy_state *polstate = &running_polstate;
65513+extern struct gr_alloc_state *current_alloc_state;
65514+
65515+extern char *gr_shared_page[4];
65516+DEFINE_RWLOCK(gr_inode_lock);
65517+
65518+static unsigned int gr_status __read_only = GR_STATUS_INIT;
65519+
65520+#ifdef CONFIG_NET
65521+extern struct vfsmount *sock_mnt;
65522+#endif
65523+
65524+extern struct vfsmount *pipe_mnt;
65525+extern struct vfsmount *shm_mnt;
65526+
65527+#ifdef CONFIG_HUGETLBFS
65528+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
65529+#endif
65530+
65531+extern u16 acl_sp_role_value;
65532+extern struct acl_object_label *fakefs_obj_rw;
65533+extern struct acl_object_label *fakefs_obj_rwx;
65534+
65535+int gr_acl_is_enabled(void)
65536+{
65537+ return (gr_status & GR_READY);
65538+}
65539+
65540+void gr_enable_rbac_system(void)
65541+{
65542+ pax_open_kernel();
65543+ gr_status |= GR_READY;
65544+ pax_close_kernel();
65545+}
65546+
65547+int gr_rbac_disable(void *unused)
65548+{
65549+ pax_open_kernel();
65550+ gr_status &= ~GR_READY;
65551+ pax_close_kernel();
65552+
65553+ return 0;
65554+}
65555+
65556+static inline dev_t __get_dev(const struct dentry *dentry)
65557+{
65558+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
65559+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
65560+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
65561+ else
65562+#endif
65563+ return dentry->d_sb->s_dev;
65564+}
65565+
65566+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
65567+{
65568+ return __get_dev(dentry);
65569+}
65570+
65571+static char gr_task_roletype_to_char(struct task_struct *task)
65572+{
65573+ switch (task->role->roletype &
65574+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
65575+ GR_ROLE_SPECIAL)) {
65576+ case GR_ROLE_DEFAULT:
65577+ return 'D';
65578+ case GR_ROLE_USER:
65579+ return 'U';
65580+ case GR_ROLE_GROUP:
65581+ return 'G';
65582+ case GR_ROLE_SPECIAL:
65583+ return 'S';
65584+ }
65585+
65586+ return 'X';
65587+}
65588+
65589+char gr_roletype_to_char(void)
65590+{
65591+ return gr_task_roletype_to_char(current);
65592+}
65593+
65594+__inline__ int
65595+gr_acl_tpe_check(void)
65596+{
65597+ if (unlikely(!(gr_status & GR_READY)))
65598+ return 0;
65599+ if (current->role->roletype & GR_ROLE_TPE)
65600+ return 1;
65601+ else
65602+ return 0;
65603+}
65604+
65605+int
65606+gr_handle_rawio(const struct inode *inode)
65607+{
65608+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65609+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
65610+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
65611+ !capable(CAP_SYS_RAWIO))
65612+ return 1;
65613+#endif
65614+ return 0;
65615+}
65616+
65617+int
65618+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
65619+{
65620+ if (likely(lena != lenb))
65621+ return 0;
65622+
65623+ return !memcmp(a, b, lena);
65624+}
65625+
65626+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
65627+{
65628+ *buflen -= namelen;
65629+ if (*buflen < 0)
65630+ return -ENAMETOOLONG;
65631+ *buffer -= namelen;
65632+ memcpy(*buffer, str, namelen);
65633+ return 0;
65634+}
65635+
65636+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
65637+{
65638+ return prepend(buffer, buflen, name->name, name->len);
65639+}
65640+
65641+static int prepend_path(const struct path *path, struct path *root,
65642+ char **buffer, int *buflen)
65643+{
65644+ struct dentry *dentry = path->dentry;
65645+ struct vfsmount *vfsmnt = path->mnt;
65646+ struct mount *mnt = real_mount(vfsmnt);
65647+ bool slash = false;
65648+ int error = 0;
65649+
65650+ while (dentry != root->dentry || vfsmnt != root->mnt) {
65651+ struct dentry * parent;
65652+
65653+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
65654+ /* Global root? */
65655+ if (!mnt_has_parent(mnt)) {
65656+ goto out;
65657+ }
65658+ dentry = mnt->mnt_mountpoint;
65659+ mnt = mnt->mnt_parent;
65660+ vfsmnt = &mnt->mnt;
65661+ continue;
65662+ }
65663+ parent = dentry->d_parent;
65664+ prefetch(parent);
65665+ spin_lock(&dentry->d_lock);
65666+ error = prepend_name(buffer, buflen, &dentry->d_name);
65667+ spin_unlock(&dentry->d_lock);
65668+ if (!error)
65669+ error = prepend(buffer, buflen, "/", 1);
65670+ if (error)
65671+ break;
65672+
65673+ slash = true;
65674+ dentry = parent;
65675+ }
65676+
65677+out:
65678+ if (!error && !slash)
65679+ error = prepend(buffer, buflen, "/", 1);
65680+
65681+ return error;
65682+}
65683+
65684+/* this must be called with mount_lock and rename_lock held */
65685+
65686+static char *__our_d_path(const struct path *path, struct path *root,
65687+ char *buf, int buflen)
65688+{
65689+ char *res = buf + buflen;
65690+ int error;
65691+
65692+ prepend(&res, &buflen, "\0", 1);
65693+ error = prepend_path(path, root, &res, &buflen);
65694+ if (error)
65695+ return ERR_PTR(error);
65696+
65697+ return res;
65698+}
65699+
65700+static char *
65701+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
65702+{
65703+ char *retval;
65704+
65705+ retval = __our_d_path(path, root, buf, buflen);
65706+ if (unlikely(IS_ERR(retval)))
65707+ retval = strcpy(buf, "<path too long>");
65708+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
65709+ retval[1] = '\0';
65710+
65711+ return retval;
65712+}
65713+
65714+static char *
65715+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
65716+ char *buf, int buflen)
65717+{
65718+ struct path path;
65719+ char *res;
65720+
65721+ path.dentry = (struct dentry *)dentry;
65722+ path.mnt = (struct vfsmount *)vfsmnt;
65723+
65724+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
65725+ by the RBAC system */
65726+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
65727+
65728+ return res;
65729+}
65730+
65731+static char *
65732+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
65733+ char *buf, int buflen)
65734+{
65735+ char *res;
65736+ struct path path;
65737+ struct path root;
65738+ struct task_struct *reaper = init_pid_ns.child_reaper;
65739+
65740+ path.dentry = (struct dentry *)dentry;
65741+ path.mnt = (struct vfsmount *)vfsmnt;
65742+
65743+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
65744+ get_fs_root(reaper->fs, &root);
65745+
65746+ read_seqlock_excl(&mount_lock);
65747+ write_seqlock(&rename_lock);
65748+ res = gen_full_path(&path, &root, buf, buflen);
65749+ write_sequnlock(&rename_lock);
65750+ read_sequnlock_excl(&mount_lock);
65751+
65752+ path_put(&root);
65753+ return res;
65754+}
65755+
65756+char *
65757+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
65758+{
65759+ char *ret;
65760+ read_seqlock_excl(&mount_lock);
65761+ write_seqlock(&rename_lock);
65762+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
65763+ PAGE_SIZE);
65764+ write_sequnlock(&rename_lock);
65765+ read_sequnlock_excl(&mount_lock);
65766+ return ret;
65767+}
65768+
65769+static char *
65770+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
65771+{
65772+ char *ret;
65773+ char *buf;
65774+ int buflen;
65775+
65776+ read_seqlock_excl(&mount_lock);
65777+ write_seqlock(&rename_lock);
65778+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
65779+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
65780+ buflen = (int)(ret - buf);
65781+ if (buflen >= 5)
65782+ prepend(&ret, &buflen, "/proc", 5);
65783+ else
65784+ ret = strcpy(buf, "<path too long>");
65785+ write_sequnlock(&rename_lock);
65786+ read_sequnlock_excl(&mount_lock);
65787+ return ret;
65788+}
65789+
65790+char *
65791+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
65792+{
65793+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
65794+ PAGE_SIZE);
65795+}
65796+
65797+char *
65798+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
65799+{
65800+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
65801+ PAGE_SIZE);
65802+}
65803+
65804+char *
65805+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
65806+{
65807+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
65808+ PAGE_SIZE);
65809+}
65810+
65811+char *
65812+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
65813+{
65814+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
65815+ PAGE_SIZE);
65816+}
65817+
65818+char *
65819+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
65820+{
65821+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
65822+ PAGE_SIZE);
65823+}
65824+
65825+__inline__ __u32
65826+to_gr_audit(const __u32 reqmode)
65827+{
65828+ /* masks off auditable permission flags, then shifts them to create
65829+ auditing flags, and adds the special case of append auditing if
65830+ we're requesting write */
65831+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
65832+}
65833+
65834+struct acl_role_label *
65835+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
65836+ const gid_t gid)
65837+{
65838+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
65839+ struct acl_role_label *match;
65840+ struct role_allowed_ip *ipp;
65841+ unsigned int x;
65842+ u32 curr_ip = task->signal->saved_ip;
65843+
65844+ match = state->acl_role_set.r_hash[index];
65845+
65846+ while (match) {
65847+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
65848+ for (x = 0; x < match->domain_child_num; x++) {
65849+ if (match->domain_children[x] == uid)
65850+ goto found;
65851+ }
65852+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
65853+ break;
65854+ match = match->next;
65855+ }
65856+found:
65857+ if (match == NULL) {
65858+ try_group:
65859+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
65860+ match = state->acl_role_set.r_hash[index];
65861+
65862+ while (match) {
65863+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
65864+ for (x = 0; x < match->domain_child_num; x++) {
65865+ if (match->domain_children[x] == gid)
65866+ goto found2;
65867+ }
65868+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
65869+ break;
65870+ match = match->next;
65871+ }
65872+found2:
65873+ if (match == NULL)
65874+ match = state->default_role;
65875+ if (match->allowed_ips == NULL)
65876+ return match;
65877+ else {
65878+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
65879+ if (likely
65880+ ((ntohl(curr_ip) & ipp->netmask) ==
65881+ (ntohl(ipp->addr) & ipp->netmask)))
65882+ return match;
65883+ }
65884+ match = state->default_role;
65885+ }
65886+ } else if (match->allowed_ips == NULL) {
65887+ return match;
65888+ } else {
65889+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
65890+ if (likely
65891+ ((ntohl(curr_ip) & ipp->netmask) ==
65892+ (ntohl(ipp->addr) & ipp->netmask)))
65893+ return match;
65894+ }
65895+ goto try_group;
65896+ }
65897+
65898+ return match;
65899+}
65900+
65901+static struct acl_role_label *
65902+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
65903+ const gid_t gid)
65904+{
65905+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
65906+}
65907+
65908+struct acl_subject_label *
65909+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
65910+ const struct acl_role_label *role)
65911+{
65912+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
65913+ struct acl_subject_label *match;
65914+
65915+ match = role->subj_hash[index];
65916+
65917+ while (match && (match->inode != ino || match->device != dev ||
65918+ (match->mode & GR_DELETED))) {
65919+ match = match->next;
65920+ }
65921+
65922+ if (match && !(match->mode & GR_DELETED))
65923+ return match;
65924+ else
65925+ return NULL;
65926+}
65927+
65928+struct acl_subject_label *
65929+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
65930+ const struct acl_role_label *role)
65931+{
65932+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
65933+ struct acl_subject_label *match;
65934+
65935+ match = role->subj_hash[index];
65936+
65937+ while (match && (match->inode != ino || match->device != dev ||
65938+ !(match->mode & GR_DELETED))) {
65939+ match = match->next;
65940+ }
65941+
65942+ if (match && (match->mode & GR_DELETED))
65943+ return match;
65944+ else
65945+ return NULL;
65946+}
65947+
65948+static struct acl_object_label *
65949+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
65950+ const struct acl_subject_label *subj)
65951+{
65952+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
65953+ struct acl_object_label *match;
65954+
65955+ match = subj->obj_hash[index];
65956+
65957+ while (match && (match->inode != ino || match->device != dev ||
65958+ (match->mode & GR_DELETED))) {
65959+ match = match->next;
65960+ }
65961+
65962+ if (match && !(match->mode & GR_DELETED))
65963+ return match;
65964+ else
65965+ return NULL;
65966+}
65967+
65968+static struct acl_object_label *
65969+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
65970+ const struct acl_subject_label *subj)
65971+{
65972+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
65973+ struct acl_object_label *match;
65974+
65975+ match = subj->obj_hash[index];
65976+
65977+ while (match && (match->inode != ino || match->device != dev ||
65978+ !(match->mode & GR_DELETED))) {
65979+ match = match->next;
65980+ }
65981+
65982+ if (match && (match->mode & GR_DELETED))
65983+ return match;
65984+
65985+ match = subj->obj_hash[index];
65986+
65987+ while (match && (match->inode != ino || match->device != dev ||
65988+ (match->mode & GR_DELETED))) {
65989+ match = match->next;
65990+ }
65991+
65992+ if (match && !(match->mode & GR_DELETED))
65993+ return match;
65994+ else
65995+ return NULL;
65996+}
65997+
65998+struct name_entry *
65999+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
66000+{
66001+ unsigned int len = strlen(name);
66002+ unsigned int key = full_name_hash(name, len);
66003+ unsigned int index = key % state->name_set.n_size;
66004+ struct name_entry *match;
66005+
66006+ match = state->name_set.n_hash[index];
66007+
66008+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
66009+ match = match->next;
66010+
66011+ return match;
66012+}
66013+
66014+static struct name_entry *
66015+lookup_name_entry(const char *name)
66016+{
66017+ return __lookup_name_entry(&running_polstate, name);
66018+}
66019+
66020+static struct name_entry *
66021+lookup_name_entry_create(const char *name)
66022+{
66023+ unsigned int len = strlen(name);
66024+ unsigned int key = full_name_hash(name, len);
66025+ unsigned int index = key % running_polstate.name_set.n_size;
66026+ struct name_entry *match;
66027+
66028+ match = running_polstate.name_set.n_hash[index];
66029+
66030+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
66031+ !match->deleted))
66032+ match = match->next;
66033+
66034+ if (match && match->deleted)
66035+ return match;
66036+
66037+ match = running_polstate.name_set.n_hash[index];
66038+
66039+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
66040+ match->deleted))
66041+ match = match->next;
66042+
66043+ if (match && !match->deleted)
66044+ return match;
66045+ else
66046+ return NULL;
66047+}
66048+
66049+static struct inodev_entry *
66050+lookup_inodev_entry(const ino_t ino, const dev_t dev)
66051+{
66052+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
66053+ struct inodev_entry *match;
66054+
66055+ match = running_polstate.inodev_set.i_hash[index];
66056+
66057+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
66058+ match = match->next;
66059+
66060+ return match;
66061+}
66062+
66063+void
66064+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
66065+{
66066+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
66067+ state->inodev_set.i_size);
66068+ struct inodev_entry **curr;
66069+
66070+ entry->prev = NULL;
66071+
66072+ curr = &state->inodev_set.i_hash[index];
66073+ if (*curr != NULL)
66074+ (*curr)->prev = entry;
66075+
66076+ entry->next = *curr;
66077+ *curr = entry;
66078+
66079+ return;
66080+}
66081+
66082+static void
66083+insert_inodev_entry(struct inodev_entry *entry)
66084+{
66085+ __insert_inodev_entry(&running_polstate, entry);
66086+}
66087+
66088+void
66089+insert_acl_obj_label(struct acl_object_label *obj,
66090+ struct acl_subject_label *subj)
66091+{
66092+ unsigned int index =
66093+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
66094+ struct acl_object_label **curr;
66095+
66096+ obj->prev = NULL;
66097+
66098+ curr = &subj->obj_hash[index];
66099+ if (*curr != NULL)
66100+ (*curr)->prev = obj;
66101+
66102+ obj->next = *curr;
66103+ *curr = obj;
66104+
66105+ return;
66106+}
66107+
66108+void
66109+insert_acl_subj_label(struct acl_subject_label *obj,
66110+ struct acl_role_label *role)
66111+{
66112+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
66113+ struct acl_subject_label **curr;
66114+
66115+ obj->prev = NULL;
66116+
66117+ curr = &role->subj_hash[index];
66118+ if (*curr != NULL)
66119+ (*curr)->prev = obj;
66120+
66121+ obj->next = *curr;
66122+ *curr = obj;
66123+
66124+ return;
66125+}
66126+
66127+/* derived from glibc fnmatch() 0: match, 1: no match*/
66128+
66129+static int
66130+glob_match(const char *p, const char *n)
66131+{
66132+ char c;
66133+
66134+ while ((c = *p++) != '\0') {
66135+ switch (c) {
66136+ case '?':
66137+ if (*n == '\0')
66138+ return 1;
66139+ else if (*n == '/')
66140+ return 1;
66141+ break;
66142+ case '\\':
66143+ if (*n != c)
66144+ return 1;
66145+ break;
66146+ case '*':
66147+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
66148+ if (*n == '/')
66149+ return 1;
66150+ else if (c == '?') {
66151+ if (*n == '\0')
66152+ return 1;
66153+ else
66154+ ++n;
66155+ }
66156+ }
66157+ if (c == '\0') {
66158+ return 0;
66159+ } else {
66160+ const char *endp;
66161+
66162+ if ((endp = strchr(n, '/')) == NULL)
66163+ endp = n + strlen(n);
66164+
66165+ if (c == '[') {
66166+ for (--p; n < endp; ++n)
66167+ if (!glob_match(p, n))
66168+ return 0;
66169+ } else if (c == '/') {
66170+ while (*n != '\0' && *n != '/')
66171+ ++n;
66172+ if (*n == '/' && !glob_match(p, n + 1))
66173+ return 0;
66174+ } else {
66175+ for (--p; n < endp; ++n)
66176+ if (*n == c && !glob_match(p, n))
66177+ return 0;
66178+ }
66179+
66180+ return 1;
66181+ }
66182+ case '[':
66183+ {
66184+ int not;
66185+ char cold;
66186+
66187+ if (*n == '\0' || *n == '/')
66188+ return 1;
66189+
66190+ not = (*p == '!' || *p == '^');
66191+ if (not)
66192+ ++p;
66193+
66194+ c = *p++;
66195+ for (;;) {
66196+ unsigned char fn = (unsigned char)*n;
66197+
66198+ if (c == '\0')
66199+ return 1;
66200+ else {
66201+ if (c == fn)
66202+ goto matched;
66203+ cold = c;
66204+ c = *p++;
66205+
66206+ if (c == '-' && *p != ']') {
66207+ unsigned char cend = *p++;
66208+
66209+ if (cend == '\0')
66210+ return 1;
66211+
66212+ if (cold <= fn && fn <= cend)
66213+ goto matched;
66214+
66215+ c = *p++;
66216+ }
66217+ }
66218+
66219+ if (c == ']')
66220+ break;
66221+ }
66222+ if (!not)
66223+ return 1;
66224+ break;
66225+ matched:
66226+ while (c != ']') {
66227+ if (c == '\0')
66228+ return 1;
66229+
66230+ c = *p++;
66231+ }
66232+ if (not)
66233+ return 1;
66234+ }
66235+ break;
66236+ default:
66237+ if (c != *n)
66238+ return 1;
66239+ }
66240+
66241+ ++n;
66242+ }
66243+
66244+ if (*n == '\0')
66245+ return 0;
66246+
66247+ if (*n == '/')
66248+ return 0;
66249+
66250+ return 1;
66251+}
66252+
66253+static struct acl_object_label *
66254+chk_glob_label(struct acl_object_label *globbed,
66255+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
66256+{
66257+ struct acl_object_label *tmp;
66258+
66259+ if (*path == NULL)
66260+ *path = gr_to_filename_nolock(dentry, mnt);
66261+
66262+ tmp = globbed;
66263+
66264+ while (tmp) {
66265+ if (!glob_match(tmp->filename, *path))
66266+ return tmp;
66267+ tmp = tmp->next;
66268+ }
66269+
66270+ return NULL;
66271+}
66272+
66273+static struct acl_object_label *
66274+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
66275+ const ino_t curr_ino, const dev_t curr_dev,
66276+ const struct acl_subject_label *subj, char **path, const int checkglob)
66277+{
66278+ struct acl_subject_label *tmpsubj;
66279+ struct acl_object_label *retval;
66280+ struct acl_object_label *retval2;
66281+
66282+ tmpsubj = (struct acl_subject_label *) subj;
66283+ read_lock(&gr_inode_lock);
66284+ do {
66285+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
66286+ if (retval) {
66287+ if (checkglob && retval->globbed) {
66288+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
66289+ if (retval2)
66290+ retval = retval2;
66291+ }
66292+ break;
66293+ }
66294+ } while ((tmpsubj = tmpsubj->parent_subject));
66295+ read_unlock(&gr_inode_lock);
66296+
66297+ return retval;
66298+}
66299+
66300+static __inline__ struct acl_object_label *
66301+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
66302+ struct dentry *curr_dentry,
66303+ const struct acl_subject_label *subj, char **path, const int checkglob)
66304+{
66305+ int newglob = checkglob;
66306+ ino_t inode;
66307+ dev_t device;
66308+
66309+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
66310+ as we don't want a / * rule to match instead of the / object
66311+ don't do this for create lookups that call this function though, since they're looking up
66312+ on the parent and thus need globbing checks on all paths
66313+ */
66314+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
66315+ newglob = GR_NO_GLOB;
66316+
66317+ spin_lock(&curr_dentry->d_lock);
66318+ inode = curr_dentry->d_inode->i_ino;
66319+ device = __get_dev(curr_dentry);
66320+ spin_unlock(&curr_dentry->d_lock);
66321+
66322+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
66323+}
66324+
66325+#ifdef CONFIG_HUGETLBFS
66326+static inline bool
66327+is_hugetlbfs_mnt(const struct vfsmount *mnt)
66328+{
66329+ int i;
66330+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
66331+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
66332+ return true;
66333+ }
66334+
66335+ return false;
66336+}
66337+#endif
66338+
66339+static struct acl_object_label *
66340+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66341+ const struct acl_subject_label *subj, char *path, const int checkglob)
66342+{
66343+ struct dentry *dentry = (struct dentry *) l_dentry;
66344+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
66345+ struct mount *real_mnt = real_mount(mnt);
66346+ struct acl_object_label *retval;
66347+ struct dentry *parent;
66348+
66349+ read_seqlock_excl(&mount_lock);
66350+ write_seqlock(&rename_lock);
66351+
66352+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
66353+#ifdef CONFIG_NET
66354+ mnt == sock_mnt ||
66355+#endif
66356+#ifdef CONFIG_HUGETLBFS
66357+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
66358+#endif
66359+ /* ignore Eric Biederman */
66360+ IS_PRIVATE(l_dentry->d_inode))) {
66361+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
66362+ goto out;
66363+ }
66364+
66365+ for (;;) {
66366+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
66367+ break;
66368+
66369+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
66370+ if (!mnt_has_parent(real_mnt))
66371+ break;
66372+
66373+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
66374+ if (retval != NULL)
66375+ goto out;
66376+
66377+ dentry = real_mnt->mnt_mountpoint;
66378+ real_mnt = real_mnt->mnt_parent;
66379+ mnt = &real_mnt->mnt;
66380+ continue;
66381+ }
66382+
66383+ parent = dentry->d_parent;
66384+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
66385+ if (retval != NULL)
66386+ goto out;
66387+
66388+ dentry = parent;
66389+ }
66390+
66391+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
66392+
66393+ /* gr_real_root is pinned so we don't have to hold a reference */
66394+ if (retval == NULL)
66395+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
66396+out:
66397+ write_sequnlock(&rename_lock);
66398+ read_sequnlock_excl(&mount_lock);
66399+
66400+ BUG_ON(retval == NULL);
66401+
66402+ return retval;
66403+}
66404+
66405+static __inline__ struct acl_object_label *
66406+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66407+ const struct acl_subject_label *subj)
66408+{
66409+ char *path = NULL;
66410+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
66411+}
66412+
66413+static __inline__ struct acl_object_label *
66414+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66415+ const struct acl_subject_label *subj)
66416+{
66417+ char *path = NULL;
66418+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
66419+}
66420+
66421+static __inline__ struct acl_object_label *
66422+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66423+ const struct acl_subject_label *subj, char *path)
66424+{
66425+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
66426+}
66427+
66428+struct acl_subject_label *
66429+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66430+ const struct acl_role_label *role)
66431+{
66432+ struct dentry *dentry = (struct dentry *) l_dentry;
66433+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
66434+ struct mount *real_mnt = real_mount(mnt);
66435+ struct acl_subject_label *retval;
66436+ struct dentry *parent;
66437+
66438+ read_seqlock_excl(&mount_lock);
66439+ write_seqlock(&rename_lock);
66440+
66441+ for (;;) {
66442+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
66443+ break;
66444+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
66445+ if (!mnt_has_parent(real_mnt))
66446+ break;
66447+
66448+ spin_lock(&dentry->d_lock);
66449+ read_lock(&gr_inode_lock);
66450+ retval =
66451+ lookup_acl_subj_label(dentry->d_inode->i_ino,
66452+ __get_dev(dentry), role);
66453+ read_unlock(&gr_inode_lock);
66454+ spin_unlock(&dentry->d_lock);
66455+ if (retval != NULL)
66456+ goto out;
66457+
66458+ dentry = real_mnt->mnt_mountpoint;
66459+ real_mnt = real_mnt->mnt_parent;
66460+ mnt = &real_mnt->mnt;
66461+ continue;
66462+ }
66463+
66464+ spin_lock(&dentry->d_lock);
66465+ read_lock(&gr_inode_lock);
66466+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
66467+ __get_dev(dentry), role);
66468+ read_unlock(&gr_inode_lock);
66469+ parent = dentry->d_parent;
66470+ spin_unlock(&dentry->d_lock);
66471+
66472+ if (retval != NULL)
66473+ goto out;
66474+
66475+ dentry = parent;
66476+ }
66477+
66478+ spin_lock(&dentry->d_lock);
66479+ read_lock(&gr_inode_lock);
66480+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
66481+ __get_dev(dentry), role);
66482+ read_unlock(&gr_inode_lock);
66483+ spin_unlock(&dentry->d_lock);
66484+
66485+ if (unlikely(retval == NULL)) {
66486+ /* gr_real_root is pinned, we don't need to hold a reference */
66487+ read_lock(&gr_inode_lock);
66488+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
66489+ __get_dev(gr_real_root.dentry), role);
66490+ read_unlock(&gr_inode_lock);
66491+ }
66492+out:
66493+ write_sequnlock(&rename_lock);
66494+ read_sequnlock_excl(&mount_lock);
66495+
66496+ BUG_ON(retval == NULL);
66497+
66498+ return retval;
66499+}
66500+
66501+void
66502+assign_special_role(const char *rolename)
66503+{
66504+ struct acl_object_label *obj;
66505+ struct acl_role_label *r;
66506+ struct acl_role_label *assigned = NULL;
66507+ struct task_struct *tsk;
66508+ struct file *filp;
66509+
66510+ FOR_EACH_ROLE_START(r)
66511+ if (!strcmp(rolename, r->rolename) &&
66512+ (r->roletype & GR_ROLE_SPECIAL)) {
66513+ assigned = r;
66514+ break;
66515+ }
66516+ FOR_EACH_ROLE_END(r)
66517+
66518+ if (!assigned)
66519+ return;
66520+
66521+ read_lock(&tasklist_lock);
66522+ read_lock(&grsec_exec_file_lock);
66523+
66524+ tsk = current->real_parent;
66525+ if (tsk == NULL)
66526+ goto out_unlock;
66527+
66528+ filp = tsk->exec_file;
66529+ if (filp == NULL)
66530+ goto out_unlock;
66531+
66532+ tsk->is_writable = 0;
66533+ tsk->inherited = 0;
66534+
66535+ tsk->acl_sp_role = 1;
66536+ tsk->acl_role_id = ++acl_sp_role_value;
66537+ tsk->role = assigned;
66538+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
66539+
66540+ /* ignore additional mmap checks for processes that are writable
66541+ by the default ACL */
66542+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
66543+ if (unlikely(obj->mode & GR_WRITE))
66544+ tsk->is_writable = 1;
66545+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
66546+ if (unlikely(obj->mode & GR_WRITE))
66547+ tsk->is_writable = 1;
66548+
66549+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
66550+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
66551+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
66552+#endif
66553+
66554+out_unlock:
66555+ read_unlock(&grsec_exec_file_lock);
66556+ read_unlock(&tasklist_lock);
66557+ return;
66558+}
66559+
66560+
66561+static void
66562+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
66563+{
66564+ struct task_struct *task = current;
66565+ const struct cred *cred = current_cred();
66566+
66567+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
66568+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
66569+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
66570+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
66571+
66572+ return;
66573+}
66574+
66575+static void
66576+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
66577+{
66578+ struct task_struct *task = current;
66579+ const struct cred *cred = current_cred();
66580+
66581+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
66582+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
66583+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
66584+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
66585+
66586+ return;
66587+}
66588+
66589+static void
66590+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
66591+{
66592+ struct task_struct *task = current;
66593+ const struct cred *cred = current_cred();
66594+
66595+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
66596+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
66597+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
66598+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
66599+
66600+ return;
66601+}
66602+
66603+static void
66604+gr_set_proc_res(struct task_struct *task)
66605+{
66606+ struct acl_subject_label *proc;
66607+ unsigned short i;
66608+
66609+ proc = task->acl;
66610+
66611+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
66612+ return;
66613+
66614+ for (i = 0; i < RLIM_NLIMITS; i++) {
66615+ if (!(proc->resmask & (1U << i)))
66616+ continue;
66617+
66618+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
66619+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
66620+
66621+ if (i == RLIMIT_CPU)
66622+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
66623+ }
66624+
66625+ return;
66626+}
66627+
66628+/* both of the below must be called with
66629+ rcu_read_lock();
66630+ read_lock(&tasklist_lock);
66631+ read_lock(&grsec_exec_file_lock);
66632+*/
66633+
66634+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
66635+{
66636+ char *tmpname;
66637+ struct acl_subject_label *tmpsubj;
66638+ struct file *filp;
66639+ struct name_entry *nmatch;
66640+
66641+ filp = task->exec_file;
66642+ if (filp == NULL)
66643+ return NULL;
66644+
66645+ /* the following is to apply the correct subject
66646+ on binaries running when the RBAC system
66647+ is enabled, when the binaries have been
66648+ replaced or deleted since their execution
66649+ -----
66650+ when the RBAC system starts, the inode/dev
66651+ from exec_file will be one the RBAC system
66652+ is unaware of. It only knows the inode/dev
66653+ of the present file on disk, or the absence
66654+ of it.
66655+ */
66656+
66657+ if (filename)
66658+ nmatch = __lookup_name_entry(state, filename);
66659+ else {
66660+ preempt_disable();
66661+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
66662+
66663+ nmatch = __lookup_name_entry(state, tmpname);
66664+ preempt_enable();
66665+ }
66666+ tmpsubj = NULL;
66667+ if (nmatch) {
66668+ if (nmatch->deleted)
66669+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
66670+ else
66671+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
66672+ }
66673+ /* this also works for the reload case -- if we don't match a potentially inherited subject
66674+ then we fall back to a normal lookup based on the binary's ino/dev
66675+ */
66676+ if (tmpsubj == NULL)
66677+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
66678+
66679+ return tmpsubj;
66680+}
66681+
66682+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
66683+{
66684+ return __gr_get_subject_for_task(&running_polstate, task, filename);
66685+}
66686+
66687+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
66688+{
66689+ struct acl_object_label *obj;
66690+ struct file *filp;
66691+
66692+ filp = task->exec_file;
66693+
66694+ task->acl = subj;
66695+ task->is_writable = 0;
66696+ /* ignore additional mmap checks for processes that are writable
66697+ by the default ACL */
66698+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
66699+ if (unlikely(obj->mode & GR_WRITE))
66700+ task->is_writable = 1;
66701+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
66702+ if (unlikely(obj->mode & GR_WRITE))
66703+ task->is_writable = 1;
66704+
66705+ gr_set_proc_res(task);
66706+
66707+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
66708+ 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);
66709+#endif
66710+}
66711+
66712+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
66713+{
66714+ __gr_apply_subject_to_task(&running_polstate, task, subj);
66715+}
66716+
66717+__u32
66718+gr_search_file(const struct dentry * dentry, const __u32 mode,
66719+ const struct vfsmount * mnt)
66720+{
66721+ __u32 retval = mode;
66722+ struct acl_subject_label *curracl;
66723+ struct acl_object_label *currobj;
66724+
66725+ if (unlikely(!(gr_status & GR_READY)))
66726+ return (mode & ~GR_AUDITS);
66727+
66728+ curracl = current->acl;
66729+
66730+ currobj = chk_obj_label(dentry, mnt, curracl);
66731+ retval = currobj->mode & mode;
66732+
66733+ /* if we're opening a specified transfer file for writing
66734+ (e.g. /dev/initctl), then transfer our role to init
66735+ */
66736+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
66737+ current->role->roletype & GR_ROLE_PERSIST)) {
66738+ struct task_struct *task = init_pid_ns.child_reaper;
66739+
66740+ if (task->role != current->role) {
66741+ struct acl_subject_label *subj;
66742+
66743+ task->acl_sp_role = 0;
66744+ task->acl_role_id = current->acl_role_id;
66745+ task->role = current->role;
66746+ rcu_read_lock();
66747+ read_lock(&grsec_exec_file_lock);
66748+ subj = gr_get_subject_for_task(task, NULL);
66749+ gr_apply_subject_to_task(task, subj);
66750+ read_unlock(&grsec_exec_file_lock);
66751+ rcu_read_unlock();
66752+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
66753+ }
66754+ }
66755+
66756+ if (unlikely
66757+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
66758+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
66759+ __u32 new_mode = mode;
66760+
66761+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
66762+
66763+ retval = new_mode;
66764+
66765+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
66766+ new_mode |= GR_INHERIT;
66767+
66768+ if (!(mode & GR_NOLEARN))
66769+ gr_log_learn(dentry, mnt, new_mode);
66770+ }
66771+
66772+ return retval;
66773+}
66774+
66775+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
66776+ const struct dentry *parent,
66777+ const struct vfsmount *mnt)
66778+{
66779+ struct name_entry *match;
66780+ struct acl_object_label *matchpo;
66781+ struct acl_subject_label *curracl;
66782+ char *path;
66783+
66784+ if (unlikely(!(gr_status & GR_READY)))
66785+ return NULL;
66786+
66787+ preempt_disable();
66788+ path = gr_to_filename_rbac(new_dentry, mnt);
66789+ match = lookup_name_entry_create(path);
66790+
66791+ curracl = current->acl;
66792+
66793+ if (match) {
66794+ read_lock(&gr_inode_lock);
66795+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
66796+ read_unlock(&gr_inode_lock);
66797+
66798+ if (matchpo) {
66799+ preempt_enable();
66800+ return matchpo;
66801+ }
66802+ }
66803+
66804+ // lookup parent
66805+
66806+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
66807+
66808+ preempt_enable();
66809+ return matchpo;
66810+}
66811+
66812+__u32
66813+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
66814+ const struct vfsmount * mnt, const __u32 mode)
66815+{
66816+ struct acl_object_label *matchpo;
66817+ __u32 retval;
66818+
66819+ if (unlikely(!(gr_status & GR_READY)))
66820+ return (mode & ~GR_AUDITS);
66821+
66822+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
66823+
66824+ retval = matchpo->mode & mode;
66825+
66826+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
66827+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
66828+ __u32 new_mode = mode;
66829+
66830+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
66831+
66832+ gr_log_learn(new_dentry, mnt, new_mode);
66833+ return new_mode;
66834+ }
66835+
66836+ return retval;
66837+}
66838+
66839+__u32
66840+gr_check_link(const struct dentry * new_dentry,
66841+ const struct dentry * parent_dentry,
66842+ const struct vfsmount * parent_mnt,
66843+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
66844+{
66845+ struct acl_object_label *obj;
66846+ __u32 oldmode, newmode;
66847+ __u32 needmode;
66848+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
66849+ GR_DELETE | GR_INHERIT;
66850+
66851+ if (unlikely(!(gr_status & GR_READY)))
66852+ return (GR_CREATE | GR_LINK);
66853+
66854+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
66855+ oldmode = obj->mode;
66856+
66857+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
66858+ newmode = obj->mode;
66859+
66860+ needmode = newmode & checkmodes;
66861+
66862+ // old name for hardlink must have at least the permissions of the new name
66863+ if ((oldmode & needmode) != needmode)
66864+ goto bad;
66865+
66866+ // if old name had restrictions/auditing, make sure the new name does as well
66867+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
66868+
66869+ // don't allow hardlinking of suid/sgid/fcapped files without permission
66870+ if (is_privileged_binary(old_dentry))
66871+ needmode |= GR_SETID;
66872+
66873+ if ((newmode & needmode) != needmode)
66874+ goto bad;
66875+
66876+ // enforce minimum permissions
66877+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
66878+ return newmode;
66879+bad:
66880+ needmode = oldmode;
66881+ if (is_privileged_binary(old_dentry))
66882+ needmode |= GR_SETID;
66883+
66884+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
66885+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
66886+ return (GR_CREATE | GR_LINK);
66887+ } else if (newmode & GR_SUPPRESS)
66888+ return GR_SUPPRESS;
66889+ else
66890+ return 0;
66891+}
66892+
66893+int
66894+gr_check_hidden_task(const struct task_struct *task)
66895+{
66896+ if (unlikely(!(gr_status & GR_READY)))
66897+ return 0;
66898+
66899+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
66900+ return 1;
66901+
66902+ return 0;
66903+}
66904+
66905+int
66906+gr_check_protected_task(const struct task_struct *task)
66907+{
66908+ if (unlikely(!(gr_status & GR_READY) || !task))
66909+ return 0;
66910+
66911+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
66912+ task->acl != current->acl)
66913+ return 1;
66914+
66915+ return 0;
66916+}
66917+
66918+int
66919+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
66920+{
66921+ struct task_struct *p;
66922+ int ret = 0;
66923+
66924+ if (unlikely(!(gr_status & GR_READY) || !pid))
66925+ return ret;
66926+
66927+ read_lock(&tasklist_lock);
66928+ do_each_pid_task(pid, type, p) {
66929+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
66930+ p->acl != current->acl) {
66931+ ret = 1;
66932+ goto out;
66933+ }
66934+ } while_each_pid_task(pid, type, p);
66935+out:
66936+ read_unlock(&tasklist_lock);
66937+
66938+ return ret;
66939+}
66940+
66941+void
66942+gr_copy_label(struct task_struct *tsk)
66943+{
66944+ struct task_struct *p = current;
66945+
66946+ tsk->inherited = p->inherited;
66947+ tsk->acl_sp_role = 0;
66948+ tsk->acl_role_id = p->acl_role_id;
66949+ tsk->acl = p->acl;
66950+ tsk->role = p->role;
66951+ tsk->signal->used_accept = 0;
66952+ tsk->signal->curr_ip = p->signal->curr_ip;
66953+ tsk->signal->saved_ip = p->signal->saved_ip;
66954+ if (p->exec_file)
66955+ get_file(p->exec_file);
66956+ tsk->exec_file = p->exec_file;
66957+ tsk->is_writable = p->is_writable;
66958+ if (unlikely(p->signal->used_accept)) {
66959+ p->signal->curr_ip = 0;
66960+ p->signal->saved_ip = 0;
66961+ }
66962+
66963+ return;
66964+}
66965+
66966+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
66967+
66968+int
66969+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
66970+{
66971+ unsigned int i;
66972+ __u16 num;
66973+ uid_t *uidlist;
66974+ uid_t curuid;
66975+ int realok = 0;
66976+ int effectiveok = 0;
66977+ int fsok = 0;
66978+ uid_t globalreal, globaleffective, globalfs;
66979+
66980+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
66981+ struct user_struct *user;
66982+
66983+ if (!uid_valid(real))
66984+ goto skipit;
66985+
66986+ /* find user based on global namespace */
66987+
66988+ globalreal = GR_GLOBAL_UID(real);
66989+
66990+ user = find_user(make_kuid(&init_user_ns, globalreal));
66991+ if (user == NULL)
66992+ goto skipit;
66993+
66994+ if (gr_process_kernel_setuid_ban(user)) {
66995+ /* for find_user */
66996+ free_uid(user);
66997+ return 1;
66998+ }
66999+
67000+ /* for find_user */
67001+ free_uid(user);
67002+
67003+skipit:
67004+#endif
67005+
67006+ if (unlikely(!(gr_status & GR_READY)))
67007+ return 0;
67008+
67009+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
67010+ gr_log_learn_uid_change(real, effective, fs);
67011+
67012+ num = current->acl->user_trans_num;
67013+ uidlist = current->acl->user_transitions;
67014+
67015+ if (uidlist == NULL)
67016+ return 0;
67017+
67018+ if (!uid_valid(real)) {
67019+ realok = 1;
67020+ globalreal = (uid_t)-1;
67021+ } else {
67022+ globalreal = GR_GLOBAL_UID(real);
67023+ }
67024+ if (!uid_valid(effective)) {
67025+ effectiveok = 1;
67026+ globaleffective = (uid_t)-1;
67027+ } else {
67028+ globaleffective = GR_GLOBAL_UID(effective);
67029+ }
67030+ if (!uid_valid(fs)) {
67031+ fsok = 1;
67032+ globalfs = (uid_t)-1;
67033+ } else {
67034+ globalfs = GR_GLOBAL_UID(fs);
67035+ }
67036+
67037+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
67038+ for (i = 0; i < num; i++) {
67039+ curuid = uidlist[i];
67040+ if (globalreal == curuid)
67041+ realok = 1;
67042+ if (globaleffective == curuid)
67043+ effectiveok = 1;
67044+ if (globalfs == curuid)
67045+ fsok = 1;
67046+ }
67047+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
67048+ for (i = 0; i < num; i++) {
67049+ curuid = uidlist[i];
67050+ if (globalreal == curuid)
67051+ break;
67052+ if (globaleffective == curuid)
67053+ break;
67054+ if (globalfs == curuid)
67055+ break;
67056+ }
67057+ /* not in deny list */
67058+ if (i == num) {
67059+ realok = 1;
67060+ effectiveok = 1;
67061+ fsok = 1;
67062+ }
67063+ }
67064+
67065+ if (realok && effectiveok && fsok)
67066+ return 0;
67067+ else {
67068+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
67069+ return 1;
67070+ }
67071+}
67072+
67073+int
67074+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
67075+{
67076+ unsigned int i;
67077+ __u16 num;
67078+ gid_t *gidlist;
67079+ gid_t curgid;
67080+ int realok = 0;
67081+ int effectiveok = 0;
67082+ int fsok = 0;
67083+ gid_t globalreal, globaleffective, globalfs;
67084+
67085+ if (unlikely(!(gr_status & GR_READY)))
67086+ return 0;
67087+
67088+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
67089+ gr_log_learn_gid_change(real, effective, fs);
67090+
67091+ num = current->acl->group_trans_num;
67092+ gidlist = current->acl->group_transitions;
67093+
67094+ if (gidlist == NULL)
67095+ return 0;
67096+
67097+ if (!gid_valid(real)) {
67098+ realok = 1;
67099+ globalreal = (gid_t)-1;
67100+ } else {
67101+ globalreal = GR_GLOBAL_GID(real);
67102+ }
67103+ if (!gid_valid(effective)) {
67104+ effectiveok = 1;
67105+ globaleffective = (gid_t)-1;
67106+ } else {
67107+ globaleffective = GR_GLOBAL_GID(effective);
67108+ }
67109+ if (!gid_valid(fs)) {
67110+ fsok = 1;
67111+ globalfs = (gid_t)-1;
67112+ } else {
67113+ globalfs = GR_GLOBAL_GID(fs);
67114+ }
67115+
67116+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
67117+ for (i = 0; i < num; i++) {
67118+ curgid = gidlist[i];
67119+ if (globalreal == curgid)
67120+ realok = 1;
67121+ if (globaleffective == curgid)
67122+ effectiveok = 1;
67123+ if (globalfs == curgid)
67124+ fsok = 1;
67125+ }
67126+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
67127+ for (i = 0; i < num; i++) {
67128+ curgid = gidlist[i];
67129+ if (globalreal == curgid)
67130+ break;
67131+ if (globaleffective == curgid)
67132+ break;
67133+ if (globalfs == curgid)
67134+ break;
67135+ }
67136+ /* not in deny list */
67137+ if (i == num) {
67138+ realok = 1;
67139+ effectiveok = 1;
67140+ fsok = 1;
67141+ }
67142+ }
67143+
67144+ if (realok && effectiveok && fsok)
67145+ return 0;
67146+ else {
67147+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
67148+ return 1;
67149+ }
67150+}
67151+
67152+extern int gr_acl_is_capable(const int cap);
67153+
67154+void
67155+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
67156+{
67157+ struct acl_role_label *role = task->role;
67158+ struct acl_subject_label *subj = NULL;
67159+ struct acl_object_label *obj;
67160+ struct file *filp;
67161+ uid_t uid;
67162+ gid_t gid;
67163+
67164+ if (unlikely(!(gr_status & GR_READY)))
67165+ return;
67166+
67167+ uid = GR_GLOBAL_UID(kuid);
67168+ gid = GR_GLOBAL_GID(kgid);
67169+
67170+ filp = task->exec_file;
67171+
67172+ /* kernel process, we'll give them the kernel role */
67173+ if (unlikely(!filp)) {
67174+ task->role = running_polstate.kernel_role;
67175+ task->acl = running_polstate.kernel_role->root_label;
67176+ return;
67177+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
67178+ /* save the current ip at time of role lookup so that the proper
67179+ IP will be learned for role_allowed_ip */
67180+ task->signal->saved_ip = task->signal->curr_ip;
67181+ role = lookup_acl_role_label(task, uid, gid);
67182+ }
67183+
67184+ /* don't change the role if we're not a privileged process */
67185+ if (role && task->role != role &&
67186+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
67187+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
67188+ return;
67189+
67190+ /* perform subject lookup in possibly new role
67191+ we can use this result below in the case where role == task->role
67192+ */
67193+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
67194+
67195+ /* if we changed uid/gid, but result in the same role
67196+ and are using inheritance, don't lose the inherited subject
67197+ if current subject is other than what normal lookup
67198+ would result in, we arrived via inheritance, don't
67199+ lose subject
67200+ */
67201+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
67202+ (subj == task->acl)))
67203+ task->acl = subj;
67204+
67205+ /* leave task->inherited unaffected */
67206+
67207+ task->role = role;
67208+
67209+ task->is_writable = 0;
67210+
67211+ /* ignore additional mmap checks for processes that are writable
67212+ by the default ACL */
67213+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67214+ if (unlikely(obj->mode & GR_WRITE))
67215+ task->is_writable = 1;
67216+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
67217+ if (unlikely(obj->mode & GR_WRITE))
67218+ task->is_writable = 1;
67219+
67220+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67221+ 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);
67222+#endif
67223+
67224+ gr_set_proc_res(task);
67225+
67226+ return;
67227+}
67228+
67229+int
67230+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
67231+ const int unsafe_flags)
67232+{
67233+ struct task_struct *task = current;
67234+ struct acl_subject_label *newacl;
67235+ struct acl_object_label *obj;
67236+ __u32 retmode;
67237+
67238+ if (unlikely(!(gr_status & GR_READY)))
67239+ return 0;
67240+
67241+ newacl = chk_subj_label(dentry, mnt, task->role);
67242+
67243+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
67244+ did an exec
67245+ */
67246+ rcu_read_lock();
67247+ read_lock(&tasklist_lock);
67248+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
67249+ (task->parent->acl->mode & GR_POVERRIDE))) {
67250+ read_unlock(&tasklist_lock);
67251+ rcu_read_unlock();
67252+ goto skip_check;
67253+ }
67254+ read_unlock(&tasklist_lock);
67255+ rcu_read_unlock();
67256+
67257+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
67258+ !(task->role->roletype & GR_ROLE_GOD) &&
67259+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
67260+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
67261+ if (unsafe_flags & LSM_UNSAFE_SHARE)
67262+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
67263+ else
67264+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
67265+ return -EACCES;
67266+ }
67267+
67268+skip_check:
67269+
67270+ obj = chk_obj_label(dentry, mnt, task->acl);
67271+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
67272+
67273+ if (!(task->acl->mode & GR_INHERITLEARN) &&
67274+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
67275+ if (obj->nested)
67276+ task->acl = obj->nested;
67277+ else
67278+ task->acl = newacl;
67279+ task->inherited = 0;
67280+ } else {
67281+ task->inherited = 1;
67282+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
67283+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
67284+ }
67285+
67286+ task->is_writable = 0;
67287+
67288+ /* ignore additional mmap checks for processes that are writable
67289+ by the default ACL */
67290+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
67291+ if (unlikely(obj->mode & GR_WRITE))
67292+ task->is_writable = 1;
67293+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
67294+ if (unlikely(obj->mode & GR_WRITE))
67295+ task->is_writable = 1;
67296+
67297+ gr_set_proc_res(task);
67298+
67299+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67300+ 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);
67301+#endif
67302+ return 0;
67303+}
67304+
67305+/* always called with valid inodev ptr */
67306+static void
67307+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
67308+{
67309+ struct acl_object_label *matchpo;
67310+ struct acl_subject_label *matchps;
67311+ struct acl_subject_label *subj;
67312+ struct acl_role_label *role;
67313+ unsigned int x;
67314+
67315+ FOR_EACH_ROLE_START(role)
67316+ FOR_EACH_SUBJECT_START(role, subj, x)
67317+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
67318+ matchpo->mode |= GR_DELETED;
67319+ FOR_EACH_SUBJECT_END(subj,x)
67320+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
67321+ /* nested subjects aren't in the role's subj_hash table */
67322+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
67323+ matchpo->mode |= GR_DELETED;
67324+ FOR_EACH_NESTED_SUBJECT_END(subj)
67325+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
67326+ matchps->mode |= GR_DELETED;
67327+ FOR_EACH_ROLE_END(role)
67328+
67329+ inodev->nentry->deleted = 1;
67330+
67331+ return;
67332+}
67333+
67334+void
67335+gr_handle_delete(const ino_t ino, const dev_t dev)
67336+{
67337+ struct inodev_entry *inodev;
67338+
67339+ if (unlikely(!(gr_status & GR_READY)))
67340+ return;
67341+
67342+ write_lock(&gr_inode_lock);
67343+ inodev = lookup_inodev_entry(ino, dev);
67344+ if (inodev != NULL)
67345+ do_handle_delete(inodev, ino, dev);
67346+ write_unlock(&gr_inode_lock);
67347+
67348+ return;
67349+}
67350+
67351+static void
67352+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
67353+ const ino_t newinode, const dev_t newdevice,
67354+ struct acl_subject_label *subj)
67355+{
67356+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
67357+ struct acl_object_label *match;
67358+
67359+ match = subj->obj_hash[index];
67360+
67361+ while (match && (match->inode != oldinode ||
67362+ match->device != olddevice ||
67363+ !(match->mode & GR_DELETED)))
67364+ match = match->next;
67365+
67366+ if (match && (match->inode == oldinode)
67367+ && (match->device == olddevice)
67368+ && (match->mode & GR_DELETED)) {
67369+ if (match->prev == NULL) {
67370+ subj->obj_hash[index] = match->next;
67371+ if (match->next != NULL)
67372+ match->next->prev = NULL;
67373+ } else {
67374+ match->prev->next = match->next;
67375+ if (match->next != NULL)
67376+ match->next->prev = match->prev;
67377+ }
67378+ match->prev = NULL;
67379+ match->next = NULL;
67380+ match->inode = newinode;
67381+ match->device = newdevice;
67382+ match->mode &= ~GR_DELETED;
67383+
67384+ insert_acl_obj_label(match, subj);
67385+ }
67386+
67387+ return;
67388+}
67389+
67390+static void
67391+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
67392+ const ino_t newinode, const dev_t newdevice,
67393+ struct acl_role_label *role)
67394+{
67395+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
67396+ struct acl_subject_label *match;
67397+
67398+ match = role->subj_hash[index];
67399+
67400+ while (match && (match->inode != oldinode ||
67401+ match->device != olddevice ||
67402+ !(match->mode & GR_DELETED)))
67403+ match = match->next;
67404+
67405+ if (match && (match->inode == oldinode)
67406+ && (match->device == olddevice)
67407+ && (match->mode & GR_DELETED)) {
67408+ if (match->prev == NULL) {
67409+ role->subj_hash[index] = match->next;
67410+ if (match->next != NULL)
67411+ match->next->prev = NULL;
67412+ } else {
67413+ match->prev->next = match->next;
67414+ if (match->next != NULL)
67415+ match->next->prev = match->prev;
67416+ }
67417+ match->prev = NULL;
67418+ match->next = NULL;
67419+ match->inode = newinode;
67420+ match->device = newdevice;
67421+ match->mode &= ~GR_DELETED;
67422+
67423+ insert_acl_subj_label(match, role);
67424+ }
67425+
67426+ return;
67427+}
67428+
67429+static void
67430+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
67431+ const ino_t newinode, const dev_t newdevice)
67432+{
67433+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
67434+ struct inodev_entry *match;
67435+
67436+ match = running_polstate.inodev_set.i_hash[index];
67437+
67438+ while (match && (match->nentry->inode != oldinode ||
67439+ match->nentry->device != olddevice || !match->nentry->deleted))
67440+ match = match->next;
67441+
67442+ if (match && (match->nentry->inode == oldinode)
67443+ && (match->nentry->device == olddevice) &&
67444+ match->nentry->deleted) {
67445+ if (match->prev == NULL) {
67446+ running_polstate.inodev_set.i_hash[index] = match->next;
67447+ if (match->next != NULL)
67448+ match->next->prev = NULL;
67449+ } else {
67450+ match->prev->next = match->next;
67451+ if (match->next != NULL)
67452+ match->next->prev = match->prev;
67453+ }
67454+ match->prev = NULL;
67455+ match->next = NULL;
67456+ match->nentry->inode = newinode;
67457+ match->nentry->device = newdevice;
67458+ match->nentry->deleted = 0;
67459+
67460+ insert_inodev_entry(match);
67461+ }
67462+
67463+ return;
67464+}
67465+
67466+static void
67467+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
67468+{
67469+ struct acl_subject_label *subj;
67470+ struct acl_role_label *role;
67471+ unsigned int x;
67472+
67473+ FOR_EACH_ROLE_START(role)
67474+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
67475+
67476+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
67477+ if ((subj->inode == ino) && (subj->device == dev)) {
67478+ subj->inode = ino;
67479+ subj->device = dev;
67480+ }
67481+ /* nested subjects aren't in the role's subj_hash table */
67482+ update_acl_obj_label(matchn->inode, matchn->device,
67483+ ino, dev, subj);
67484+ FOR_EACH_NESTED_SUBJECT_END(subj)
67485+ FOR_EACH_SUBJECT_START(role, subj, x)
67486+ update_acl_obj_label(matchn->inode, matchn->device,
67487+ ino, dev, subj);
67488+ FOR_EACH_SUBJECT_END(subj,x)
67489+ FOR_EACH_ROLE_END(role)
67490+
67491+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
67492+
67493+ return;
67494+}
67495+
67496+static void
67497+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
67498+ const struct vfsmount *mnt)
67499+{
67500+ ino_t ino = dentry->d_inode->i_ino;
67501+ dev_t dev = __get_dev(dentry);
67502+
67503+ __do_handle_create(matchn, ino, dev);
67504+
67505+ return;
67506+}
67507+
67508+void
67509+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
67510+{
67511+ struct name_entry *matchn;
67512+
67513+ if (unlikely(!(gr_status & GR_READY)))
67514+ return;
67515+
67516+ preempt_disable();
67517+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
67518+
67519+ if (unlikely((unsigned long)matchn)) {
67520+ write_lock(&gr_inode_lock);
67521+ do_handle_create(matchn, dentry, mnt);
67522+ write_unlock(&gr_inode_lock);
67523+ }
67524+ preempt_enable();
67525+
67526+ return;
67527+}
67528+
67529+void
67530+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
67531+{
67532+ struct name_entry *matchn;
67533+
67534+ if (unlikely(!(gr_status & GR_READY)))
67535+ return;
67536+
67537+ preempt_disable();
67538+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
67539+
67540+ if (unlikely((unsigned long)matchn)) {
67541+ write_lock(&gr_inode_lock);
67542+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
67543+ write_unlock(&gr_inode_lock);
67544+ }
67545+ preempt_enable();
67546+
67547+ return;
67548+}
67549+
67550+void
67551+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
67552+ struct dentry *old_dentry,
67553+ struct dentry *new_dentry,
67554+ struct vfsmount *mnt, const __u8 replace)
67555+{
67556+ struct name_entry *matchn;
67557+ struct inodev_entry *inodev;
67558+ struct inode *inode = new_dentry->d_inode;
67559+ ino_t old_ino = old_dentry->d_inode->i_ino;
67560+ dev_t old_dev = __get_dev(old_dentry);
67561+
67562+ /* vfs_rename swaps the name and parent link for old_dentry and
67563+ new_dentry
67564+ at this point, old_dentry has the new name, parent link, and inode
67565+ for the renamed file
67566+ if a file is being replaced by a rename, new_dentry has the inode
67567+ and name for the replaced file
67568+ */
67569+
67570+ if (unlikely(!(gr_status & GR_READY)))
67571+ return;
67572+
67573+ preempt_disable();
67574+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
67575+
67576+ /* we wouldn't have to check d_inode if it weren't for
67577+ NFS silly-renaming
67578+ */
67579+
67580+ write_lock(&gr_inode_lock);
67581+ if (unlikely(replace && inode)) {
67582+ ino_t new_ino = inode->i_ino;
67583+ dev_t new_dev = __get_dev(new_dentry);
67584+
67585+ inodev = lookup_inodev_entry(new_ino, new_dev);
67586+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
67587+ do_handle_delete(inodev, new_ino, new_dev);
67588+ }
67589+
67590+ inodev = lookup_inodev_entry(old_ino, old_dev);
67591+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
67592+ do_handle_delete(inodev, old_ino, old_dev);
67593+
67594+ if (unlikely((unsigned long)matchn))
67595+ do_handle_create(matchn, old_dentry, mnt);
67596+
67597+ write_unlock(&gr_inode_lock);
67598+ preempt_enable();
67599+
67600+ return;
67601+}
67602+
67603+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
67604+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
67605+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
67606+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
67607+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
67608+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
67609+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
67610+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
67611+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
67612+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
67613+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
67614+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
67615+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
67616+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
67617+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
67618+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
67619+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
67620+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
67621+};
67622+
67623+void
67624+gr_learn_resource(const struct task_struct *task,
67625+ const int res, const unsigned long wanted, const int gt)
67626+{
67627+ struct acl_subject_label *acl;
67628+ const struct cred *cred;
67629+
67630+ if (unlikely((gr_status & GR_READY) &&
67631+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
67632+ goto skip_reslog;
67633+
67634+ gr_log_resource(task, res, wanted, gt);
67635+skip_reslog:
67636+
67637+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
67638+ return;
67639+
67640+ acl = task->acl;
67641+
67642+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
67643+ !(acl->resmask & (1U << (unsigned short) res))))
67644+ return;
67645+
67646+ if (wanted >= acl->res[res].rlim_cur) {
67647+ unsigned long res_add;
67648+
67649+ res_add = wanted + res_learn_bumps[res];
67650+
67651+ acl->res[res].rlim_cur = res_add;
67652+
67653+ if (wanted > acl->res[res].rlim_max)
67654+ acl->res[res].rlim_max = res_add;
67655+
67656+ /* only log the subject filename, since resource logging is supported for
67657+ single-subject learning only */
67658+ rcu_read_lock();
67659+ cred = __task_cred(task);
67660+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
67661+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
67662+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
67663+ "", (unsigned long) res, &task->signal->saved_ip);
67664+ rcu_read_unlock();
67665+ }
67666+
67667+ return;
67668+}
67669+EXPORT_SYMBOL(gr_learn_resource);
67670+#endif
67671+
67672+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
67673+void
67674+pax_set_initial_flags(struct linux_binprm *bprm)
67675+{
67676+ struct task_struct *task = current;
67677+ struct acl_subject_label *proc;
67678+ unsigned long flags;
67679+
67680+ if (unlikely(!(gr_status & GR_READY)))
67681+ return;
67682+
67683+ flags = pax_get_flags(task);
67684+
67685+ proc = task->acl;
67686+
67687+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
67688+ flags &= ~MF_PAX_PAGEEXEC;
67689+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
67690+ flags &= ~MF_PAX_SEGMEXEC;
67691+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
67692+ flags &= ~MF_PAX_RANDMMAP;
67693+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
67694+ flags &= ~MF_PAX_EMUTRAMP;
67695+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
67696+ flags &= ~MF_PAX_MPROTECT;
67697+
67698+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
67699+ flags |= MF_PAX_PAGEEXEC;
67700+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
67701+ flags |= MF_PAX_SEGMEXEC;
67702+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
67703+ flags |= MF_PAX_RANDMMAP;
67704+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
67705+ flags |= MF_PAX_EMUTRAMP;
67706+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
67707+ flags |= MF_PAX_MPROTECT;
67708+
67709+ pax_set_flags(task, flags);
67710+
67711+ return;
67712+}
67713+#endif
67714+
67715+int
67716+gr_handle_proc_ptrace(struct task_struct *task)
67717+{
67718+ struct file *filp;
67719+ struct task_struct *tmp = task;
67720+ struct task_struct *curtemp = current;
67721+ __u32 retmode;
67722+
67723+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
67724+ if (unlikely(!(gr_status & GR_READY)))
67725+ return 0;
67726+#endif
67727+
67728+ read_lock(&tasklist_lock);
67729+ read_lock(&grsec_exec_file_lock);
67730+ filp = task->exec_file;
67731+
67732+ while (task_pid_nr(tmp) > 0) {
67733+ if (tmp == curtemp)
67734+ break;
67735+ tmp = tmp->real_parent;
67736+ }
67737+
67738+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
67739+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
67740+ read_unlock(&grsec_exec_file_lock);
67741+ read_unlock(&tasklist_lock);
67742+ return 1;
67743+ }
67744+
67745+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
67746+ if (!(gr_status & GR_READY)) {
67747+ read_unlock(&grsec_exec_file_lock);
67748+ read_unlock(&tasklist_lock);
67749+ return 0;
67750+ }
67751+#endif
67752+
67753+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
67754+ read_unlock(&grsec_exec_file_lock);
67755+ read_unlock(&tasklist_lock);
67756+
67757+ if (retmode & GR_NOPTRACE)
67758+ return 1;
67759+
67760+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
67761+ && (current->acl != task->acl || (current->acl != current->role->root_label
67762+ && task_pid_nr(current) != task_pid_nr(task))))
67763+ return 1;
67764+
67765+ return 0;
67766+}
67767+
67768+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
67769+{
67770+ if (unlikely(!(gr_status & GR_READY)))
67771+ return;
67772+
67773+ if (!(current->role->roletype & GR_ROLE_GOD))
67774+ return;
67775+
67776+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
67777+ p->role->rolename, gr_task_roletype_to_char(p),
67778+ p->acl->filename);
67779+}
67780+
67781+int
67782+gr_handle_ptrace(struct task_struct *task, const long request)
67783+{
67784+ struct task_struct *tmp = task;
67785+ struct task_struct *curtemp = current;
67786+ __u32 retmode;
67787+
67788+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
67789+ if (unlikely(!(gr_status & GR_READY)))
67790+ return 0;
67791+#endif
67792+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67793+ read_lock(&tasklist_lock);
67794+ while (task_pid_nr(tmp) > 0) {
67795+ if (tmp == curtemp)
67796+ break;
67797+ tmp = tmp->real_parent;
67798+ }
67799+
67800+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
67801+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
67802+ read_unlock(&tasklist_lock);
67803+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67804+ return 1;
67805+ }
67806+ read_unlock(&tasklist_lock);
67807+ }
67808+
67809+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
67810+ if (!(gr_status & GR_READY))
67811+ return 0;
67812+#endif
67813+
67814+ read_lock(&grsec_exec_file_lock);
67815+ if (unlikely(!task->exec_file)) {
67816+ read_unlock(&grsec_exec_file_lock);
67817+ return 0;
67818+ }
67819+
67820+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
67821+ read_unlock(&grsec_exec_file_lock);
67822+
67823+ if (retmode & GR_NOPTRACE) {
67824+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67825+ return 1;
67826+ }
67827+
67828+ if (retmode & GR_PTRACERD) {
67829+ switch (request) {
67830+ case PTRACE_SEIZE:
67831+ case PTRACE_POKETEXT:
67832+ case PTRACE_POKEDATA:
67833+ case PTRACE_POKEUSR:
67834+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
67835+ case PTRACE_SETREGS:
67836+ case PTRACE_SETFPREGS:
67837+#endif
67838+#ifdef CONFIG_X86
67839+ case PTRACE_SETFPXREGS:
67840+#endif
67841+#ifdef CONFIG_ALTIVEC
67842+ case PTRACE_SETVRREGS:
67843+#endif
67844+ return 1;
67845+ default:
67846+ return 0;
67847+ }
67848+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
67849+ !(current->role->roletype & GR_ROLE_GOD) &&
67850+ (current->acl != task->acl)) {
67851+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67852+ return 1;
67853+ }
67854+
67855+ return 0;
67856+}
67857+
67858+static int is_writable_mmap(const struct file *filp)
67859+{
67860+ struct task_struct *task = current;
67861+ struct acl_object_label *obj, *obj2;
67862+
67863+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
67864+ !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))) {
67865+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67866+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
67867+ task->role->root_label);
67868+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
67869+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
67870+ return 1;
67871+ }
67872+ }
67873+ return 0;
67874+}
67875+
67876+int
67877+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
67878+{
67879+ __u32 mode;
67880+
67881+ if (unlikely(!file || !(prot & PROT_EXEC)))
67882+ return 1;
67883+
67884+ if (is_writable_mmap(file))
67885+ return 0;
67886+
67887+ mode =
67888+ gr_search_file(file->f_path.dentry,
67889+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
67890+ file->f_path.mnt);
67891+
67892+ if (!gr_tpe_allow(file))
67893+ return 0;
67894+
67895+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
67896+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67897+ return 0;
67898+ } else if (unlikely(!(mode & GR_EXEC))) {
67899+ return 0;
67900+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
67901+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67902+ return 1;
67903+ }
67904+
67905+ return 1;
67906+}
67907+
67908+int
67909+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
67910+{
67911+ __u32 mode;
67912+
67913+ if (unlikely(!file || !(prot & PROT_EXEC)))
67914+ return 1;
67915+
67916+ if (is_writable_mmap(file))
67917+ return 0;
67918+
67919+ mode =
67920+ gr_search_file(file->f_path.dentry,
67921+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
67922+ file->f_path.mnt);
67923+
67924+ if (!gr_tpe_allow(file))
67925+ return 0;
67926+
67927+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
67928+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67929+ return 0;
67930+ } else if (unlikely(!(mode & GR_EXEC))) {
67931+ return 0;
67932+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
67933+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67934+ return 1;
67935+ }
67936+
67937+ return 1;
67938+}
67939+
67940+void
67941+gr_acl_handle_psacct(struct task_struct *task, const long code)
67942+{
67943+ unsigned long runtime, cputime;
67944+ cputime_t utime, stime;
67945+ unsigned int wday, cday;
67946+ __u8 whr, chr;
67947+ __u8 wmin, cmin;
67948+ __u8 wsec, csec;
67949+ struct timespec timeval;
67950+
67951+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
67952+ !(task->acl->mode & GR_PROCACCT)))
67953+ return;
67954+
67955+ do_posix_clock_monotonic_gettime(&timeval);
67956+ runtime = timeval.tv_sec - task->start_time.tv_sec;
67957+ wday = runtime / (60 * 60 * 24);
67958+ runtime -= wday * (60 * 60 * 24);
67959+ whr = runtime / (60 * 60);
67960+ runtime -= whr * (60 * 60);
67961+ wmin = runtime / 60;
67962+ runtime -= wmin * 60;
67963+ wsec = runtime;
67964+
67965+ task_cputime(task, &utime, &stime);
67966+ cputime = cputime_to_secs(utime + stime);
67967+ cday = cputime / (60 * 60 * 24);
67968+ cputime -= cday * (60 * 60 * 24);
67969+ chr = cputime / (60 * 60);
67970+ cputime -= chr * (60 * 60);
67971+ cmin = cputime / 60;
67972+ cputime -= cmin * 60;
67973+ csec = cputime;
67974+
67975+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
67976+
67977+ return;
67978+}
67979+
67980+#ifdef CONFIG_TASKSTATS
67981+int gr_is_taskstats_denied(int pid)
67982+{
67983+ struct task_struct *task;
67984+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67985+ const struct cred *cred;
67986+#endif
67987+ int ret = 0;
67988+
67989+ /* restrict taskstats viewing to un-chrooted root users
67990+ who have the 'view' subject flag if the RBAC system is enabled
67991+ */
67992+
67993+ rcu_read_lock();
67994+ read_lock(&tasklist_lock);
67995+ task = find_task_by_vpid(pid);
67996+ if (task) {
67997+#ifdef CONFIG_GRKERNSEC_CHROOT
67998+ if (proc_is_chrooted(task))
67999+ ret = -EACCES;
68000+#endif
68001+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68002+ cred = __task_cred(task);
68003+#ifdef CONFIG_GRKERNSEC_PROC_USER
68004+ if (gr_is_global_nonroot(cred->uid))
68005+ ret = -EACCES;
68006+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68007+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
68008+ ret = -EACCES;
68009+#endif
68010+#endif
68011+ if (gr_status & GR_READY) {
68012+ if (!(task->acl->mode & GR_VIEW))
68013+ ret = -EACCES;
68014+ }
68015+ } else
68016+ ret = -ENOENT;
68017+
68018+ read_unlock(&tasklist_lock);
68019+ rcu_read_unlock();
68020+
68021+ return ret;
68022+}
68023+#endif
68024+
68025+/* AUXV entries are filled via a descendant of search_binary_handler
68026+ after we've already applied the subject for the target
68027+*/
68028+int gr_acl_enable_at_secure(void)
68029+{
68030+ if (unlikely(!(gr_status & GR_READY)))
68031+ return 0;
68032+
68033+ if (current->acl->mode & GR_ATSECURE)
68034+ return 1;
68035+
68036+ return 0;
68037+}
68038+
68039+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
68040+{
68041+ struct task_struct *task = current;
68042+ struct dentry *dentry = file->f_path.dentry;
68043+ struct vfsmount *mnt = file->f_path.mnt;
68044+ struct acl_object_label *obj, *tmp;
68045+ struct acl_subject_label *subj;
68046+ unsigned int bufsize;
68047+ int is_not_root;
68048+ char *path;
68049+ dev_t dev = __get_dev(dentry);
68050+
68051+ if (unlikely(!(gr_status & GR_READY)))
68052+ return 1;
68053+
68054+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68055+ return 1;
68056+
68057+ /* ignore Eric Biederman */
68058+ if (IS_PRIVATE(dentry->d_inode))
68059+ return 1;
68060+
68061+ subj = task->acl;
68062+ read_lock(&gr_inode_lock);
68063+ do {
68064+ obj = lookup_acl_obj_label(ino, dev, subj);
68065+ if (obj != NULL) {
68066+ read_unlock(&gr_inode_lock);
68067+ return (obj->mode & GR_FIND) ? 1 : 0;
68068+ }
68069+ } while ((subj = subj->parent_subject));
68070+ read_unlock(&gr_inode_lock);
68071+
68072+ /* this is purely an optimization since we're looking for an object
68073+ for the directory we're doing a readdir on
68074+ if it's possible for any globbed object to match the entry we're
68075+ filling into the directory, then the object we find here will be
68076+ an anchor point with attached globbed objects
68077+ */
68078+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
68079+ if (obj->globbed == NULL)
68080+ return (obj->mode & GR_FIND) ? 1 : 0;
68081+
68082+ is_not_root = ((obj->filename[0] == '/') &&
68083+ (obj->filename[1] == '\0')) ? 0 : 1;
68084+ bufsize = PAGE_SIZE - namelen - is_not_root;
68085+
68086+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
68087+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
68088+ return 1;
68089+
68090+ preempt_disable();
68091+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
68092+ bufsize);
68093+
68094+ bufsize = strlen(path);
68095+
68096+ /* if base is "/", don't append an additional slash */
68097+ if (is_not_root)
68098+ *(path + bufsize) = '/';
68099+ memcpy(path + bufsize + is_not_root, name, namelen);
68100+ *(path + bufsize + namelen + is_not_root) = '\0';
68101+
68102+ tmp = obj->globbed;
68103+ while (tmp) {
68104+ if (!glob_match(tmp->filename, path)) {
68105+ preempt_enable();
68106+ return (tmp->mode & GR_FIND) ? 1 : 0;
68107+ }
68108+ tmp = tmp->next;
68109+ }
68110+ preempt_enable();
68111+ return (obj->mode & GR_FIND) ? 1 : 0;
68112+}
68113+
68114+void gr_put_exec_file(struct task_struct *task)
68115+{
68116+ struct file *filp;
68117+
68118+ write_lock(&grsec_exec_file_lock);
68119+ filp = task->exec_file;
68120+ task->exec_file = NULL;
68121+ write_unlock(&grsec_exec_file_lock);
68122+
68123+ if (filp)
68124+ fput(filp);
68125+
68126+ return;
68127+}
68128+
68129+
68130+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
68131+EXPORT_SYMBOL(gr_acl_is_enabled);
68132+#endif
68133+#ifdef CONFIG_SECURITY
68134+EXPORT_SYMBOL(gr_check_user_change);
68135+EXPORT_SYMBOL(gr_check_group_change);
68136+#endif
68137+
68138diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
68139new file mode 100644
68140index 0000000..18ffbbd
68141--- /dev/null
68142+++ b/grsecurity/gracl_alloc.c
68143@@ -0,0 +1,105 @@
68144+#include <linux/kernel.h>
68145+#include <linux/mm.h>
68146+#include <linux/slab.h>
68147+#include <linux/vmalloc.h>
68148+#include <linux/gracl.h>
68149+#include <linux/grsecurity.h>
68150+
68151+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
68152+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
68153+
68154+static __inline__ int
68155+alloc_pop(void)
68156+{
68157+ if (current_alloc_state->alloc_stack_next == 1)
68158+ return 0;
68159+
68160+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
68161+
68162+ current_alloc_state->alloc_stack_next--;
68163+
68164+ return 1;
68165+}
68166+
68167+static __inline__ int
68168+alloc_push(void *buf)
68169+{
68170+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
68171+ return 1;
68172+
68173+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
68174+
68175+ current_alloc_state->alloc_stack_next++;
68176+
68177+ return 0;
68178+}
68179+
68180+void *
68181+acl_alloc(unsigned long len)
68182+{
68183+ void *ret = NULL;
68184+
68185+ if (!len || len > PAGE_SIZE)
68186+ goto out;
68187+
68188+ ret = kmalloc(len, GFP_KERNEL);
68189+
68190+ if (ret) {
68191+ if (alloc_push(ret)) {
68192+ kfree(ret);
68193+ ret = NULL;
68194+ }
68195+ }
68196+
68197+out:
68198+ return ret;
68199+}
68200+
68201+void *
68202+acl_alloc_num(unsigned long num, unsigned long len)
68203+{
68204+ if (!len || (num > (PAGE_SIZE / len)))
68205+ return NULL;
68206+
68207+ return acl_alloc(num * len);
68208+}
68209+
68210+void
68211+acl_free_all(void)
68212+{
68213+ if (!current_alloc_state->alloc_stack)
68214+ return;
68215+
68216+ while (alloc_pop()) ;
68217+
68218+ if (current_alloc_state->alloc_stack) {
68219+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
68220+ kfree(current_alloc_state->alloc_stack);
68221+ else
68222+ vfree(current_alloc_state->alloc_stack);
68223+ }
68224+
68225+ current_alloc_state->alloc_stack = NULL;
68226+ current_alloc_state->alloc_stack_size = 1;
68227+ current_alloc_state->alloc_stack_next = 1;
68228+
68229+ return;
68230+}
68231+
68232+int
68233+acl_alloc_stack_init(unsigned long size)
68234+{
68235+ if ((size * sizeof (void *)) <= PAGE_SIZE)
68236+ current_alloc_state->alloc_stack =
68237+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
68238+ else
68239+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
68240+
68241+ current_alloc_state->alloc_stack_size = size;
68242+ current_alloc_state->alloc_stack_next = 1;
68243+
68244+ if (!current_alloc_state->alloc_stack)
68245+ return 0;
68246+ else
68247+ return 1;
68248+}
68249diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
68250new file mode 100644
68251index 0000000..bdd51ea
68252--- /dev/null
68253+++ b/grsecurity/gracl_cap.c
68254@@ -0,0 +1,110 @@
68255+#include <linux/kernel.h>
68256+#include <linux/module.h>
68257+#include <linux/sched.h>
68258+#include <linux/gracl.h>
68259+#include <linux/grsecurity.h>
68260+#include <linux/grinternal.h>
68261+
68262+extern const char *captab_log[];
68263+extern int captab_log_entries;
68264+
68265+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
68266+{
68267+ struct acl_subject_label *curracl;
68268+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
68269+ kernel_cap_t cap_audit = __cap_empty_set;
68270+
68271+ if (!gr_acl_is_enabled())
68272+ return 1;
68273+
68274+ curracl = task->acl;
68275+
68276+ cap_drop = curracl->cap_lower;
68277+ cap_mask = curracl->cap_mask;
68278+ cap_audit = curracl->cap_invert_audit;
68279+
68280+ while ((curracl = curracl->parent_subject)) {
68281+ /* if the cap isn't specified in the current computed mask but is specified in the
68282+ current level subject, and is lowered in the current level subject, then add
68283+ it to the set of dropped capabilities
68284+ otherwise, add the current level subject's mask to the current computed mask
68285+ */
68286+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
68287+ cap_raise(cap_mask, cap);
68288+ if (cap_raised(curracl->cap_lower, cap))
68289+ cap_raise(cap_drop, cap);
68290+ if (cap_raised(curracl->cap_invert_audit, cap))
68291+ cap_raise(cap_audit, cap);
68292+ }
68293+ }
68294+
68295+ if (!cap_raised(cap_drop, cap)) {
68296+ if (cap_raised(cap_audit, cap))
68297+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
68298+ return 1;
68299+ }
68300+
68301+ curracl = task->acl;
68302+
68303+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
68304+ && cap_raised(cred->cap_effective, cap)) {
68305+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
68306+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
68307+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
68308+ gr_to_filename(task->exec_file->f_path.dentry,
68309+ task->exec_file->f_path.mnt) : curracl->filename,
68310+ curracl->filename, 0UL,
68311+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
68312+ return 1;
68313+ }
68314+
68315+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
68316+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
68317+
68318+ return 0;
68319+}
68320+
68321+int
68322+gr_acl_is_capable(const int cap)
68323+{
68324+ return gr_task_acl_is_capable(current, current_cred(), cap);
68325+}
68326+
68327+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
68328+{
68329+ struct acl_subject_label *curracl;
68330+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
68331+
68332+ if (!gr_acl_is_enabled())
68333+ return 1;
68334+
68335+ curracl = task->acl;
68336+
68337+ cap_drop = curracl->cap_lower;
68338+ cap_mask = curracl->cap_mask;
68339+
68340+ while ((curracl = curracl->parent_subject)) {
68341+ /* if the cap isn't specified in the current computed mask but is specified in the
68342+ current level subject, and is lowered in the current level subject, then add
68343+ it to the set of dropped capabilities
68344+ otherwise, add the current level subject's mask to the current computed mask
68345+ */
68346+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
68347+ cap_raise(cap_mask, cap);
68348+ if (cap_raised(curracl->cap_lower, cap))
68349+ cap_raise(cap_drop, cap);
68350+ }
68351+ }
68352+
68353+ if (!cap_raised(cap_drop, cap))
68354+ return 1;
68355+
68356+ return 0;
68357+}
68358+
68359+int
68360+gr_acl_is_capable_nolog(const int cap)
68361+{
68362+ return gr_task_acl_is_capable_nolog(current, cap);
68363+}
68364+
68365diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
68366new file mode 100644
68367index 0000000..ca25605
68368--- /dev/null
68369+++ b/grsecurity/gracl_compat.c
68370@@ -0,0 +1,270 @@
68371+#include <linux/kernel.h>
68372+#include <linux/gracl.h>
68373+#include <linux/compat.h>
68374+#include <linux/gracl_compat.h>
68375+
68376+#include <asm/uaccess.h>
68377+
68378+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
68379+{
68380+ struct gr_arg_wrapper_compat uwrapcompat;
68381+
68382+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
68383+ return -EFAULT;
68384+
68385+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
68386+ (uwrapcompat.version != 0x2901)) ||
68387+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
68388+ return -EINVAL;
68389+
68390+ uwrap->arg = compat_ptr(uwrapcompat.arg);
68391+ uwrap->version = uwrapcompat.version;
68392+ uwrap->size = sizeof(struct gr_arg);
68393+
68394+ return 0;
68395+}
68396+
68397+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
68398+{
68399+ struct gr_arg_compat argcompat;
68400+
68401+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
68402+ return -EFAULT;
68403+
68404+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
68405+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
68406+ arg->role_db.num_roles = argcompat.role_db.num_roles;
68407+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
68408+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
68409+ arg->role_db.num_objects = argcompat.role_db.num_objects;
68410+
68411+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
68412+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
68413+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
68414+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
68415+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
68416+ arg->segv_device = argcompat.segv_device;
68417+ arg->segv_inode = argcompat.segv_inode;
68418+ arg->segv_uid = argcompat.segv_uid;
68419+ arg->num_sprole_pws = argcompat.num_sprole_pws;
68420+ arg->mode = argcompat.mode;
68421+
68422+ return 0;
68423+}
68424+
68425+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
68426+{
68427+ struct acl_object_label_compat objcompat;
68428+
68429+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
68430+ return -EFAULT;
68431+
68432+ obj->filename = compat_ptr(objcompat.filename);
68433+ obj->inode = objcompat.inode;
68434+ obj->device = objcompat.device;
68435+ obj->mode = objcompat.mode;
68436+
68437+ obj->nested = compat_ptr(objcompat.nested);
68438+ obj->globbed = compat_ptr(objcompat.globbed);
68439+
68440+ obj->prev = compat_ptr(objcompat.prev);
68441+ obj->next = compat_ptr(objcompat.next);
68442+
68443+ return 0;
68444+}
68445+
68446+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
68447+{
68448+ unsigned int i;
68449+ struct acl_subject_label_compat subjcompat;
68450+
68451+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
68452+ return -EFAULT;
68453+
68454+ subj->filename = compat_ptr(subjcompat.filename);
68455+ subj->inode = subjcompat.inode;
68456+ subj->device = subjcompat.device;
68457+ subj->mode = subjcompat.mode;
68458+ subj->cap_mask = subjcompat.cap_mask;
68459+ subj->cap_lower = subjcompat.cap_lower;
68460+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
68461+
68462+ for (i = 0; i < GR_NLIMITS; i++) {
68463+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
68464+ subj->res[i].rlim_cur = RLIM_INFINITY;
68465+ else
68466+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
68467+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
68468+ subj->res[i].rlim_max = RLIM_INFINITY;
68469+ else
68470+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
68471+ }
68472+ subj->resmask = subjcompat.resmask;
68473+
68474+ subj->user_trans_type = subjcompat.user_trans_type;
68475+ subj->group_trans_type = subjcompat.group_trans_type;
68476+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
68477+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
68478+ subj->user_trans_num = subjcompat.user_trans_num;
68479+ subj->group_trans_num = subjcompat.group_trans_num;
68480+
68481+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
68482+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
68483+ subj->ip_type = subjcompat.ip_type;
68484+ subj->ips = compat_ptr(subjcompat.ips);
68485+ subj->ip_num = subjcompat.ip_num;
68486+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
68487+
68488+ subj->crashes = subjcompat.crashes;
68489+ subj->expires = subjcompat.expires;
68490+
68491+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
68492+ subj->hash = compat_ptr(subjcompat.hash);
68493+ subj->prev = compat_ptr(subjcompat.prev);
68494+ subj->next = compat_ptr(subjcompat.next);
68495+
68496+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
68497+ subj->obj_hash_size = subjcompat.obj_hash_size;
68498+ subj->pax_flags = subjcompat.pax_flags;
68499+
68500+ return 0;
68501+}
68502+
68503+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
68504+{
68505+ struct acl_role_label_compat rolecompat;
68506+
68507+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
68508+ return -EFAULT;
68509+
68510+ role->rolename = compat_ptr(rolecompat.rolename);
68511+ role->uidgid = rolecompat.uidgid;
68512+ role->roletype = rolecompat.roletype;
68513+
68514+ role->auth_attempts = rolecompat.auth_attempts;
68515+ role->expires = rolecompat.expires;
68516+
68517+ role->root_label = compat_ptr(rolecompat.root_label);
68518+ role->hash = compat_ptr(rolecompat.hash);
68519+
68520+ role->prev = compat_ptr(rolecompat.prev);
68521+ role->next = compat_ptr(rolecompat.next);
68522+
68523+ role->transitions = compat_ptr(rolecompat.transitions);
68524+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
68525+ role->domain_children = compat_ptr(rolecompat.domain_children);
68526+ role->domain_child_num = rolecompat.domain_child_num;
68527+
68528+ role->umask = rolecompat.umask;
68529+
68530+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
68531+ role->subj_hash_size = rolecompat.subj_hash_size;
68532+
68533+ return 0;
68534+}
68535+
68536+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
68537+{
68538+ struct role_allowed_ip_compat roleip_compat;
68539+
68540+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
68541+ return -EFAULT;
68542+
68543+ roleip->addr = roleip_compat.addr;
68544+ roleip->netmask = roleip_compat.netmask;
68545+
68546+ roleip->prev = compat_ptr(roleip_compat.prev);
68547+ roleip->next = compat_ptr(roleip_compat.next);
68548+
68549+ return 0;
68550+}
68551+
68552+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
68553+{
68554+ struct role_transition_compat trans_compat;
68555+
68556+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
68557+ return -EFAULT;
68558+
68559+ trans->rolename = compat_ptr(trans_compat.rolename);
68560+
68561+ trans->prev = compat_ptr(trans_compat.prev);
68562+ trans->next = compat_ptr(trans_compat.next);
68563+
68564+ return 0;
68565+
68566+}
68567+
68568+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
68569+{
68570+ struct gr_hash_struct_compat hash_compat;
68571+
68572+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
68573+ return -EFAULT;
68574+
68575+ hash->table = compat_ptr(hash_compat.table);
68576+ hash->nametable = compat_ptr(hash_compat.nametable);
68577+ hash->first = compat_ptr(hash_compat.first);
68578+
68579+ hash->table_size = hash_compat.table_size;
68580+ hash->used_size = hash_compat.used_size;
68581+
68582+ hash->type = hash_compat.type;
68583+
68584+ return 0;
68585+}
68586+
68587+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
68588+{
68589+ compat_uptr_t ptrcompat;
68590+
68591+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
68592+ return -EFAULT;
68593+
68594+ *(void **)ptr = compat_ptr(ptrcompat);
68595+
68596+ return 0;
68597+}
68598+
68599+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
68600+{
68601+ struct acl_ip_label_compat ip_compat;
68602+
68603+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
68604+ return -EFAULT;
68605+
68606+ ip->iface = compat_ptr(ip_compat.iface);
68607+ ip->addr = ip_compat.addr;
68608+ ip->netmask = ip_compat.netmask;
68609+ ip->low = ip_compat.low;
68610+ ip->high = ip_compat.high;
68611+ ip->mode = ip_compat.mode;
68612+ ip->type = ip_compat.type;
68613+
68614+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
68615+
68616+ ip->prev = compat_ptr(ip_compat.prev);
68617+ ip->next = compat_ptr(ip_compat.next);
68618+
68619+ return 0;
68620+}
68621+
68622+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
68623+{
68624+ struct sprole_pw_compat pw_compat;
68625+
68626+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
68627+ return -EFAULT;
68628+
68629+ pw->rolename = compat_ptr(pw_compat.rolename);
68630+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
68631+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
68632+
68633+ return 0;
68634+}
68635+
68636+size_t get_gr_arg_wrapper_size_compat(void)
68637+{
68638+ return sizeof(struct gr_arg_wrapper_compat);
68639+}
68640+
68641diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
68642new file mode 100644
68643index 0000000..a89b1f4
68644--- /dev/null
68645+++ b/grsecurity/gracl_fs.c
68646@@ -0,0 +1,437 @@
68647+#include <linux/kernel.h>
68648+#include <linux/sched.h>
68649+#include <linux/types.h>
68650+#include <linux/fs.h>
68651+#include <linux/file.h>
68652+#include <linux/stat.h>
68653+#include <linux/grsecurity.h>
68654+#include <linux/grinternal.h>
68655+#include <linux/gracl.h>
68656+
68657+umode_t
68658+gr_acl_umask(void)
68659+{
68660+ if (unlikely(!gr_acl_is_enabled()))
68661+ return 0;
68662+
68663+ return current->role->umask;
68664+}
68665+
68666+__u32
68667+gr_acl_handle_hidden_file(const struct dentry * dentry,
68668+ const struct vfsmount * mnt)
68669+{
68670+ __u32 mode;
68671+
68672+ if (unlikely(d_is_negative(dentry)))
68673+ return GR_FIND;
68674+
68675+ mode =
68676+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
68677+
68678+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
68679+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
68680+ return mode;
68681+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
68682+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
68683+ return 0;
68684+ } else if (unlikely(!(mode & GR_FIND)))
68685+ return 0;
68686+
68687+ return GR_FIND;
68688+}
68689+
68690+__u32
68691+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
68692+ int acc_mode)
68693+{
68694+ __u32 reqmode = GR_FIND;
68695+ __u32 mode;
68696+
68697+ if (unlikely(d_is_negative(dentry)))
68698+ return reqmode;
68699+
68700+ if (acc_mode & MAY_APPEND)
68701+ reqmode |= GR_APPEND;
68702+ else if (acc_mode & MAY_WRITE)
68703+ reqmode |= GR_WRITE;
68704+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
68705+ reqmode |= GR_READ;
68706+
68707+ mode =
68708+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
68709+ mnt);
68710+
68711+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68712+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
68713+ reqmode & GR_READ ? " reading" : "",
68714+ reqmode & GR_WRITE ? " writing" : reqmode &
68715+ GR_APPEND ? " appending" : "");
68716+ return reqmode;
68717+ } else
68718+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68719+ {
68720+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
68721+ reqmode & GR_READ ? " reading" : "",
68722+ reqmode & GR_WRITE ? " writing" : reqmode &
68723+ GR_APPEND ? " appending" : "");
68724+ return 0;
68725+ } else if (unlikely((mode & reqmode) != reqmode))
68726+ return 0;
68727+
68728+ return reqmode;
68729+}
68730+
68731+__u32
68732+gr_acl_handle_creat(const struct dentry * dentry,
68733+ const struct dentry * p_dentry,
68734+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
68735+ const int imode)
68736+{
68737+ __u32 reqmode = GR_WRITE | GR_CREATE;
68738+ __u32 mode;
68739+
68740+ if (acc_mode & MAY_APPEND)
68741+ reqmode |= GR_APPEND;
68742+ // if a directory was required or the directory already exists, then
68743+ // don't count this open as a read
68744+ if ((acc_mode & MAY_READ) &&
68745+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
68746+ reqmode |= GR_READ;
68747+ if ((open_flags & O_CREAT) &&
68748+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
68749+ reqmode |= GR_SETID;
68750+
68751+ mode =
68752+ gr_check_create(dentry, p_dentry, p_mnt,
68753+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
68754+
68755+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68756+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
68757+ reqmode & GR_READ ? " reading" : "",
68758+ reqmode & GR_WRITE ? " writing" : reqmode &
68759+ GR_APPEND ? " appending" : "");
68760+ return reqmode;
68761+ } else
68762+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68763+ {
68764+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
68765+ reqmode & GR_READ ? " reading" : "",
68766+ reqmode & GR_WRITE ? " writing" : reqmode &
68767+ GR_APPEND ? " appending" : "");
68768+ return 0;
68769+ } else if (unlikely((mode & reqmode) != reqmode))
68770+ return 0;
68771+
68772+ return reqmode;
68773+}
68774+
68775+__u32
68776+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
68777+ const int fmode)
68778+{
68779+ __u32 mode, reqmode = GR_FIND;
68780+
68781+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
68782+ reqmode |= GR_EXEC;
68783+ if (fmode & S_IWOTH)
68784+ reqmode |= GR_WRITE;
68785+ if (fmode & S_IROTH)
68786+ reqmode |= GR_READ;
68787+
68788+ mode =
68789+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
68790+ mnt);
68791+
68792+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68793+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
68794+ reqmode & GR_READ ? " reading" : "",
68795+ reqmode & GR_WRITE ? " writing" : "",
68796+ reqmode & GR_EXEC ? " executing" : "");
68797+ return reqmode;
68798+ } else
68799+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68800+ {
68801+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
68802+ reqmode & GR_READ ? " reading" : "",
68803+ reqmode & GR_WRITE ? " writing" : "",
68804+ reqmode & GR_EXEC ? " executing" : "");
68805+ return 0;
68806+ } else if (unlikely((mode & reqmode) != reqmode))
68807+ return 0;
68808+
68809+ return reqmode;
68810+}
68811+
68812+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
68813+{
68814+ __u32 mode;
68815+
68816+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
68817+
68818+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
68819+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
68820+ return mode;
68821+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
68822+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
68823+ return 0;
68824+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
68825+ return 0;
68826+
68827+ return (reqmode);
68828+}
68829+
68830+__u32
68831+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
68832+{
68833+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
68834+}
68835+
68836+__u32
68837+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
68838+{
68839+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
68840+}
68841+
68842+__u32
68843+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
68844+{
68845+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
68846+}
68847+
68848+__u32
68849+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
68850+{
68851+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
68852+}
68853+
68854+__u32
68855+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
68856+ umode_t *modeptr)
68857+{
68858+ umode_t mode;
68859+
68860+ *modeptr &= ~gr_acl_umask();
68861+ mode = *modeptr;
68862+
68863+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
68864+ return 1;
68865+
68866+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
68867+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
68868+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
68869+ GR_CHMOD_ACL_MSG);
68870+ } else {
68871+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
68872+ }
68873+}
68874+
68875+__u32
68876+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
68877+{
68878+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
68879+}
68880+
68881+__u32
68882+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
68883+{
68884+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
68885+}
68886+
68887+__u32
68888+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
68889+{
68890+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
68891+}
68892+
68893+__u32
68894+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
68895+{
68896+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
68897+}
68898+
68899+__u32
68900+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
68901+{
68902+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
68903+ GR_UNIXCONNECT_ACL_MSG);
68904+}
68905+
68906+/* hardlinks require at minimum create and link permission,
68907+ any additional privilege required is based on the
68908+ privilege of the file being linked to
68909+*/
68910+__u32
68911+gr_acl_handle_link(const struct dentry * new_dentry,
68912+ const struct dentry * parent_dentry,
68913+ const struct vfsmount * parent_mnt,
68914+ const struct dentry * old_dentry,
68915+ const struct vfsmount * old_mnt, const struct filename *to)
68916+{
68917+ __u32 mode;
68918+ __u32 needmode = GR_CREATE | GR_LINK;
68919+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
68920+
68921+ mode =
68922+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
68923+ old_mnt);
68924+
68925+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
68926+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
68927+ return mode;
68928+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
68929+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
68930+ return 0;
68931+ } else if (unlikely((mode & needmode) != needmode))
68932+ return 0;
68933+
68934+ return 1;
68935+}
68936+
68937+__u32
68938+gr_acl_handle_symlink(const struct dentry * new_dentry,
68939+ const struct dentry * parent_dentry,
68940+ const struct vfsmount * parent_mnt, const struct filename *from)
68941+{
68942+ __u32 needmode = GR_WRITE | GR_CREATE;
68943+ __u32 mode;
68944+
68945+ mode =
68946+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
68947+ GR_CREATE | GR_AUDIT_CREATE |
68948+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
68949+
68950+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
68951+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
68952+ return mode;
68953+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
68954+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
68955+ return 0;
68956+ } else if (unlikely((mode & needmode) != needmode))
68957+ return 0;
68958+
68959+ return (GR_WRITE | GR_CREATE);
68960+}
68961+
68962+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)
68963+{
68964+ __u32 mode;
68965+
68966+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
68967+
68968+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
68969+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
68970+ return mode;
68971+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
68972+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
68973+ return 0;
68974+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
68975+ return 0;
68976+
68977+ return (reqmode);
68978+}
68979+
68980+__u32
68981+gr_acl_handle_mknod(const struct dentry * new_dentry,
68982+ const struct dentry * parent_dentry,
68983+ const struct vfsmount * parent_mnt,
68984+ const int mode)
68985+{
68986+ __u32 reqmode = GR_WRITE | GR_CREATE;
68987+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
68988+ reqmode |= GR_SETID;
68989+
68990+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
68991+ reqmode, GR_MKNOD_ACL_MSG);
68992+}
68993+
68994+__u32
68995+gr_acl_handle_mkdir(const struct dentry *new_dentry,
68996+ const struct dentry *parent_dentry,
68997+ const struct vfsmount *parent_mnt)
68998+{
68999+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
69000+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
69001+}
69002+
69003+#define RENAME_CHECK_SUCCESS(old, new) \
69004+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
69005+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
69006+
69007+int
69008+gr_acl_handle_rename(struct dentry *new_dentry,
69009+ struct dentry *parent_dentry,
69010+ const struct vfsmount *parent_mnt,
69011+ struct dentry *old_dentry,
69012+ struct inode *old_parent_inode,
69013+ struct vfsmount *old_mnt, const struct filename *newname)
69014+{
69015+ __u32 comp1, comp2;
69016+ int error = 0;
69017+
69018+ if (unlikely(!gr_acl_is_enabled()))
69019+ return 0;
69020+
69021+ if (d_is_negative(new_dentry)) {
69022+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
69023+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
69024+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
69025+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
69026+ GR_DELETE | GR_AUDIT_DELETE |
69027+ GR_AUDIT_READ | GR_AUDIT_WRITE |
69028+ GR_SUPPRESS, old_mnt);
69029+ } else {
69030+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
69031+ GR_CREATE | GR_DELETE |
69032+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
69033+ GR_AUDIT_READ | GR_AUDIT_WRITE |
69034+ GR_SUPPRESS, parent_mnt);
69035+ comp2 =
69036+ gr_search_file(old_dentry,
69037+ GR_READ | GR_WRITE | GR_AUDIT_READ |
69038+ GR_DELETE | GR_AUDIT_DELETE |
69039+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
69040+ }
69041+
69042+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
69043+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
69044+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
69045+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
69046+ && !(comp2 & GR_SUPPRESS)) {
69047+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
69048+ error = -EACCES;
69049+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
69050+ error = -EACCES;
69051+
69052+ return error;
69053+}
69054+
69055+void
69056+gr_acl_handle_exit(void)
69057+{
69058+ u16 id;
69059+ char *rolename;
69060+
69061+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
69062+ !(current->role->roletype & GR_ROLE_PERSIST))) {
69063+ id = current->acl_role_id;
69064+ rolename = current->role->rolename;
69065+ gr_set_acls(1);
69066+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
69067+ }
69068+
69069+ gr_put_exec_file(current);
69070+ return;
69071+}
69072+
69073+int
69074+gr_acl_handle_procpidmem(const struct task_struct *task)
69075+{
69076+ if (unlikely(!gr_acl_is_enabled()))
69077+ return 0;
69078+
69079+ if (task != current && task->acl->mode & GR_PROTPROCFD)
69080+ return -EACCES;
69081+
69082+ return 0;
69083+}
69084diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
69085new file mode 100644
69086index 0000000..f056b81
69087--- /dev/null
69088+++ b/grsecurity/gracl_ip.c
69089@@ -0,0 +1,386 @@
69090+#include <linux/kernel.h>
69091+#include <asm/uaccess.h>
69092+#include <asm/errno.h>
69093+#include <net/sock.h>
69094+#include <linux/file.h>
69095+#include <linux/fs.h>
69096+#include <linux/net.h>
69097+#include <linux/in.h>
69098+#include <linux/skbuff.h>
69099+#include <linux/ip.h>
69100+#include <linux/udp.h>
69101+#include <linux/types.h>
69102+#include <linux/sched.h>
69103+#include <linux/netdevice.h>
69104+#include <linux/inetdevice.h>
69105+#include <linux/gracl.h>
69106+#include <linux/grsecurity.h>
69107+#include <linux/grinternal.h>
69108+
69109+#define GR_BIND 0x01
69110+#define GR_CONNECT 0x02
69111+#define GR_INVERT 0x04
69112+#define GR_BINDOVERRIDE 0x08
69113+#define GR_CONNECTOVERRIDE 0x10
69114+#define GR_SOCK_FAMILY 0x20
69115+
69116+static const char * gr_protocols[IPPROTO_MAX] = {
69117+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
69118+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
69119+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
69120+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
69121+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
69122+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
69123+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
69124+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
69125+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
69126+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
69127+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
69128+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
69129+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
69130+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
69131+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
69132+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
69133+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
69134+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
69135+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
69136+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
69137+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
69138+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
69139+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
69140+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
69141+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
69142+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
69143+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
69144+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
69145+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
69146+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
69147+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
69148+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
69149+ };
69150+
69151+static const char * gr_socktypes[SOCK_MAX] = {
69152+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
69153+ "unknown:7", "unknown:8", "unknown:9", "packet"
69154+ };
69155+
69156+static const char * gr_sockfamilies[AF_MAX+1] = {
69157+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
69158+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
69159+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
69160+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
69161+ };
69162+
69163+const char *
69164+gr_proto_to_name(unsigned char proto)
69165+{
69166+ return gr_protocols[proto];
69167+}
69168+
69169+const char *
69170+gr_socktype_to_name(unsigned char type)
69171+{
69172+ return gr_socktypes[type];
69173+}
69174+
69175+const char *
69176+gr_sockfamily_to_name(unsigned char family)
69177+{
69178+ return gr_sockfamilies[family];
69179+}
69180+
69181+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
69182+
69183+int
69184+gr_search_socket(const int domain, const int type, const int protocol)
69185+{
69186+ struct acl_subject_label *curr;
69187+ const struct cred *cred = current_cred();
69188+
69189+ if (unlikely(!gr_acl_is_enabled()))
69190+ goto exit;
69191+
69192+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
69193+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
69194+ goto exit; // let the kernel handle it
69195+
69196+ curr = current->acl;
69197+
69198+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
69199+ /* the family is allowed, if this is PF_INET allow it only if
69200+ the extra sock type/protocol checks pass */
69201+ if (domain == PF_INET)
69202+ goto inet_check;
69203+ goto exit;
69204+ } else {
69205+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
69206+ __u32 fakeip = 0;
69207+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69208+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
69209+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
69210+ gr_to_filename(current->exec_file->f_path.dentry,
69211+ current->exec_file->f_path.mnt) :
69212+ curr->filename, curr->filename,
69213+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
69214+ &current->signal->saved_ip);
69215+ goto exit;
69216+ }
69217+ goto exit_fail;
69218+ }
69219+
69220+inet_check:
69221+ /* the rest of this checking is for IPv4 only */
69222+ if (!curr->ips)
69223+ goto exit;
69224+
69225+ if ((curr->ip_type & (1U << type)) &&
69226+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
69227+ goto exit;
69228+
69229+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
69230+ /* we don't place acls on raw sockets , and sometimes
69231+ dgram/ip sockets are opened for ioctl and not
69232+ bind/connect, so we'll fake a bind learn log */
69233+ if (type == SOCK_RAW || type == SOCK_PACKET) {
69234+ __u32 fakeip = 0;
69235+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69236+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
69237+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
69238+ gr_to_filename(current->exec_file->f_path.dentry,
69239+ current->exec_file->f_path.mnt) :
69240+ curr->filename, curr->filename,
69241+ &fakeip, 0, type,
69242+ protocol, GR_CONNECT, &current->signal->saved_ip);
69243+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
69244+ __u32 fakeip = 0;
69245+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69246+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
69247+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
69248+ gr_to_filename(current->exec_file->f_path.dentry,
69249+ current->exec_file->f_path.mnt) :
69250+ curr->filename, curr->filename,
69251+ &fakeip, 0, type,
69252+ protocol, GR_BIND, &current->signal->saved_ip);
69253+ }
69254+ /* we'll log when they use connect or bind */
69255+ goto exit;
69256+ }
69257+
69258+exit_fail:
69259+ if (domain == PF_INET)
69260+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
69261+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
69262+ else if (rcu_access_pointer(net_families[domain]) != NULL)
69263+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
69264+ gr_socktype_to_name(type), protocol);
69265+
69266+ return 0;
69267+exit:
69268+ return 1;
69269+}
69270+
69271+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)
69272+{
69273+ if ((ip->mode & mode) &&
69274+ (ip_port >= ip->low) &&
69275+ (ip_port <= ip->high) &&
69276+ ((ntohl(ip_addr) & our_netmask) ==
69277+ (ntohl(our_addr) & our_netmask))
69278+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
69279+ && (ip->type & (1U << type))) {
69280+ if (ip->mode & GR_INVERT)
69281+ return 2; // specifically denied
69282+ else
69283+ return 1; // allowed
69284+ }
69285+
69286+ return 0; // not specifically allowed, may continue parsing
69287+}
69288+
69289+static int
69290+gr_search_connectbind(const int full_mode, struct sock *sk,
69291+ struct sockaddr_in *addr, const int type)
69292+{
69293+ char iface[IFNAMSIZ] = {0};
69294+ struct acl_subject_label *curr;
69295+ struct acl_ip_label *ip;
69296+ struct inet_sock *isk;
69297+ struct net_device *dev;
69298+ struct in_device *idev;
69299+ unsigned long i;
69300+ int ret;
69301+ int mode = full_mode & (GR_BIND | GR_CONNECT);
69302+ __u32 ip_addr = 0;
69303+ __u32 our_addr;
69304+ __u32 our_netmask;
69305+ char *p;
69306+ __u16 ip_port = 0;
69307+ const struct cred *cred = current_cred();
69308+
69309+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
69310+ return 0;
69311+
69312+ curr = current->acl;
69313+ isk = inet_sk(sk);
69314+
69315+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
69316+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
69317+ addr->sin_addr.s_addr = curr->inaddr_any_override;
69318+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
69319+ struct sockaddr_in saddr;
69320+ int err;
69321+
69322+ saddr.sin_family = AF_INET;
69323+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
69324+ saddr.sin_port = isk->inet_sport;
69325+
69326+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
69327+ if (err)
69328+ return err;
69329+
69330+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
69331+ if (err)
69332+ return err;
69333+ }
69334+
69335+ if (!curr->ips)
69336+ return 0;
69337+
69338+ ip_addr = addr->sin_addr.s_addr;
69339+ ip_port = ntohs(addr->sin_port);
69340+
69341+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
69342+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69343+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
69344+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
69345+ gr_to_filename(current->exec_file->f_path.dentry,
69346+ current->exec_file->f_path.mnt) :
69347+ curr->filename, curr->filename,
69348+ &ip_addr, ip_port, type,
69349+ sk->sk_protocol, mode, &current->signal->saved_ip);
69350+ return 0;
69351+ }
69352+
69353+ for (i = 0; i < curr->ip_num; i++) {
69354+ ip = *(curr->ips + i);
69355+ if (ip->iface != NULL) {
69356+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
69357+ p = strchr(iface, ':');
69358+ if (p != NULL)
69359+ *p = '\0';
69360+ dev = dev_get_by_name(sock_net(sk), iface);
69361+ if (dev == NULL)
69362+ continue;
69363+ idev = in_dev_get(dev);
69364+ if (idev == NULL) {
69365+ dev_put(dev);
69366+ continue;
69367+ }
69368+ rcu_read_lock();
69369+ for_ifa(idev) {
69370+ if (!strcmp(ip->iface, ifa->ifa_label)) {
69371+ our_addr = ifa->ifa_address;
69372+ our_netmask = 0xffffffff;
69373+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
69374+ if (ret == 1) {
69375+ rcu_read_unlock();
69376+ in_dev_put(idev);
69377+ dev_put(dev);
69378+ return 0;
69379+ } else if (ret == 2) {
69380+ rcu_read_unlock();
69381+ in_dev_put(idev);
69382+ dev_put(dev);
69383+ goto denied;
69384+ }
69385+ }
69386+ } endfor_ifa(idev);
69387+ rcu_read_unlock();
69388+ in_dev_put(idev);
69389+ dev_put(dev);
69390+ } else {
69391+ our_addr = ip->addr;
69392+ our_netmask = ip->netmask;
69393+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
69394+ if (ret == 1)
69395+ return 0;
69396+ else if (ret == 2)
69397+ goto denied;
69398+ }
69399+ }
69400+
69401+denied:
69402+ if (mode == GR_BIND)
69403+ 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));
69404+ else if (mode == GR_CONNECT)
69405+ 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));
69406+
69407+ return -EACCES;
69408+}
69409+
69410+int
69411+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
69412+{
69413+ /* always allow disconnection of dgram sockets with connect */
69414+ if (addr->sin_family == AF_UNSPEC)
69415+ return 0;
69416+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
69417+}
69418+
69419+int
69420+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
69421+{
69422+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
69423+}
69424+
69425+int gr_search_listen(struct socket *sock)
69426+{
69427+ struct sock *sk = sock->sk;
69428+ struct sockaddr_in addr;
69429+
69430+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
69431+ addr.sin_port = inet_sk(sk)->inet_sport;
69432+
69433+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
69434+}
69435+
69436+int gr_search_accept(struct socket *sock)
69437+{
69438+ struct sock *sk = sock->sk;
69439+ struct sockaddr_in addr;
69440+
69441+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
69442+ addr.sin_port = inet_sk(sk)->inet_sport;
69443+
69444+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
69445+}
69446+
69447+int
69448+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
69449+{
69450+ if (addr)
69451+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
69452+ else {
69453+ struct sockaddr_in sin;
69454+ const struct inet_sock *inet = inet_sk(sk);
69455+
69456+ sin.sin_addr.s_addr = inet->inet_daddr;
69457+ sin.sin_port = inet->inet_dport;
69458+
69459+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
69460+ }
69461+}
69462+
69463+int
69464+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
69465+{
69466+ struct sockaddr_in sin;
69467+
69468+ if (unlikely(skb->len < sizeof (struct udphdr)))
69469+ return 0; // skip this packet
69470+
69471+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
69472+ sin.sin_port = udp_hdr(skb)->source;
69473+
69474+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
69475+}
69476diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
69477new file mode 100644
69478index 0000000..25f54ef
69479--- /dev/null
69480+++ b/grsecurity/gracl_learn.c
69481@@ -0,0 +1,207 @@
69482+#include <linux/kernel.h>
69483+#include <linux/mm.h>
69484+#include <linux/sched.h>
69485+#include <linux/poll.h>
69486+#include <linux/string.h>
69487+#include <linux/file.h>
69488+#include <linux/types.h>
69489+#include <linux/vmalloc.h>
69490+#include <linux/grinternal.h>
69491+
69492+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
69493+ size_t count, loff_t *ppos);
69494+extern int gr_acl_is_enabled(void);
69495+
69496+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
69497+static int gr_learn_attached;
69498+
69499+/* use a 512k buffer */
69500+#define LEARN_BUFFER_SIZE (512 * 1024)
69501+
69502+static DEFINE_SPINLOCK(gr_learn_lock);
69503+static DEFINE_MUTEX(gr_learn_user_mutex);
69504+
69505+/* we need to maintain two buffers, so that the kernel context of grlearn
69506+ uses a semaphore around the userspace copying, and the other kernel contexts
69507+ use a spinlock when copying into the buffer, since they cannot sleep
69508+*/
69509+static char *learn_buffer;
69510+static char *learn_buffer_user;
69511+static int learn_buffer_len;
69512+static int learn_buffer_user_len;
69513+
69514+static ssize_t
69515+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
69516+{
69517+ DECLARE_WAITQUEUE(wait, current);
69518+ ssize_t retval = 0;
69519+
69520+ add_wait_queue(&learn_wait, &wait);
69521+ set_current_state(TASK_INTERRUPTIBLE);
69522+ do {
69523+ mutex_lock(&gr_learn_user_mutex);
69524+ spin_lock(&gr_learn_lock);
69525+ if (learn_buffer_len)
69526+ break;
69527+ spin_unlock(&gr_learn_lock);
69528+ mutex_unlock(&gr_learn_user_mutex);
69529+ if (file->f_flags & O_NONBLOCK) {
69530+ retval = -EAGAIN;
69531+ goto out;
69532+ }
69533+ if (signal_pending(current)) {
69534+ retval = -ERESTARTSYS;
69535+ goto out;
69536+ }
69537+
69538+ schedule();
69539+ } while (1);
69540+
69541+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
69542+ learn_buffer_user_len = learn_buffer_len;
69543+ retval = learn_buffer_len;
69544+ learn_buffer_len = 0;
69545+
69546+ spin_unlock(&gr_learn_lock);
69547+
69548+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
69549+ retval = -EFAULT;
69550+
69551+ mutex_unlock(&gr_learn_user_mutex);
69552+out:
69553+ set_current_state(TASK_RUNNING);
69554+ remove_wait_queue(&learn_wait, &wait);
69555+ return retval;
69556+}
69557+
69558+static unsigned int
69559+poll_learn(struct file * file, poll_table * wait)
69560+{
69561+ poll_wait(file, &learn_wait, wait);
69562+
69563+ if (learn_buffer_len)
69564+ return (POLLIN | POLLRDNORM);
69565+
69566+ return 0;
69567+}
69568+
69569+void
69570+gr_clear_learn_entries(void)
69571+{
69572+ char *tmp;
69573+
69574+ mutex_lock(&gr_learn_user_mutex);
69575+ spin_lock(&gr_learn_lock);
69576+ tmp = learn_buffer;
69577+ learn_buffer = NULL;
69578+ spin_unlock(&gr_learn_lock);
69579+ if (tmp)
69580+ vfree(tmp);
69581+ if (learn_buffer_user != NULL) {
69582+ vfree(learn_buffer_user);
69583+ learn_buffer_user = NULL;
69584+ }
69585+ learn_buffer_len = 0;
69586+ mutex_unlock(&gr_learn_user_mutex);
69587+
69588+ return;
69589+}
69590+
69591+void
69592+gr_add_learn_entry(const char *fmt, ...)
69593+{
69594+ va_list args;
69595+ unsigned int len;
69596+
69597+ if (!gr_learn_attached)
69598+ return;
69599+
69600+ spin_lock(&gr_learn_lock);
69601+
69602+ /* leave a gap at the end so we know when it's "full" but don't have to
69603+ compute the exact length of the string we're trying to append
69604+ */
69605+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
69606+ spin_unlock(&gr_learn_lock);
69607+ wake_up_interruptible(&learn_wait);
69608+ return;
69609+ }
69610+ if (learn_buffer == NULL) {
69611+ spin_unlock(&gr_learn_lock);
69612+ return;
69613+ }
69614+
69615+ va_start(args, fmt);
69616+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
69617+ va_end(args);
69618+
69619+ learn_buffer_len += len + 1;
69620+
69621+ spin_unlock(&gr_learn_lock);
69622+ wake_up_interruptible(&learn_wait);
69623+
69624+ return;
69625+}
69626+
69627+static int
69628+open_learn(struct inode *inode, struct file *file)
69629+{
69630+ if (file->f_mode & FMODE_READ && gr_learn_attached)
69631+ return -EBUSY;
69632+ if (file->f_mode & FMODE_READ) {
69633+ int retval = 0;
69634+ mutex_lock(&gr_learn_user_mutex);
69635+ if (learn_buffer == NULL)
69636+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
69637+ if (learn_buffer_user == NULL)
69638+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
69639+ if (learn_buffer == NULL) {
69640+ retval = -ENOMEM;
69641+ goto out_error;
69642+ }
69643+ if (learn_buffer_user == NULL) {
69644+ retval = -ENOMEM;
69645+ goto out_error;
69646+ }
69647+ learn_buffer_len = 0;
69648+ learn_buffer_user_len = 0;
69649+ gr_learn_attached = 1;
69650+out_error:
69651+ mutex_unlock(&gr_learn_user_mutex);
69652+ return retval;
69653+ }
69654+ return 0;
69655+}
69656+
69657+static int
69658+close_learn(struct inode *inode, struct file *file)
69659+{
69660+ if (file->f_mode & FMODE_READ) {
69661+ char *tmp = NULL;
69662+ mutex_lock(&gr_learn_user_mutex);
69663+ spin_lock(&gr_learn_lock);
69664+ tmp = learn_buffer;
69665+ learn_buffer = NULL;
69666+ spin_unlock(&gr_learn_lock);
69667+ if (tmp)
69668+ vfree(tmp);
69669+ if (learn_buffer_user != NULL) {
69670+ vfree(learn_buffer_user);
69671+ learn_buffer_user = NULL;
69672+ }
69673+ learn_buffer_len = 0;
69674+ learn_buffer_user_len = 0;
69675+ gr_learn_attached = 0;
69676+ mutex_unlock(&gr_learn_user_mutex);
69677+ }
69678+
69679+ return 0;
69680+}
69681+
69682+const struct file_operations grsec_fops = {
69683+ .read = read_learn,
69684+ .write = write_grsec_handler,
69685+ .open = open_learn,
69686+ .release = close_learn,
69687+ .poll = poll_learn,
69688+};
69689diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
69690new file mode 100644
69691index 0000000..361a099
69692--- /dev/null
69693+++ b/grsecurity/gracl_policy.c
69694@@ -0,0 +1,1782 @@
69695+#include <linux/kernel.h>
69696+#include <linux/module.h>
69697+#include <linux/sched.h>
69698+#include <linux/mm.h>
69699+#include <linux/file.h>
69700+#include <linux/fs.h>
69701+#include <linux/namei.h>
69702+#include <linux/mount.h>
69703+#include <linux/tty.h>
69704+#include <linux/proc_fs.h>
69705+#include <linux/lglock.h>
69706+#include <linux/slab.h>
69707+#include <linux/vmalloc.h>
69708+#include <linux/types.h>
69709+#include <linux/sysctl.h>
69710+#include <linux/netdevice.h>
69711+#include <linux/ptrace.h>
69712+#include <linux/gracl.h>
69713+#include <linux/gralloc.h>
69714+#include <linux/security.h>
69715+#include <linux/grinternal.h>
69716+#include <linux/pid_namespace.h>
69717+#include <linux/stop_machine.h>
69718+#include <linux/fdtable.h>
69719+#include <linux/percpu.h>
69720+#include <linux/lglock.h>
69721+#include <linux/hugetlb.h>
69722+#include <linux/posix-timers.h>
69723+#include "../fs/mount.h"
69724+
69725+#include <asm/uaccess.h>
69726+#include <asm/errno.h>
69727+#include <asm/mman.h>
69728+
69729+extern struct gr_policy_state *polstate;
69730+
69731+#define FOR_EACH_ROLE_START(role) \
69732+ role = polstate->role_list; \
69733+ while (role) {
69734+
69735+#define FOR_EACH_ROLE_END(role) \
69736+ role = role->prev; \
69737+ }
69738+
69739+struct path gr_real_root;
69740+
69741+extern struct gr_alloc_state *current_alloc_state;
69742+
69743+u16 acl_sp_role_value;
69744+
69745+static DEFINE_MUTEX(gr_dev_mutex);
69746+
69747+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
69748+extern void gr_clear_learn_entries(void);
69749+
69750+static struct gr_arg gr_usermode;
69751+static unsigned char gr_system_salt[GR_SALT_LEN];
69752+static unsigned char gr_system_sum[GR_SHA_LEN];
69753+
69754+static unsigned int gr_auth_attempts = 0;
69755+static unsigned long gr_auth_expires = 0UL;
69756+
69757+struct acl_object_label *fakefs_obj_rw;
69758+struct acl_object_label *fakefs_obj_rwx;
69759+
69760+extern int gr_init_uidset(void);
69761+extern void gr_free_uidset(void);
69762+extern void gr_remove_uid(uid_t uid);
69763+extern int gr_find_uid(uid_t uid);
69764+
69765+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
69766+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
69767+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
69768+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
69769+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);
69770+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
69771+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
69772+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
69773+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
69774+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
69775+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
69776+extern void assign_special_role(const char *rolename);
69777+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
69778+extern int gr_rbac_disable(void *unused);
69779+extern void gr_enable_rbac_system(void);
69780+
69781+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
69782+{
69783+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
69784+ return -EFAULT;
69785+
69786+ return 0;
69787+}
69788+
69789+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
69790+{
69791+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
69792+ return -EFAULT;
69793+
69794+ return 0;
69795+}
69796+
69797+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69798+{
69799+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
69800+ return -EFAULT;
69801+
69802+ return 0;
69803+}
69804+
69805+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
69806+{
69807+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
69808+ return -EFAULT;
69809+
69810+ return 0;
69811+}
69812+
69813+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
69814+{
69815+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
69816+ return -EFAULT;
69817+
69818+ return 0;
69819+}
69820+
69821+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
69822+{
69823+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
69824+ return -EFAULT;
69825+
69826+ return 0;
69827+}
69828+
69829+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
69830+{
69831+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
69832+ return -EFAULT;
69833+
69834+ return 0;
69835+}
69836+
69837+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
69838+{
69839+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
69840+ return -EFAULT;
69841+
69842+ return 0;
69843+}
69844+
69845+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
69846+{
69847+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
69848+ return -EFAULT;
69849+
69850+ return 0;
69851+}
69852+
69853+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
69854+{
69855+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
69856+ return -EFAULT;
69857+
69858+ if (((uwrap->version != GRSECURITY_VERSION) &&
69859+ (uwrap->version != 0x2901)) ||
69860+ (uwrap->size != sizeof(struct gr_arg)))
69861+ return -EINVAL;
69862+
69863+ return 0;
69864+}
69865+
69866+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
69867+{
69868+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
69869+ return -EFAULT;
69870+
69871+ return 0;
69872+}
69873+
69874+static size_t get_gr_arg_wrapper_size_normal(void)
69875+{
69876+ return sizeof(struct gr_arg_wrapper);
69877+}
69878+
69879+#ifdef CONFIG_COMPAT
69880+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
69881+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
69882+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
69883+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
69884+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
69885+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
69886+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
69887+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
69888+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
69889+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
69890+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
69891+extern size_t get_gr_arg_wrapper_size_compat(void);
69892+
69893+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
69894+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
69895+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
69896+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
69897+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
69898+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
69899+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
69900+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
69901+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
69902+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
69903+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
69904+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
69905+
69906+#else
69907+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
69908+#define copy_gr_arg copy_gr_arg_normal
69909+#define copy_gr_hash_struct copy_gr_hash_struct_normal
69910+#define copy_acl_object_label copy_acl_object_label_normal
69911+#define copy_acl_subject_label copy_acl_subject_label_normal
69912+#define copy_acl_role_label copy_acl_role_label_normal
69913+#define copy_acl_ip_label copy_acl_ip_label_normal
69914+#define copy_pointer_from_array copy_pointer_from_array_normal
69915+#define copy_sprole_pw copy_sprole_pw_normal
69916+#define copy_role_transition copy_role_transition_normal
69917+#define copy_role_allowed_ip copy_role_allowed_ip_normal
69918+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
69919+#endif
69920+
69921+static struct acl_subject_label *
69922+lookup_subject_map(const struct acl_subject_label *userp)
69923+{
69924+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
69925+ struct subject_map *match;
69926+
69927+ match = polstate->subj_map_set.s_hash[index];
69928+
69929+ while (match && match->user != userp)
69930+ match = match->next;
69931+
69932+ if (match != NULL)
69933+ return match->kernel;
69934+ else
69935+ return NULL;
69936+}
69937+
69938+static void
69939+insert_subj_map_entry(struct subject_map *subjmap)
69940+{
69941+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
69942+ struct subject_map **curr;
69943+
69944+ subjmap->prev = NULL;
69945+
69946+ curr = &polstate->subj_map_set.s_hash[index];
69947+ if (*curr != NULL)
69948+ (*curr)->prev = subjmap;
69949+
69950+ subjmap->next = *curr;
69951+ *curr = subjmap;
69952+
69953+ return;
69954+}
69955+
69956+static void
69957+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
69958+{
69959+ unsigned int index =
69960+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
69961+ struct acl_role_label **curr;
69962+ struct acl_role_label *tmp, *tmp2;
69963+
69964+ curr = &polstate->acl_role_set.r_hash[index];
69965+
69966+ /* simple case, slot is empty, just set it to our role */
69967+ if (*curr == NULL) {
69968+ *curr = role;
69969+ } else {
69970+ /* example:
69971+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
69972+ 2 -> 3
69973+ */
69974+ /* first check to see if we can already be reached via this slot */
69975+ tmp = *curr;
69976+ while (tmp && tmp != role)
69977+ tmp = tmp->next;
69978+ if (tmp == role) {
69979+ /* we don't need to add ourselves to this slot's chain */
69980+ return;
69981+ }
69982+ /* we need to add ourselves to this chain, two cases */
69983+ if (role->next == NULL) {
69984+ /* simple case, append the current chain to our role */
69985+ role->next = *curr;
69986+ *curr = role;
69987+ } else {
69988+ /* 1 -> 2 -> 3 -> 4
69989+ 2 -> 3 -> 4
69990+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
69991+ */
69992+ /* trickier case: walk our role's chain until we find
69993+ the role for the start of the current slot's chain */
69994+ tmp = role;
69995+ tmp2 = *curr;
69996+ while (tmp->next && tmp->next != tmp2)
69997+ tmp = tmp->next;
69998+ if (tmp->next == tmp2) {
69999+ /* from example above, we found 3, so just
70000+ replace this slot's chain with ours */
70001+ *curr = role;
70002+ } else {
70003+ /* we didn't find a subset of our role's chain
70004+ in the current slot's chain, so append their
70005+ chain to ours, and set us as the first role in
70006+ the slot's chain
70007+
70008+ we could fold this case with the case above,
70009+ but making it explicit for clarity
70010+ */
70011+ tmp->next = tmp2;
70012+ *curr = role;
70013+ }
70014+ }
70015+ }
70016+
70017+ return;
70018+}
70019+
70020+static void
70021+insert_acl_role_label(struct acl_role_label *role)
70022+{
70023+ int i;
70024+
70025+ if (polstate->role_list == NULL) {
70026+ polstate->role_list = role;
70027+ role->prev = NULL;
70028+ } else {
70029+ role->prev = polstate->role_list;
70030+ polstate->role_list = role;
70031+ }
70032+
70033+ /* used for hash chains */
70034+ role->next = NULL;
70035+
70036+ if (role->roletype & GR_ROLE_DOMAIN) {
70037+ for (i = 0; i < role->domain_child_num; i++)
70038+ __insert_acl_role_label(role, role->domain_children[i]);
70039+ } else
70040+ __insert_acl_role_label(role, role->uidgid);
70041+}
70042+
70043+static int
70044+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
70045+{
70046+ struct name_entry **curr, *nentry;
70047+ struct inodev_entry *ientry;
70048+ unsigned int len = strlen(name);
70049+ unsigned int key = full_name_hash(name, len);
70050+ unsigned int index = key % polstate->name_set.n_size;
70051+
70052+ curr = &polstate->name_set.n_hash[index];
70053+
70054+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
70055+ curr = &((*curr)->next);
70056+
70057+ if (*curr != NULL)
70058+ return 1;
70059+
70060+ nentry = acl_alloc(sizeof (struct name_entry));
70061+ if (nentry == NULL)
70062+ return 0;
70063+ ientry = acl_alloc(sizeof (struct inodev_entry));
70064+ if (ientry == NULL)
70065+ return 0;
70066+ ientry->nentry = nentry;
70067+
70068+ nentry->key = key;
70069+ nentry->name = name;
70070+ nentry->inode = inode;
70071+ nentry->device = device;
70072+ nentry->len = len;
70073+ nentry->deleted = deleted;
70074+
70075+ nentry->prev = NULL;
70076+ curr = &polstate->name_set.n_hash[index];
70077+ if (*curr != NULL)
70078+ (*curr)->prev = nentry;
70079+ nentry->next = *curr;
70080+ *curr = nentry;
70081+
70082+ /* insert us into the table searchable by inode/dev */
70083+ __insert_inodev_entry(polstate, ientry);
70084+
70085+ return 1;
70086+}
70087+
70088+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
70089+
70090+static void *
70091+create_table(__u32 * len, int elementsize)
70092+{
70093+ unsigned int table_sizes[] = {
70094+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
70095+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
70096+ 4194301, 8388593, 16777213, 33554393, 67108859
70097+ };
70098+ void *newtable = NULL;
70099+ unsigned int pwr = 0;
70100+
70101+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
70102+ table_sizes[pwr] <= *len)
70103+ pwr++;
70104+
70105+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
70106+ return newtable;
70107+
70108+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
70109+ newtable =
70110+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
70111+ else
70112+ newtable = vmalloc(table_sizes[pwr] * elementsize);
70113+
70114+ *len = table_sizes[pwr];
70115+
70116+ return newtable;
70117+}
70118+
70119+static int
70120+init_variables(const struct gr_arg *arg, bool reload)
70121+{
70122+ struct task_struct *reaper = init_pid_ns.child_reaper;
70123+ unsigned int stacksize;
70124+
70125+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
70126+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
70127+ polstate->name_set.n_size = arg->role_db.num_objects;
70128+ polstate->inodev_set.i_size = arg->role_db.num_objects;
70129+
70130+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
70131+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
70132+ return 1;
70133+
70134+ if (!reload) {
70135+ if (!gr_init_uidset())
70136+ return 1;
70137+ }
70138+
70139+ /* set up the stack that holds allocation info */
70140+
70141+ stacksize = arg->role_db.num_pointers + 5;
70142+
70143+ if (!acl_alloc_stack_init(stacksize))
70144+ return 1;
70145+
70146+ if (!reload) {
70147+ /* grab reference for the real root dentry and vfsmount */
70148+ get_fs_root(reaper->fs, &gr_real_root);
70149+
70150+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70151+ 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);
70152+#endif
70153+
70154+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
70155+ if (fakefs_obj_rw == NULL)
70156+ return 1;
70157+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
70158+
70159+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
70160+ if (fakefs_obj_rwx == NULL)
70161+ return 1;
70162+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
70163+ }
70164+
70165+ polstate->subj_map_set.s_hash =
70166+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
70167+ polstate->acl_role_set.r_hash =
70168+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
70169+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
70170+ polstate->inodev_set.i_hash =
70171+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
70172+
70173+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
70174+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
70175+ return 1;
70176+
70177+ memset(polstate->subj_map_set.s_hash, 0,
70178+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
70179+ memset(polstate->acl_role_set.r_hash, 0,
70180+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
70181+ memset(polstate->name_set.n_hash, 0,
70182+ sizeof (struct name_entry *) * polstate->name_set.n_size);
70183+ memset(polstate->inodev_set.i_hash, 0,
70184+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
70185+
70186+ return 0;
70187+}
70188+
70189+/* free information not needed after startup
70190+ currently contains user->kernel pointer mappings for subjects
70191+*/
70192+
70193+static void
70194+free_init_variables(void)
70195+{
70196+ __u32 i;
70197+
70198+ if (polstate->subj_map_set.s_hash) {
70199+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
70200+ if (polstate->subj_map_set.s_hash[i]) {
70201+ kfree(polstate->subj_map_set.s_hash[i]);
70202+ polstate->subj_map_set.s_hash[i] = NULL;
70203+ }
70204+ }
70205+
70206+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
70207+ PAGE_SIZE)
70208+ kfree(polstate->subj_map_set.s_hash);
70209+ else
70210+ vfree(polstate->subj_map_set.s_hash);
70211+ }
70212+
70213+ return;
70214+}
70215+
70216+static void
70217+free_variables(bool reload)
70218+{
70219+ struct acl_subject_label *s;
70220+ struct acl_role_label *r;
70221+ struct task_struct *task, *task2;
70222+ unsigned int x;
70223+
70224+ if (!reload) {
70225+ gr_clear_learn_entries();
70226+
70227+ read_lock(&tasklist_lock);
70228+ do_each_thread(task2, task) {
70229+ task->acl_sp_role = 0;
70230+ task->acl_role_id = 0;
70231+ task->inherited = 0;
70232+ task->acl = NULL;
70233+ task->role = NULL;
70234+ } while_each_thread(task2, task);
70235+ read_unlock(&tasklist_lock);
70236+
70237+ kfree(fakefs_obj_rw);
70238+ fakefs_obj_rw = NULL;
70239+ kfree(fakefs_obj_rwx);
70240+ fakefs_obj_rwx = NULL;
70241+
70242+ /* release the reference to the real root dentry and vfsmount */
70243+ path_put(&gr_real_root);
70244+ memset(&gr_real_root, 0, sizeof(gr_real_root));
70245+ }
70246+
70247+ /* free all object hash tables */
70248+
70249+ FOR_EACH_ROLE_START(r)
70250+ if (r->subj_hash == NULL)
70251+ goto next_role;
70252+ FOR_EACH_SUBJECT_START(r, s, x)
70253+ if (s->obj_hash == NULL)
70254+ break;
70255+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
70256+ kfree(s->obj_hash);
70257+ else
70258+ vfree(s->obj_hash);
70259+ FOR_EACH_SUBJECT_END(s, x)
70260+ FOR_EACH_NESTED_SUBJECT_START(r, s)
70261+ if (s->obj_hash == NULL)
70262+ break;
70263+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
70264+ kfree(s->obj_hash);
70265+ else
70266+ vfree(s->obj_hash);
70267+ FOR_EACH_NESTED_SUBJECT_END(s)
70268+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
70269+ kfree(r->subj_hash);
70270+ else
70271+ vfree(r->subj_hash);
70272+ r->subj_hash = NULL;
70273+next_role:
70274+ FOR_EACH_ROLE_END(r)
70275+
70276+ acl_free_all();
70277+
70278+ if (polstate->acl_role_set.r_hash) {
70279+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
70280+ PAGE_SIZE)
70281+ kfree(polstate->acl_role_set.r_hash);
70282+ else
70283+ vfree(polstate->acl_role_set.r_hash);
70284+ }
70285+ if (polstate->name_set.n_hash) {
70286+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
70287+ PAGE_SIZE)
70288+ kfree(polstate->name_set.n_hash);
70289+ else
70290+ vfree(polstate->name_set.n_hash);
70291+ }
70292+
70293+ if (polstate->inodev_set.i_hash) {
70294+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
70295+ PAGE_SIZE)
70296+ kfree(polstate->inodev_set.i_hash);
70297+ else
70298+ vfree(polstate->inodev_set.i_hash);
70299+ }
70300+
70301+ if (!reload)
70302+ gr_free_uidset();
70303+
70304+ memset(&polstate->name_set, 0, sizeof (struct name_db));
70305+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
70306+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
70307+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
70308+
70309+ polstate->default_role = NULL;
70310+ polstate->kernel_role = NULL;
70311+ polstate->role_list = NULL;
70312+
70313+ return;
70314+}
70315+
70316+static struct acl_subject_label *
70317+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
70318+
70319+static int alloc_and_copy_string(char **name, unsigned int maxlen)
70320+{
70321+ unsigned int len = strnlen_user(*name, maxlen);
70322+ char *tmp;
70323+
70324+ if (!len || len >= maxlen)
70325+ return -EINVAL;
70326+
70327+ if ((tmp = (char *) acl_alloc(len)) == NULL)
70328+ return -ENOMEM;
70329+
70330+ if (copy_from_user(tmp, *name, len))
70331+ return -EFAULT;
70332+
70333+ tmp[len-1] = '\0';
70334+ *name = tmp;
70335+
70336+ return 0;
70337+}
70338+
70339+static int
70340+copy_user_glob(struct acl_object_label *obj)
70341+{
70342+ struct acl_object_label *g_tmp, **guser;
70343+ int error;
70344+
70345+ if (obj->globbed == NULL)
70346+ return 0;
70347+
70348+ guser = &obj->globbed;
70349+ while (*guser) {
70350+ g_tmp = (struct acl_object_label *)
70351+ acl_alloc(sizeof (struct acl_object_label));
70352+ if (g_tmp == NULL)
70353+ return -ENOMEM;
70354+
70355+ if (copy_acl_object_label(g_tmp, *guser))
70356+ return -EFAULT;
70357+
70358+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
70359+ if (error)
70360+ return error;
70361+
70362+ *guser = g_tmp;
70363+ guser = &(g_tmp->next);
70364+ }
70365+
70366+ return 0;
70367+}
70368+
70369+static int
70370+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
70371+ struct acl_role_label *role)
70372+{
70373+ struct acl_object_label *o_tmp;
70374+ int ret;
70375+
70376+ while (userp) {
70377+ if ((o_tmp = (struct acl_object_label *)
70378+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
70379+ return -ENOMEM;
70380+
70381+ if (copy_acl_object_label(o_tmp, userp))
70382+ return -EFAULT;
70383+
70384+ userp = o_tmp->prev;
70385+
70386+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
70387+ if (ret)
70388+ return ret;
70389+
70390+ insert_acl_obj_label(o_tmp, subj);
70391+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
70392+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
70393+ return -ENOMEM;
70394+
70395+ ret = copy_user_glob(o_tmp);
70396+ if (ret)
70397+ return ret;
70398+
70399+ if (o_tmp->nested) {
70400+ int already_copied;
70401+
70402+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
70403+ if (IS_ERR(o_tmp->nested))
70404+ return PTR_ERR(o_tmp->nested);
70405+
70406+ /* insert into nested subject list if we haven't copied this one yet
70407+ to prevent duplicate entries */
70408+ if (!already_copied) {
70409+ o_tmp->nested->next = role->hash->first;
70410+ role->hash->first = o_tmp->nested;
70411+ }
70412+ }
70413+ }
70414+
70415+ return 0;
70416+}
70417+
70418+static __u32
70419+count_user_subjs(struct acl_subject_label *userp)
70420+{
70421+ struct acl_subject_label s_tmp;
70422+ __u32 num = 0;
70423+
70424+ while (userp) {
70425+ if (copy_acl_subject_label(&s_tmp, userp))
70426+ break;
70427+
70428+ userp = s_tmp.prev;
70429+ }
70430+
70431+ return num;
70432+}
70433+
70434+static int
70435+copy_user_allowedips(struct acl_role_label *rolep)
70436+{
70437+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
70438+
70439+ ruserip = rolep->allowed_ips;
70440+
70441+ while (ruserip) {
70442+ rlast = rtmp;
70443+
70444+ if ((rtmp = (struct role_allowed_ip *)
70445+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
70446+ return -ENOMEM;
70447+
70448+ if (copy_role_allowed_ip(rtmp, ruserip))
70449+ return -EFAULT;
70450+
70451+ ruserip = rtmp->prev;
70452+
70453+ if (!rlast) {
70454+ rtmp->prev = NULL;
70455+ rolep->allowed_ips = rtmp;
70456+ } else {
70457+ rlast->next = rtmp;
70458+ rtmp->prev = rlast;
70459+ }
70460+
70461+ if (!ruserip)
70462+ rtmp->next = NULL;
70463+ }
70464+
70465+ return 0;
70466+}
70467+
70468+static int
70469+copy_user_transitions(struct acl_role_label *rolep)
70470+{
70471+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
70472+ int error;
70473+
70474+ rusertp = rolep->transitions;
70475+
70476+ while (rusertp) {
70477+ rlast = rtmp;
70478+
70479+ if ((rtmp = (struct role_transition *)
70480+ acl_alloc(sizeof (struct role_transition))) == NULL)
70481+ return -ENOMEM;
70482+
70483+ if (copy_role_transition(rtmp, rusertp))
70484+ return -EFAULT;
70485+
70486+ rusertp = rtmp->prev;
70487+
70488+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
70489+ if (error)
70490+ return error;
70491+
70492+ if (!rlast) {
70493+ rtmp->prev = NULL;
70494+ rolep->transitions = rtmp;
70495+ } else {
70496+ rlast->next = rtmp;
70497+ rtmp->prev = rlast;
70498+ }
70499+
70500+ if (!rusertp)
70501+ rtmp->next = NULL;
70502+ }
70503+
70504+ return 0;
70505+}
70506+
70507+static __u32 count_user_objs(const struct acl_object_label __user *userp)
70508+{
70509+ struct acl_object_label o_tmp;
70510+ __u32 num = 0;
70511+
70512+ while (userp) {
70513+ if (copy_acl_object_label(&o_tmp, userp))
70514+ break;
70515+
70516+ userp = o_tmp.prev;
70517+ num++;
70518+ }
70519+
70520+ return num;
70521+}
70522+
70523+static struct acl_subject_label *
70524+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
70525+{
70526+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
70527+ __u32 num_objs;
70528+ struct acl_ip_label **i_tmp, *i_utmp2;
70529+ struct gr_hash_struct ghash;
70530+ struct subject_map *subjmap;
70531+ unsigned int i_num;
70532+ int err;
70533+
70534+ if (already_copied != NULL)
70535+ *already_copied = 0;
70536+
70537+ s_tmp = lookup_subject_map(userp);
70538+
70539+ /* we've already copied this subject into the kernel, just return
70540+ the reference to it, and don't copy it over again
70541+ */
70542+ if (s_tmp) {
70543+ if (already_copied != NULL)
70544+ *already_copied = 1;
70545+ return(s_tmp);
70546+ }
70547+
70548+ if ((s_tmp = (struct acl_subject_label *)
70549+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
70550+ return ERR_PTR(-ENOMEM);
70551+
70552+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
70553+ if (subjmap == NULL)
70554+ return ERR_PTR(-ENOMEM);
70555+
70556+ subjmap->user = userp;
70557+ subjmap->kernel = s_tmp;
70558+ insert_subj_map_entry(subjmap);
70559+
70560+ if (copy_acl_subject_label(s_tmp, userp))
70561+ return ERR_PTR(-EFAULT);
70562+
70563+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
70564+ if (err)
70565+ return ERR_PTR(err);
70566+
70567+ if (!strcmp(s_tmp->filename, "/"))
70568+ role->root_label = s_tmp;
70569+
70570+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
70571+ return ERR_PTR(-EFAULT);
70572+
70573+ /* copy user and group transition tables */
70574+
70575+ if (s_tmp->user_trans_num) {
70576+ uid_t *uidlist;
70577+
70578+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
70579+ if (uidlist == NULL)
70580+ return ERR_PTR(-ENOMEM);
70581+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
70582+ return ERR_PTR(-EFAULT);
70583+
70584+ s_tmp->user_transitions = uidlist;
70585+ }
70586+
70587+ if (s_tmp->group_trans_num) {
70588+ gid_t *gidlist;
70589+
70590+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
70591+ if (gidlist == NULL)
70592+ return ERR_PTR(-ENOMEM);
70593+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
70594+ return ERR_PTR(-EFAULT);
70595+
70596+ s_tmp->group_transitions = gidlist;
70597+ }
70598+
70599+ /* set up object hash table */
70600+ num_objs = count_user_objs(ghash.first);
70601+
70602+ s_tmp->obj_hash_size = num_objs;
70603+ s_tmp->obj_hash =
70604+ (struct acl_object_label **)
70605+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
70606+
70607+ if (!s_tmp->obj_hash)
70608+ return ERR_PTR(-ENOMEM);
70609+
70610+ memset(s_tmp->obj_hash, 0,
70611+ s_tmp->obj_hash_size *
70612+ sizeof (struct acl_object_label *));
70613+
70614+ /* add in objects */
70615+ err = copy_user_objs(ghash.first, s_tmp, role);
70616+
70617+ if (err)
70618+ return ERR_PTR(err);
70619+
70620+ /* set pointer for parent subject */
70621+ if (s_tmp->parent_subject) {
70622+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
70623+
70624+ if (IS_ERR(s_tmp2))
70625+ return s_tmp2;
70626+
70627+ s_tmp->parent_subject = s_tmp2;
70628+ }
70629+
70630+ /* add in ip acls */
70631+
70632+ if (!s_tmp->ip_num) {
70633+ s_tmp->ips = NULL;
70634+ goto insert;
70635+ }
70636+
70637+ i_tmp =
70638+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
70639+ sizeof (struct acl_ip_label *));
70640+
70641+ if (!i_tmp)
70642+ return ERR_PTR(-ENOMEM);
70643+
70644+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
70645+ *(i_tmp + i_num) =
70646+ (struct acl_ip_label *)
70647+ acl_alloc(sizeof (struct acl_ip_label));
70648+ if (!*(i_tmp + i_num))
70649+ return ERR_PTR(-ENOMEM);
70650+
70651+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
70652+ return ERR_PTR(-EFAULT);
70653+
70654+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
70655+ return ERR_PTR(-EFAULT);
70656+
70657+ if ((*(i_tmp + i_num))->iface == NULL)
70658+ continue;
70659+
70660+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
70661+ if (err)
70662+ return ERR_PTR(err);
70663+ }
70664+
70665+ s_tmp->ips = i_tmp;
70666+
70667+insert:
70668+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
70669+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
70670+ return ERR_PTR(-ENOMEM);
70671+
70672+ return s_tmp;
70673+}
70674+
70675+static int
70676+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
70677+{
70678+ struct acl_subject_label s_pre;
70679+ struct acl_subject_label * ret;
70680+ int err;
70681+
70682+ while (userp) {
70683+ if (copy_acl_subject_label(&s_pre, userp))
70684+ return -EFAULT;
70685+
70686+ ret = do_copy_user_subj(userp, role, NULL);
70687+
70688+ err = PTR_ERR(ret);
70689+ if (IS_ERR(ret))
70690+ return err;
70691+
70692+ insert_acl_subj_label(ret, role);
70693+
70694+ userp = s_pre.prev;
70695+ }
70696+
70697+ return 0;
70698+}
70699+
70700+static int
70701+copy_user_acl(struct gr_arg *arg)
70702+{
70703+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
70704+ struct acl_subject_label *subj_list;
70705+ struct sprole_pw *sptmp;
70706+ struct gr_hash_struct *ghash;
70707+ uid_t *domainlist;
70708+ unsigned int r_num;
70709+ int err = 0;
70710+ __u16 i;
70711+ __u32 num_subjs;
70712+
70713+ /* we need a default and kernel role */
70714+ if (arg->role_db.num_roles < 2)
70715+ return -EINVAL;
70716+
70717+ /* copy special role authentication info from userspace */
70718+
70719+ polstate->num_sprole_pws = arg->num_sprole_pws;
70720+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
70721+
70722+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
70723+ return -ENOMEM;
70724+
70725+ for (i = 0; i < polstate->num_sprole_pws; i++) {
70726+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
70727+ if (!sptmp)
70728+ return -ENOMEM;
70729+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
70730+ return -EFAULT;
70731+
70732+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
70733+ if (err)
70734+ return err;
70735+
70736+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70737+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
70738+#endif
70739+
70740+ polstate->acl_special_roles[i] = sptmp;
70741+ }
70742+
70743+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
70744+
70745+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
70746+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
70747+
70748+ if (!r_tmp)
70749+ return -ENOMEM;
70750+
70751+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
70752+ return -EFAULT;
70753+
70754+ if (copy_acl_role_label(r_tmp, r_utmp2))
70755+ return -EFAULT;
70756+
70757+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
70758+ if (err)
70759+ return err;
70760+
70761+ if (!strcmp(r_tmp->rolename, "default")
70762+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
70763+ polstate->default_role = r_tmp;
70764+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
70765+ polstate->kernel_role = r_tmp;
70766+ }
70767+
70768+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
70769+ return -ENOMEM;
70770+
70771+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
70772+ return -EFAULT;
70773+
70774+ r_tmp->hash = ghash;
70775+
70776+ num_subjs = count_user_subjs(r_tmp->hash->first);
70777+
70778+ r_tmp->subj_hash_size = num_subjs;
70779+ r_tmp->subj_hash =
70780+ (struct acl_subject_label **)
70781+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
70782+
70783+ if (!r_tmp->subj_hash)
70784+ return -ENOMEM;
70785+
70786+ err = copy_user_allowedips(r_tmp);
70787+ if (err)
70788+ return err;
70789+
70790+ /* copy domain info */
70791+ if (r_tmp->domain_children != NULL) {
70792+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
70793+ if (domainlist == NULL)
70794+ return -ENOMEM;
70795+
70796+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
70797+ return -EFAULT;
70798+
70799+ r_tmp->domain_children = domainlist;
70800+ }
70801+
70802+ err = copy_user_transitions(r_tmp);
70803+ if (err)
70804+ return err;
70805+
70806+ memset(r_tmp->subj_hash, 0,
70807+ r_tmp->subj_hash_size *
70808+ sizeof (struct acl_subject_label *));
70809+
70810+ /* acquire the list of subjects, then NULL out
70811+ the list prior to parsing the subjects for this role,
70812+ as during this parsing the list is replaced with a list
70813+ of *nested* subjects for the role
70814+ */
70815+ subj_list = r_tmp->hash->first;
70816+
70817+ /* set nested subject list to null */
70818+ r_tmp->hash->first = NULL;
70819+
70820+ err = copy_user_subjs(subj_list, r_tmp);
70821+
70822+ if (err)
70823+ return err;
70824+
70825+ insert_acl_role_label(r_tmp);
70826+ }
70827+
70828+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
70829+ return -EINVAL;
70830+
70831+ return err;
70832+}
70833+
70834+static int gracl_reload_apply_policies(void *reload)
70835+{
70836+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
70837+ struct task_struct *task, *task2;
70838+ struct acl_role_label *role, *rtmp;
70839+ struct acl_subject_label *subj;
70840+ const struct cred *cred;
70841+ int role_applied;
70842+ int ret = 0;
70843+
70844+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
70845+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
70846+
70847+ /* first make sure we'll be able to apply the new policy cleanly */
70848+ do_each_thread(task2, task) {
70849+ if (task->exec_file == NULL)
70850+ continue;
70851+ role_applied = 0;
70852+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
70853+ /* preserve special roles */
70854+ FOR_EACH_ROLE_START(role)
70855+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
70856+ rtmp = task->role;
70857+ task->role = role;
70858+ role_applied = 1;
70859+ break;
70860+ }
70861+ FOR_EACH_ROLE_END(role)
70862+ }
70863+ if (!role_applied) {
70864+ cred = __task_cred(task);
70865+ rtmp = task->role;
70866+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
70867+ }
70868+ /* this handles non-nested inherited subjects, nested subjects will still
70869+ be dropped currently */
70870+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
70871+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
70872+ /* change the role back so that we've made no modifications to the policy */
70873+ task->role = rtmp;
70874+
70875+ if (subj == NULL || task->tmpacl == NULL) {
70876+ ret = -EINVAL;
70877+ goto out;
70878+ }
70879+ } while_each_thread(task2, task);
70880+
70881+ /* now actually apply the policy */
70882+
70883+ do_each_thread(task2, task) {
70884+ if (task->exec_file) {
70885+ role_applied = 0;
70886+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
70887+ /* preserve special roles */
70888+ FOR_EACH_ROLE_START(role)
70889+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
70890+ task->role = role;
70891+ role_applied = 1;
70892+ break;
70893+ }
70894+ FOR_EACH_ROLE_END(role)
70895+ }
70896+ if (!role_applied) {
70897+ cred = __task_cred(task);
70898+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
70899+ }
70900+ /* this handles non-nested inherited subjects, nested subjects will still
70901+ be dropped currently */
70902+ if (!reload_state->oldmode && task->inherited)
70903+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
70904+ else {
70905+ /* looked up and tagged to the task previously */
70906+ subj = task->tmpacl;
70907+ }
70908+ /* subj will be non-null */
70909+ __gr_apply_subject_to_task(polstate, task, subj);
70910+ if (reload_state->oldmode) {
70911+ task->acl_role_id = 0;
70912+ task->acl_sp_role = 0;
70913+ task->inherited = 0;
70914+ }
70915+ } else {
70916+ // it's a kernel process
70917+ task->role = polstate->kernel_role;
70918+ task->acl = polstate->kernel_role->root_label;
70919+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
70920+ task->acl->mode &= ~GR_PROCFIND;
70921+#endif
70922+ }
70923+ } while_each_thread(task2, task);
70924+
70925+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
70926+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
70927+
70928+out:
70929+
70930+ return ret;
70931+}
70932+
70933+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
70934+{
70935+ struct gr_reload_state new_reload_state = { };
70936+ int err;
70937+
70938+ new_reload_state.oldpolicy_ptr = polstate;
70939+ new_reload_state.oldalloc_ptr = current_alloc_state;
70940+ new_reload_state.oldmode = oldmode;
70941+
70942+ current_alloc_state = &new_reload_state.newalloc;
70943+ polstate = &new_reload_state.newpolicy;
70944+
70945+ /* everything relevant is now saved off, copy in the new policy */
70946+ if (init_variables(args, true)) {
70947+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
70948+ err = -ENOMEM;
70949+ goto error;
70950+ }
70951+
70952+ err = copy_user_acl(args);
70953+ free_init_variables();
70954+ if (err)
70955+ goto error;
70956+ /* the new policy is copied in, with the old policy available via saved_state
70957+ first go through applying roles, making sure to preserve special roles
70958+ then apply new subjects, making sure to preserve inherited and nested subjects,
70959+ though currently only inherited subjects will be preserved
70960+ */
70961+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
70962+ if (err)
70963+ goto error;
70964+
70965+ /* we've now applied the new policy, so restore the old policy state to free it */
70966+ polstate = &new_reload_state.oldpolicy;
70967+ current_alloc_state = &new_reload_state.oldalloc;
70968+ free_variables(true);
70969+
70970+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
70971+ to running_polstate/current_alloc_state inside stop_machine
70972+ */
70973+ err = 0;
70974+ goto out;
70975+error:
70976+ /* on error of loading the new policy, we'll just keep the previous
70977+ policy set around
70978+ */
70979+ free_variables(true);
70980+
70981+ /* doesn't affect runtime, but maintains consistent state */
70982+out:
70983+ polstate = new_reload_state.oldpolicy_ptr;
70984+ current_alloc_state = new_reload_state.oldalloc_ptr;
70985+
70986+ return err;
70987+}
70988+
70989+static int
70990+gracl_init(struct gr_arg *args)
70991+{
70992+ int error = 0;
70993+
70994+ memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
70995+ memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
70996+
70997+ if (init_variables(args, false)) {
70998+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
70999+ error = -ENOMEM;
71000+ goto out;
71001+ }
71002+
71003+ error = copy_user_acl(args);
71004+ free_init_variables();
71005+ if (error)
71006+ goto out;
71007+
71008+ error = gr_set_acls(0);
71009+ if (error)
71010+ goto out;
71011+
71012+ gr_enable_rbac_system();
71013+
71014+ return 0;
71015+
71016+out:
71017+ free_variables(false);
71018+ return error;
71019+}
71020+
71021+static int
71022+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
71023+ unsigned char **sum)
71024+{
71025+ struct acl_role_label *r;
71026+ struct role_allowed_ip *ipp;
71027+ struct role_transition *trans;
71028+ unsigned int i;
71029+ int found = 0;
71030+ u32 curr_ip = current->signal->curr_ip;
71031+
71032+ current->signal->saved_ip = curr_ip;
71033+
71034+ /* check transition table */
71035+
71036+ for (trans = current->role->transitions; trans; trans = trans->next) {
71037+ if (!strcmp(rolename, trans->rolename)) {
71038+ found = 1;
71039+ break;
71040+ }
71041+ }
71042+
71043+ if (!found)
71044+ return 0;
71045+
71046+ /* handle special roles that do not require authentication
71047+ and check ip */
71048+
71049+ FOR_EACH_ROLE_START(r)
71050+ if (!strcmp(rolename, r->rolename) &&
71051+ (r->roletype & GR_ROLE_SPECIAL)) {
71052+ found = 0;
71053+ if (r->allowed_ips != NULL) {
71054+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
71055+ if ((ntohl(curr_ip) & ipp->netmask) ==
71056+ (ntohl(ipp->addr) & ipp->netmask))
71057+ found = 1;
71058+ }
71059+ } else
71060+ found = 2;
71061+ if (!found)
71062+ return 0;
71063+
71064+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
71065+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
71066+ *salt = NULL;
71067+ *sum = NULL;
71068+ return 1;
71069+ }
71070+ }
71071+ FOR_EACH_ROLE_END(r)
71072+
71073+ for (i = 0; i < polstate->num_sprole_pws; i++) {
71074+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
71075+ *salt = polstate->acl_special_roles[i]->salt;
71076+ *sum = polstate->acl_special_roles[i]->sum;
71077+ return 1;
71078+ }
71079+ }
71080+
71081+ return 0;
71082+}
71083+
71084+int gr_check_secure_terminal(struct task_struct *task)
71085+{
71086+ struct task_struct *p, *p2, *p3;
71087+ struct files_struct *files;
71088+ struct fdtable *fdt;
71089+ struct file *our_file = NULL, *file;
71090+ int i;
71091+
71092+ if (task->signal->tty == NULL)
71093+ return 1;
71094+
71095+ files = get_files_struct(task);
71096+ if (files != NULL) {
71097+ rcu_read_lock();
71098+ fdt = files_fdtable(files);
71099+ for (i=0; i < fdt->max_fds; i++) {
71100+ file = fcheck_files(files, i);
71101+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
71102+ get_file(file);
71103+ our_file = file;
71104+ }
71105+ }
71106+ rcu_read_unlock();
71107+ put_files_struct(files);
71108+ }
71109+
71110+ if (our_file == NULL)
71111+ return 1;
71112+
71113+ read_lock(&tasklist_lock);
71114+ do_each_thread(p2, p) {
71115+ files = get_files_struct(p);
71116+ if (files == NULL ||
71117+ (p->signal && p->signal->tty == task->signal->tty)) {
71118+ if (files != NULL)
71119+ put_files_struct(files);
71120+ continue;
71121+ }
71122+ rcu_read_lock();
71123+ fdt = files_fdtable(files);
71124+ for (i=0; i < fdt->max_fds; i++) {
71125+ file = fcheck_files(files, i);
71126+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
71127+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
71128+ p3 = task;
71129+ while (task_pid_nr(p3) > 0) {
71130+ if (p3 == p)
71131+ break;
71132+ p3 = p3->real_parent;
71133+ }
71134+ if (p3 == p)
71135+ break;
71136+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
71137+ gr_handle_alertkill(p);
71138+ rcu_read_unlock();
71139+ put_files_struct(files);
71140+ read_unlock(&tasklist_lock);
71141+ fput(our_file);
71142+ return 0;
71143+ }
71144+ }
71145+ rcu_read_unlock();
71146+ put_files_struct(files);
71147+ } while_each_thread(p2, p);
71148+ read_unlock(&tasklist_lock);
71149+
71150+ fput(our_file);
71151+ return 1;
71152+}
71153+
71154+ssize_t
71155+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
71156+{
71157+ struct gr_arg_wrapper uwrap;
71158+ unsigned char *sprole_salt = NULL;
71159+ unsigned char *sprole_sum = NULL;
71160+ int error = 0;
71161+ int error2 = 0;
71162+ size_t req_count = 0;
71163+ unsigned char oldmode = 0;
71164+
71165+ mutex_lock(&gr_dev_mutex);
71166+
71167+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
71168+ error = -EPERM;
71169+ goto out;
71170+ }
71171+
71172+#ifdef CONFIG_COMPAT
71173+ pax_open_kernel();
71174+ if (is_compat_task()) {
71175+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
71176+ copy_gr_arg = &copy_gr_arg_compat;
71177+ copy_acl_object_label = &copy_acl_object_label_compat;
71178+ copy_acl_subject_label = &copy_acl_subject_label_compat;
71179+ copy_acl_role_label = &copy_acl_role_label_compat;
71180+ copy_acl_ip_label = &copy_acl_ip_label_compat;
71181+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
71182+ copy_role_transition = &copy_role_transition_compat;
71183+ copy_sprole_pw = &copy_sprole_pw_compat;
71184+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
71185+ copy_pointer_from_array = &copy_pointer_from_array_compat;
71186+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
71187+ } else {
71188+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
71189+ copy_gr_arg = &copy_gr_arg_normal;
71190+ copy_acl_object_label = &copy_acl_object_label_normal;
71191+ copy_acl_subject_label = &copy_acl_subject_label_normal;
71192+ copy_acl_role_label = &copy_acl_role_label_normal;
71193+ copy_acl_ip_label = &copy_acl_ip_label_normal;
71194+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
71195+ copy_role_transition = &copy_role_transition_normal;
71196+ copy_sprole_pw = &copy_sprole_pw_normal;
71197+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
71198+ copy_pointer_from_array = &copy_pointer_from_array_normal;
71199+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
71200+ }
71201+ pax_close_kernel();
71202+#endif
71203+
71204+ req_count = get_gr_arg_wrapper_size();
71205+
71206+ if (count != req_count) {
71207+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
71208+ error = -EINVAL;
71209+ goto out;
71210+ }
71211+
71212+
71213+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
71214+ gr_auth_expires = 0;
71215+ gr_auth_attempts = 0;
71216+ }
71217+
71218+ error = copy_gr_arg_wrapper(buf, &uwrap);
71219+ if (error)
71220+ goto out;
71221+
71222+ error = copy_gr_arg(uwrap.arg, &gr_usermode);
71223+ if (error)
71224+ goto out;
71225+
71226+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
71227+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
71228+ time_after(gr_auth_expires, get_seconds())) {
71229+ error = -EBUSY;
71230+ goto out;
71231+ }
71232+
71233+ /* if non-root trying to do anything other than use a special role,
71234+ do not attempt authentication, do not count towards authentication
71235+ locking
71236+ */
71237+
71238+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
71239+ gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
71240+ gr_is_global_nonroot(current_uid())) {
71241+ error = -EPERM;
71242+ goto out;
71243+ }
71244+
71245+ /* ensure pw and special role name are null terminated */
71246+
71247+ gr_usermode.pw[GR_PW_LEN - 1] = '\0';
71248+ gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
71249+
71250+ /* Okay.
71251+ * We have our enough of the argument structure..(we have yet
71252+ * to copy_from_user the tables themselves) . Copy the tables
71253+ * only if we need them, i.e. for loading operations. */
71254+
71255+ switch (gr_usermode.mode) {
71256+ case GR_STATUS:
71257+ if (gr_acl_is_enabled()) {
71258+ error = 1;
71259+ if (!gr_check_secure_terminal(current))
71260+ error = 3;
71261+ } else
71262+ error = 2;
71263+ goto out;
71264+ case GR_SHUTDOWN:
71265+ if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
71266+ stop_machine(gr_rbac_disable, NULL, NULL);
71267+ free_variables(false);
71268+ memset(&gr_usermode, 0, sizeof(gr_usermode));
71269+ memset(&gr_system_salt, 0, sizeof(gr_system_salt));
71270+ memset(&gr_system_sum, 0, sizeof(gr_system_sum));
71271+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
71272+ } else if (gr_acl_is_enabled()) {
71273+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
71274+ error = -EPERM;
71275+ } else {
71276+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
71277+ error = -EAGAIN;
71278+ }
71279+ break;
71280+ case GR_ENABLE:
71281+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
71282+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
71283+ else {
71284+ if (gr_acl_is_enabled())
71285+ error = -EAGAIN;
71286+ else
71287+ error = error2;
71288+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
71289+ }
71290+ break;
71291+ case GR_OLDRELOAD:
71292+ oldmode = 1;
71293+ case GR_RELOAD:
71294+ if (!gr_acl_is_enabled()) {
71295+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
71296+ error = -EAGAIN;
71297+ } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
71298+ error2 = gracl_reload(&gr_usermode, oldmode);
71299+ if (!error2)
71300+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
71301+ else {
71302+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
71303+ error = error2;
71304+ }
71305+ } else {
71306+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
71307+ error = -EPERM;
71308+ }
71309+ break;
71310+ case GR_SEGVMOD:
71311+ if (unlikely(!gr_acl_is_enabled())) {
71312+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
71313+ error = -EAGAIN;
71314+ break;
71315+ }
71316+
71317+ if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
71318+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
71319+ if (gr_usermode.segv_device && gr_usermode.segv_inode) {
71320+ struct acl_subject_label *segvacl;
71321+ segvacl =
71322+ lookup_acl_subj_label(gr_usermode.segv_inode,
71323+ gr_usermode.segv_device,
71324+ current->role);
71325+ if (segvacl) {
71326+ segvacl->crashes = 0;
71327+ segvacl->expires = 0;
71328+ }
71329+ } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
71330+ gr_remove_uid(gr_usermode.segv_uid);
71331+ }
71332+ } else {
71333+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
71334+ error = -EPERM;
71335+ }
71336+ break;
71337+ case GR_SPROLE:
71338+ case GR_SPROLEPAM:
71339+ if (unlikely(!gr_acl_is_enabled())) {
71340+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
71341+ error = -EAGAIN;
71342+ break;
71343+ }
71344+
71345+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
71346+ current->role->expires = 0;
71347+ current->role->auth_attempts = 0;
71348+ }
71349+
71350+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
71351+ time_after(current->role->expires, get_seconds())) {
71352+ error = -EBUSY;
71353+ goto out;
71354+ }
71355+
71356+ if (lookup_special_role_auth
71357+ (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
71358+ && ((!sprole_salt && !sprole_sum)
71359+ || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
71360+ char *p = "";
71361+ assign_special_role(gr_usermode.sp_role);
71362+ read_lock(&tasklist_lock);
71363+ if (current->real_parent)
71364+ p = current->real_parent->role->rolename;
71365+ read_unlock(&tasklist_lock);
71366+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
71367+ p, acl_sp_role_value);
71368+ } else {
71369+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
71370+ error = -EPERM;
71371+ if(!(current->role->auth_attempts++))
71372+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
71373+
71374+ goto out;
71375+ }
71376+ break;
71377+ case GR_UNSPROLE:
71378+ if (unlikely(!gr_acl_is_enabled())) {
71379+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
71380+ error = -EAGAIN;
71381+ break;
71382+ }
71383+
71384+ if (current->role->roletype & GR_ROLE_SPECIAL) {
71385+ char *p = "";
71386+ int i = 0;
71387+
71388+ read_lock(&tasklist_lock);
71389+ if (current->real_parent) {
71390+ p = current->real_parent->role->rolename;
71391+ i = current->real_parent->acl_role_id;
71392+ }
71393+ read_unlock(&tasklist_lock);
71394+
71395+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
71396+ gr_set_acls(1);
71397+ } else {
71398+ error = -EPERM;
71399+ goto out;
71400+ }
71401+ break;
71402+ default:
71403+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
71404+ error = -EINVAL;
71405+ break;
71406+ }
71407+
71408+ if (error != -EPERM)
71409+ goto out;
71410+
71411+ if(!(gr_auth_attempts++))
71412+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
71413+
71414+ out:
71415+ mutex_unlock(&gr_dev_mutex);
71416+
71417+ if (!error)
71418+ error = req_count;
71419+
71420+ return error;
71421+}
71422+
71423+int
71424+gr_set_acls(const int type)
71425+{
71426+ struct task_struct *task, *task2;
71427+ struct acl_role_label *role = current->role;
71428+ struct acl_subject_label *subj;
71429+ __u16 acl_role_id = current->acl_role_id;
71430+ const struct cred *cred;
71431+ int ret;
71432+
71433+ rcu_read_lock();
71434+ read_lock(&tasklist_lock);
71435+ read_lock(&grsec_exec_file_lock);
71436+ do_each_thread(task2, task) {
71437+ /* check to see if we're called from the exit handler,
71438+ if so, only replace ACLs that have inherited the admin
71439+ ACL */
71440+
71441+ if (type && (task->role != role ||
71442+ task->acl_role_id != acl_role_id))
71443+ continue;
71444+
71445+ task->acl_role_id = 0;
71446+ task->acl_sp_role = 0;
71447+ task->inherited = 0;
71448+
71449+ if (task->exec_file) {
71450+ cred = __task_cred(task);
71451+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71452+ subj = __gr_get_subject_for_task(polstate, task, NULL);
71453+ if (subj == NULL) {
71454+ ret = -EINVAL;
71455+ read_unlock(&grsec_exec_file_lock);
71456+ read_unlock(&tasklist_lock);
71457+ rcu_read_unlock();
71458+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
71459+ return ret;
71460+ }
71461+ __gr_apply_subject_to_task(polstate, task, subj);
71462+ } else {
71463+ // it's a kernel process
71464+ task->role = polstate->kernel_role;
71465+ task->acl = polstate->kernel_role->root_label;
71466+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
71467+ task->acl->mode &= ~GR_PROCFIND;
71468+#endif
71469+ }
71470+ } while_each_thread(task2, task);
71471+ read_unlock(&grsec_exec_file_lock);
71472+ read_unlock(&tasklist_lock);
71473+ rcu_read_unlock();
71474+
71475+ return 0;
71476+}
71477diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
71478new file mode 100644
71479index 0000000..39645c9
71480--- /dev/null
71481+++ b/grsecurity/gracl_res.c
71482@@ -0,0 +1,68 @@
71483+#include <linux/kernel.h>
71484+#include <linux/sched.h>
71485+#include <linux/gracl.h>
71486+#include <linux/grinternal.h>
71487+
71488+static const char *restab_log[] = {
71489+ [RLIMIT_CPU] = "RLIMIT_CPU",
71490+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
71491+ [RLIMIT_DATA] = "RLIMIT_DATA",
71492+ [RLIMIT_STACK] = "RLIMIT_STACK",
71493+ [RLIMIT_CORE] = "RLIMIT_CORE",
71494+ [RLIMIT_RSS] = "RLIMIT_RSS",
71495+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
71496+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
71497+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
71498+ [RLIMIT_AS] = "RLIMIT_AS",
71499+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
71500+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
71501+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
71502+ [RLIMIT_NICE] = "RLIMIT_NICE",
71503+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
71504+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
71505+ [GR_CRASH_RES] = "RLIMIT_CRASH"
71506+};
71507+
71508+void
71509+gr_log_resource(const struct task_struct *task,
71510+ const int res, const unsigned long wanted, const int gt)
71511+{
71512+ const struct cred *cred;
71513+ unsigned long rlim;
71514+
71515+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
71516+ return;
71517+
71518+ // not yet supported resource
71519+ if (unlikely(!restab_log[res]))
71520+ return;
71521+
71522+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
71523+ rlim = task_rlimit_max(task, res);
71524+ else
71525+ rlim = task_rlimit(task, res);
71526+
71527+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
71528+ return;
71529+
71530+ rcu_read_lock();
71531+ cred = __task_cred(task);
71532+
71533+ if (res == RLIMIT_NPROC &&
71534+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
71535+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
71536+ goto out_rcu_unlock;
71537+ else if (res == RLIMIT_MEMLOCK &&
71538+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
71539+ goto out_rcu_unlock;
71540+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
71541+ goto out_rcu_unlock;
71542+ rcu_read_unlock();
71543+
71544+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
71545+
71546+ return;
71547+out_rcu_unlock:
71548+ rcu_read_unlock();
71549+ return;
71550+}
71551diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
71552new file mode 100644
71553index 0000000..2040e61
71554--- /dev/null
71555+++ b/grsecurity/gracl_segv.c
71556@@ -0,0 +1,313 @@
71557+#include <linux/kernel.h>
71558+#include <linux/mm.h>
71559+#include <asm/uaccess.h>
71560+#include <asm/errno.h>
71561+#include <asm/mman.h>
71562+#include <net/sock.h>
71563+#include <linux/file.h>
71564+#include <linux/fs.h>
71565+#include <linux/net.h>
71566+#include <linux/in.h>
71567+#include <linux/slab.h>
71568+#include <linux/types.h>
71569+#include <linux/sched.h>
71570+#include <linux/timer.h>
71571+#include <linux/gracl.h>
71572+#include <linux/grsecurity.h>
71573+#include <linux/grinternal.h>
71574+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
71575+#include <linux/magic.h>
71576+#include <linux/pagemap.h>
71577+#include "../fs/btrfs/async-thread.h"
71578+#include "../fs/btrfs/ctree.h"
71579+#include "../fs/btrfs/btrfs_inode.h"
71580+#endif
71581+
71582+static struct crash_uid *uid_set;
71583+static unsigned short uid_used;
71584+static DEFINE_SPINLOCK(gr_uid_lock);
71585+extern rwlock_t gr_inode_lock;
71586+extern struct acl_subject_label *
71587+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
71588+ struct acl_role_label *role);
71589+
71590+static inline dev_t __get_dev(const struct dentry *dentry)
71591+{
71592+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
71593+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
71594+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
71595+ else
71596+#endif
71597+ return dentry->d_sb->s_dev;
71598+}
71599+
71600+int
71601+gr_init_uidset(void)
71602+{
71603+ uid_set =
71604+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
71605+ uid_used = 0;
71606+
71607+ return uid_set ? 1 : 0;
71608+}
71609+
71610+void
71611+gr_free_uidset(void)
71612+{
71613+ if (uid_set) {
71614+ struct crash_uid *tmpset;
71615+ spin_lock(&gr_uid_lock);
71616+ tmpset = uid_set;
71617+ uid_set = NULL;
71618+ uid_used = 0;
71619+ spin_unlock(&gr_uid_lock);
71620+ if (tmpset)
71621+ kfree(tmpset);
71622+ }
71623+
71624+ return;
71625+}
71626+
71627+int
71628+gr_find_uid(const uid_t uid)
71629+{
71630+ struct crash_uid *tmp = uid_set;
71631+ uid_t buid;
71632+ int low = 0, high = uid_used - 1, mid;
71633+
71634+ while (high >= low) {
71635+ mid = (low + high) >> 1;
71636+ buid = tmp[mid].uid;
71637+ if (buid == uid)
71638+ return mid;
71639+ if (buid > uid)
71640+ high = mid - 1;
71641+ if (buid < uid)
71642+ low = mid + 1;
71643+ }
71644+
71645+ return -1;
71646+}
71647+
71648+static __inline__ void
71649+gr_insertsort(void)
71650+{
71651+ unsigned short i, j;
71652+ struct crash_uid index;
71653+
71654+ for (i = 1; i < uid_used; i++) {
71655+ index = uid_set[i];
71656+ j = i;
71657+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
71658+ uid_set[j] = uid_set[j - 1];
71659+ j--;
71660+ }
71661+ uid_set[j] = index;
71662+ }
71663+
71664+ return;
71665+}
71666+
71667+static __inline__ void
71668+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
71669+{
71670+ int loc;
71671+ uid_t uid = GR_GLOBAL_UID(kuid);
71672+
71673+ if (uid_used == GR_UIDTABLE_MAX)
71674+ return;
71675+
71676+ loc = gr_find_uid(uid);
71677+
71678+ if (loc >= 0) {
71679+ uid_set[loc].expires = expires;
71680+ return;
71681+ }
71682+
71683+ uid_set[uid_used].uid = uid;
71684+ uid_set[uid_used].expires = expires;
71685+ uid_used++;
71686+
71687+ gr_insertsort();
71688+
71689+ return;
71690+}
71691+
71692+void
71693+gr_remove_uid(const unsigned short loc)
71694+{
71695+ unsigned short i;
71696+
71697+ for (i = loc + 1; i < uid_used; i++)
71698+ uid_set[i - 1] = uid_set[i];
71699+
71700+ uid_used--;
71701+
71702+ return;
71703+}
71704+
71705+int
71706+gr_check_crash_uid(const kuid_t kuid)
71707+{
71708+ int loc;
71709+ int ret = 0;
71710+ uid_t uid;
71711+
71712+ if (unlikely(!gr_acl_is_enabled()))
71713+ return 0;
71714+
71715+ uid = GR_GLOBAL_UID(kuid);
71716+
71717+ spin_lock(&gr_uid_lock);
71718+ loc = gr_find_uid(uid);
71719+
71720+ if (loc < 0)
71721+ goto out_unlock;
71722+
71723+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
71724+ gr_remove_uid(loc);
71725+ else
71726+ ret = 1;
71727+
71728+out_unlock:
71729+ spin_unlock(&gr_uid_lock);
71730+ return ret;
71731+}
71732+
71733+static __inline__ int
71734+proc_is_setxid(const struct cred *cred)
71735+{
71736+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
71737+ !uid_eq(cred->uid, cred->fsuid))
71738+ return 1;
71739+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
71740+ !gid_eq(cred->gid, cred->fsgid))
71741+ return 1;
71742+
71743+ return 0;
71744+}
71745+
71746+extern int gr_fake_force_sig(int sig, struct task_struct *t);
71747+
71748+void
71749+gr_handle_crash(struct task_struct *task, const int sig)
71750+{
71751+ struct acl_subject_label *curr;
71752+ struct task_struct *tsk, *tsk2;
71753+ const struct cred *cred;
71754+ const struct cred *cred2;
71755+
71756+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
71757+ return;
71758+
71759+ if (unlikely(!gr_acl_is_enabled()))
71760+ return;
71761+
71762+ curr = task->acl;
71763+
71764+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
71765+ return;
71766+
71767+ if (time_before_eq(curr->expires, get_seconds())) {
71768+ curr->expires = 0;
71769+ curr->crashes = 0;
71770+ }
71771+
71772+ curr->crashes++;
71773+
71774+ if (!curr->expires)
71775+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
71776+
71777+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
71778+ time_after(curr->expires, get_seconds())) {
71779+ rcu_read_lock();
71780+ cred = __task_cred(task);
71781+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
71782+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
71783+ spin_lock(&gr_uid_lock);
71784+ gr_insert_uid(cred->uid, curr->expires);
71785+ spin_unlock(&gr_uid_lock);
71786+ curr->expires = 0;
71787+ curr->crashes = 0;
71788+ read_lock(&tasklist_lock);
71789+ do_each_thread(tsk2, tsk) {
71790+ cred2 = __task_cred(tsk);
71791+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
71792+ gr_fake_force_sig(SIGKILL, tsk);
71793+ } while_each_thread(tsk2, tsk);
71794+ read_unlock(&tasklist_lock);
71795+ } else {
71796+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
71797+ read_lock(&tasklist_lock);
71798+ read_lock(&grsec_exec_file_lock);
71799+ do_each_thread(tsk2, tsk) {
71800+ if (likely(tsk != task)) {
71801+ // if this thread has the same subject as the one that triggered
71802+ // RES_CRASH and it's the same binary, kill it
71803+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
71804+ gr_fake_force_sig(SIGKILL, tsk);
71805+ }
71806+ } while_each_thread(tsk2, tsk);
71807+ read_unlock(&grsec_exec_file_lock);
71808+ read_unlock(&tasklist_lock);
71809+ }
71810+ rcu_read_unlock();
71811+ }
71812+
71813+ return;
71814+}
71815+
71816+int
71817+gr_check_crash_exec(const struct file *filp)
71818+{
71819+ struct acl_subject_label *curr;
71820+
71821+ if (unlikely(!gr_acl_is_enabled()))
71822+ return 0;
71823+
71824+ read_lock(&gr_inode_lock);
71825+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
71826+ __get_dev(filp->f_path.dentry),
71827+ current->role);
71828+ read_unlock(&gr_inode_lock);
71829+
71830+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
71831+ (!curr->crashes && !curr->expires))
71832+ return 0;
71833+
71834+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
71835+ time_after(curr->expires, get_seconds()))
71836+ return 1;
71837+ else if (time_before_eq(curr->expires, get_seconds())) {
71838+ curr->crashes = 0;
71839+ curr->expires = 0;
71840+ }
71841+
71842+ return 0;
71843+}
71844+
71845+void
71846+gr_handle_alertkill(struct task_struct *task)
71847+{
71848+ struct acl_subject_label *curracl;
71849+ __u32 curr_ip;
71850+ struct task_struct *p, *p2;
71851+
71852+ if (unlikely(!gr_acl_is_enabled()))
71853+ return;
71854+
71855+ curracl = task->acl;
71856+ curr_ip = task->signal->curr_ip;
71857+
71858+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
71859+ read_lock(&tasklist_lock);
71860+ do_each_thread(p2, p) {
71861+ if (p->signal->curr_ip == curr_ip)
71862+ gr_fake_force_sig(SIGKILL, p);
71863+ } while_each_thread(p2, p);
71864+ read_unlock(&tasklist_lock);
71865+ } else if (curracl->mode & GR_KILLPROC)
71866+ gr_fake_force_sig(SIGKILL, task);
71867+
71868+ return;
71869+}
71870diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
71871new file mode 100644
71872index 0000000..98011b0
71873--- /dev/null
71874+++ b/grsecurity/gracl_shm.c
71875@@ -0,0 +1,40 @@
71876+#include <linux/kernel.h>
71877+#include <linux/mm.h>
71878+#include <linux/sched.h>
71879+#include <linux/file.h>
71880+#include <linux/ipc.h>
71881+#include <linux/gracl.h>
71882+#include <linux/grsecurity.h>
71883+#include <linux/grinternal.h>
71884+
71885+int
71886+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
71887+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
71888+{
71889+ struct task_struct *task;
71890+
71891+ if (!gr_acl_is_enabled())
71892+ return 1;
71893+
71894+ rcu_read_lock();
71895+ read_lock(&tasklist_lock);
71896+
71897+ task = find_task_by_vpid(shm_cprid);
71898+
71899+ if (unlikely(!task))
71900+ task = find_task_by_vpid(shm_lapid);
71901+
71902+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
71903+ (task_pid_nr(task) == shm_lapid)) &&
71904+ (task->acl->mode & GR_PROTSHM) &&
71905+ (task->acl != current->acl))) {
71906+ read_unlock(&tasklist_lock);
71907+ rcu_read_unlock();
71908+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
71909+ return 0;
71910+ }
71911+ read_unlock(&tasklist_lock);
71912+ rcu_read_unlock();
71913+
71914+ return 1;
71915+}
71916diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
71917new file mode 100644
71918index 0000000..bc0be01
71919--- /dev/null
71920+++ b/grsecurity/grsec_chdir.c
71921@@ -0,0 +1,19 @@
71922+#include <linux/kernel.h>
71923+#include <linux/sched.h>
71924+#include <linux/fs.h>
71925+#include <linux/file.h>
71926+#include <linux/grsecurity.h>
71927+#include <linux/grinternal.h>
71928+
71929+void
71930+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
71931+{
71932+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
71933+ if ((grsec_enable_chdir && grsec_enable_group &&
71934+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
71935+ !grsec_enable_group)) {
71936+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
71937+ }
71938+#endif
71939+ return;
71940+}
71941diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
71942new file mode 100644
71943index 0000000..e10b319
71944--- /dev/null
71945+++ b/grsecurity/grsec_chroot.c
71946@@ -0,0 +1,370 @@
71947+#include <linux/kernel.h>
71948+#include <linux/module.h>
71949+#include <linux/sched.h>
71950+#include <linux/file.h>
71951+#include <linux/fs.h>
71952+#include <linux/mount.h>
71953+#include <linux/types.h>
71954+#include "../fs/mount.h"
71955+#include <linux/grsecurity.h>
71956+#include <linux/grinternal.h>
71957+
71958+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
71959+int gr_init_ran;
71960+#endif
71961+
71962+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
71963+{
71964+#ifdef CONFIG_GRKERNSEC
71965+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
71966+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
71967+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
71968+ && gr_init_ran
71969+#endif
71970+ )
71971+ task->gr_is_chrooted = 1;
71972+ else {
71973+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
71974+ if (task_pid_nr(task) == 1 && !gr_init_ran)
71975+ gr_init_ran = 1;
71976+#endif
71977+ task->gr_is_chrooted = 0;
71978+ }
71979+
71980+ task->gr_chroot_dentry = path->dentry;
71981+#endif
71982+ return;
71983+}
71984+
71985+void gr_clear_chroot_entries(struct task_struct *task)
71986+{
71987+#ifdef CONFIG_GRKERNSEC
71988+ task->gr_is_chrooted = 0;
71989+ task->gr_chroot_dentry = NULL;
71990+#endif
71991+ return;
71992+}
71993+
71994+int
71995+gr_handle_chroot_unix(const pid_t pid)
71996+{
71997+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
71998+ struct task_struct *p;
71999+
72000+ if (unlikely(!grsec_enable_chroot_unix))
72001+ return 1;
72002+
72003+ if (likely(!proc_is_chrooted(current)))
72004+ return 1;
72005+
72006+ rcu_read_lock();
72007+ read_lock(&tasklist_lock);
72008+ p = find_task_by_vpid_unrestricted(pid);
72009+ if (unlikely(p && !have_same_root(current, p))) {
72010+ read_unlock(&tasklist_lock);
72011+ rcu_read_unlock();
72012+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
72013+ return 0;
72014+ }
72015+ read_unlock(&tasklist_lock);
72016+ rcu_read_unlock();
72017+#endif
72018+ return 1;
72019+}
72020+
72021+int
72022+gr_handle_chroot_nice(void)
72023+{
72024+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
72025+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
72026+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
72027+ return -EPERM;
72028+ }
72029+#endif
72030+ return 0;
72031+}
72032+
72033+int
72034+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
72035+{
72036+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
72037+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
72038+ && proc_is_chrooted(current)) {
72039+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
72040+ return -EACCES;
72041+ }
72042+#endif
72043+ return 0;
72044+}
72045+
72046+int
72047+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
72048+{
72049+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72050+ struct task_struct *p;
72051+ int ret = 0;
72052+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
72053+ return ret;
72054+
72055+ read_lock(&tasklist_lock);
72056+ do_each_pid_task(pid, type, p) {
72057+ if (!have_same_root(current, p)) {
72058+ ret = 1;
72059+ goto out;
72060+ }
72061+ } while_each_pid_task(pid, type, p);
72062+out:
72063+ read_unlock(&tasklist_lock);
72064+ return ret;
72065+#endif
72066+ return 0;
72067+}
72068+
72069+int
72070+gr_pid_is_chrooted(struct task_struct *p)
72071+{
72072+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72073+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
72074+ return 0;
72075+
72076+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
72077+ !have_same_root(current, p)) {
72078+ return 1;
72079+ }
72080+#endif
72081+ return 0;
72082+}
72083+
72084+EXPORT_SYMBOL(gr_pid_is_chrooted);
72085+
72086+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
72087+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
72088+{
72089+ struct path path, currentroot;
72090+ int ret = 0;
72091+
72092+ path.dentry = (struct dentry *)u_dentry;
72093+ path.mnt = (struct vfsmount *)u_mnt;
72094+ get_fs_root(current->fs, &currentroot);
72095+ if (path_is_under(&path, &currentroot))
72096+ ret = 1;
72097+ path_put(&currentroot);
72098+
72099+ return ret;
72100+}
72101+#endif
72102+
72103+int
72104+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
72105+{
72106+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
72107+ if (!grsec_enable_chroot_fchdir)
72108+ return 1;
72109+
72110+ if (!proc_is_chrooted(current))
72111+ return 1;
72112+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
72113+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
72114+ return 0;
72115+ }
72116+#endif
72117+ return 1;
72118+}
72119+
72120+int
72121+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72122+ const time_t shm_createtime)
72123+{
72124+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
72125+ struct task_struct *p;
72126+ time_t starttime;
72127+
72128+ if (unlikely(!grsec_enable_chroot_shmat))
72129+ return 1;
72130+
72131+ if (likely(!proc_is_chrooted(current)))
72132+ return 1;
72133+
72134+ rcu_read_lock();
72135+ read_lock(&tasklist_lock);
72136+
72137+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
72138+ starttime = p->start_time.tv_sec;
72139+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
72140+ if (have_same_root(current, p)) {
72141+ goto allow;
72142+ } else {
72143+ read_unlock(&tasklist_lock);
72144+ rcu_read_unlock();
72145+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
72146+ return 0;
72147+ }
72148+ }
72149+ /* creator exited, pid reuse, fall through to next check */
72150+ }
72151+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
72152+ if (unlikely(!have_same_root(current, p))) {
72153+ read_unlock(&tasklist_lock);
72154+ rcu_read_unlock();
72155+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
72156+ return 0;
72157+ }
72158+ }
72159+
72160+allow:
72161+ read_unlock(&tasklist_lock);
72162+ rcu_read_unlock();
72163+#endif
72164+ return 1;
72165+}
72166+
72167+void
72168+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
72169+{
72170+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
72171+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
72172+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
72173+#endif
72174+ return;
72175+}
72176+
72177+int
72178+gr_handle_chroot_mknod(const struct dentry *dentry,
72179+ const struct vfsmount *mnt, const int mode)
72180+{
72181+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
72182+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
72183+ proc_is_chrooted(current)) {
72184+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
72185+ return -EPERM;
72186+ }
72187+#endif
72188+ return 0;
72189+}
72190+
72191+int
72192+gr_handle_chroot_mount(const struct dentry *dentry,
72193+ const struct vfsmount *mnt, const char *dev_name)
72194+{
72195+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
72196+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
72197+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
72198+ return -EPERM;
72199+ }
72200+#endif
72201+ return 0;
72202+}
72203+
72204+int
72205+gr_handle_chroot_pivot(void)
72206+{
72207+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
72208+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
72209+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
72210+ return -EPERM;
72211+ }
72212+#endif
72213+ return 0;
72214+}
72215+
72216+int
72217+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
72218+{
72219+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
72220+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
72221+ !gr_is_outside_chroot(dentry, mnt)) {
72222+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
72223+ return -EPERM;
72224+ }
72225+#endif
72226+ return 0;
72227+}
72228+
72229+extern const char *captab_log[];
72230+extern int captab_log_entries;
72231+
72232+int
72233+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72234+{
72235+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72236+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
72237+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
72238+ if (cap_raised(chroot_caps, cap)) {
72239+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
72240+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
72241+ }
72242+ return 0;
72243+ }
72244+ }
72245+#endif
72246+ return 1;
72247+}
72248+
72249+int
72250+gr_chroot_is_capable(const int cap)
72251+{
72252+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72253+ return gr_task_chroot_is_capable(current, current_cred(), cap);
72254+#endif
72255+ return 1;
72256+}
72257+
72258+int
72259+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
72260+{
72261+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72262+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
72263+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
72264+ if (cap_raised(chroot_caps, cap)) {
72265+ return 0;
72266+ }
72267+ }
72268+#endif
72269+ return 1;
72270+}
72271+
72272+int
72273+gr_chroot_is_capable_nolog(const int cap)
72274+{
72275+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72276+ return gr_task_chroot_is_capable_nolog(current, cap);
72277+#endif
72278+ return 1;
72279+}
72280+
72281+int
72282+gr_handle_chroot_sysctl(const int op)
72283+{
72284+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
72285+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
72286+ proc_is_chrooted(current))
72287+ return -EACCES;
72288+#endif
72289+ return 0;
72290+}
72291+
72292+void
72293+gr_handle_chroot_chdir(const struct path *path)
72294+{
72295+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
72296+ if (grsec_enable_chroot_chdir)
72297+ set_fs_pwd(current->fs, path);
72298+#endif
72299+ return;
72300+}
72301+
72302+int
72303+gr_handle_chroot_chmod(const struct dentry *dentry,
72304+ const struct vfsmount *mnt, const int mode)
72305+{
72306+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
72307+ /* allow chmod +s on directories, but not files */
72308+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
72309+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
72310+ proc_is_chrooted(current)) {
72311+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
72312+ return -EPERM;
72313+ }
72314+#endif
72315+ return 0;
72316+}
72317diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
72318new file mode 100644
72319index 0000000..52b3e30
72320--- /dev/null
72321+++ b/grsecurity/grsec_disabled.c
72322@@ -0,0 +1,433 @@
72323+#include <linux/kernel.h>
72324+#include <linux/module.h>
72325+#include <linux/sched.h>
72326+#include <linux/file.h>
72327+#include <linux/fs.h>
72328+#include <linux/kdev_t.h>
72329+#include <linux/net.h>
72330+#include <linux/in.h>
72331+#include <linux/ip.h>
72332+#include <linux/skbuff.h>
72333+#include <linux/sysctl.h>
72334+
72335+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
72336+void
72337+pax_set_initial_flags(struct linux_binprm *bprm)
72338+{
72339+ return;
72340+}
72341+#endif
72342+
72343+#ifdef CONFIG_SYSCTL
72344+__u32
72345+gr_handle_sysctl(const struct ctl_table * table, const int op)
72346+{
72347+ return 0;
72348+}
72349+#endif
72350+
72351+#ifdef CONFIG_TASKSTATS
72352+int gr_is_taskstats_denied(int pid)
72353+{
72354+ return 0;
72355+}
72356+#endif
72357+
72358+int
72359+gr_acl_is_enabled(void)
72360+{
72361+ return 0;
72362+}
72363+
72364+void
72365+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
72366+{
72367+ return;
72368+}
72369+
72370+int
72371+gr_handle_rawio(const struct inode *inode)
72372+{
72373+ return 0;
72374+}
72375+
72376+void
72377+gr_acl_handle_psacct(struct task_struct *task, const long code)
72378+{
72379+ return;
72380+}
72381+
72382+int
72383+gr_handle_ptrace(struct task_struct *task, const long request)
72384+{
72385+ return 0;
72386+}
72387+
72388+int
72389+gr_handle_proc_ptrace(struct task_struct *task)
72390+{
72391+ return 0;
72392+}
72393+
72394+int
72395+gr_set_acls(const int type)
72396+{
72397+ return 0;
72398+}
72399+
72400+int
72401+gr_check_hidden_task(const struct task_struct *tsk)
72402+{
72403+ return 0;
72404+}
72405+
72406+int
72407+gr_check_protected_task(const struct task_struct *task)
72408+{
72409+ return 0;
72410+}
72411+
72412+int
72413+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
72414+{
72415+ return 0;
72416+}
72417+
72418+void
72419+gr_copy_label(struct task_struct *tsk)
72420+{
72421+ return;
72422+}
72423+
72424+void
72425+gr_set_pax_flags(struct task_struct *task)
72426+{
72427+ return;
72428+}
72429+
72430+int
72431+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
72432+ const int unsafe_share)
72433+{
72434+ return 0;
72435+}
72436+
72437+void
72438+gr_handle_delete(const ino_t ino, const dev_t dev)
72439+{
72440+ return;
72441+}
72442+
72443+void
72444+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
72445+{
72446+ return;
72447+}
72448+
72449+void
72450+gr_handle_crash(struct task_struct *task, const int sig)
72451+{
72452+ return;
72453+}
72454+
72455+int
72456+gr_check_crash_exec(const struct file *filp)
72457+{
72458+ return 0;
72459+}
72460+
72461+int
72462+gr_check_crash_uid(const kuid_t uid)
72463+{
72464+ return 0;
72465+}
72466+
72467+void
72468+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
72469+ struct dentry *old_dentry,
72470+ struct dentry *new_dentry,
72471+ struct vfsmount *mnt, const __u8 replace)
72472+{
72473+ return;
72474+}
72475+
72476+int
72477+gr_search_socket(const int family, const int type, const int protocol)
72478+{
72479+ return 1;
72480+}
72481+
72482+int
72483+gr_search_connectbind(const int mode, const struct socket *sock,
72484+ const struct sockaddr_in *addr)
72485+{
72486+ return 0;
72487+}
72488+
72489+void
72490+gr_handle_alertkill(struct task_struct *task)
72491+{
72492+ return;
72493+}
72494+
72495+__u32
72496+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
72497+{
72498+ return 1;
72499+}
72500+
72501+__u32
72502+gr_acl_handle_hidden_file(const struct dentry * dentry,
72503+ const struct vfsmount * mnt)
72504+{
72505+ return 1;
72506+}
72507+
72508+__u32
72509+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
72510+ int acc_mode)
72511+{
72512+ return 1;
72513+}
72514+
72515+__u32
72516+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
72517+{
72518+ return 1;
72519+}
72520+
72521+__u32
72522+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
72523+{
72524+ return 1;
72525+}
72526+
72527+int
72528+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
72529+ unsigned int *vm_flags)
72530+{
72531+ return 1;
72532+}
72533+
72534+__u32
72535+gr_acl_handle_truncate(const struct dentry * dentry,
72536+ const struct vfsmount * mnt)
72537+{
72538+ return 1;
72539+}
72540+
72541+__u32
72542+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
72543+{
72544+ return 1;
72545+}
72546+
72547+__u32
72548+gr_acl_handle_access(const struct dentry * dentry,
72549+ const struct vfsmount * mnt, const int fmode)
72550+{
72551+ return 1;
72552+}
72553+
72554+__u32
72555+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
72556+ umode_t *mode)
72557+{
72558+ return 1;
72559+}
72560+
72561+__u32
72562+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
72563+{
72564+ return 1;
72565+}
72566+
72567+__u32
72568+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
72569+{
72570+ return 1;
72571+}
72572+
72573+__u32
72574+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
72575+{
72576+ return 1;
72577+}
72578+
72579+void
72580+grsecurity_init(void)
72581+{
72582+ return;
72583+}
72584+
72585+umode_t gr_acl_umask(void)
72586+{
72587+ return 0;
72588+}
72589+
72590+__u32
72591+gr_acl_handle_mknod(const struct dentry * new_dentry,
72592+ const struct dentry * parent_dentry,
72593+ const struct vfsmount * parent_mnt,
72594+ const int mode)
72595+{
72596+ return 1;
72597+}
72598+
72599+__u32
72600+gr_acl_handle_mkdir(const struct dentry * new_dentry,
72601+ const struct dentry * parent_dentry,
72602+ const struct vfsmount * parent_mnt)
72603+{
72604+ return 1;
72605+}
72606+
72607+__u32
72608+gr_acl_handle_symlink(const struct dentry * new_dentry,
72609+ const struct dentry * parent_dentry,
72610+ const struct vfsmount * parent_mnt, const struct filename *from)
72611+{
72612+ return 1;
72613+}
72614+
72615+__u32
72616+gr_acl_handle_link(const struct dentry * new_dentry,
72617+ const struct dentry * parent_dentry,
72618+ const struct vfsmount * parent_mnt,
72619+ const struct dentry * old_dentry,
72620+ const struct vfsmount * old_mnt, const struct filename *to)
72621+{
72622+ return 1;
72623+}
72624+
72625+int
72626+gr_acl_handle_rename(const struct dentry *new_dentry,
72627+ const struct dentry *parent_dentry,
72628+ const struct vfsmount *parent_mnt,
72629+ const struct dentry *old_dentry,
72630+ const struct inode *old_parent_inode,
72631+ const struct vfsmount *old_mnt, const struct filename *newname)
72632+{
72633+ return 0;
72634+}
72635+
72636+int
72637+gr_acl_handle_filldir(const struct file *file, const char *name,
72638+ const int namelen, const ino_t ino)
72639+{
72640+ return 1;
72641+}
72642+
72643+int
72644+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72645+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
72646+{
72647+ return 1;
72648+}
72649+
72650+int
72651+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
72652+{
72653+ return 0;
72654+}
72655+
72656+int
72657+gr_search_accept(const struct socket *sock)
72658+{
72659+ return 0;
72660+}
72661+
72662+int
72663+gr_search_listen(const struct socket *sock)
72664+{
72665+ return 0;
72666+}
72667+
72668+int
72669+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
72670+{
72671+ return 0;
72672+}
72673+
72674+__u32
72675+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
72676+{
72677+ return 1;
72678+}
72679+
72680+__u32
72681+gr_acl_handle_creat(const struct dentry * dentry,
72682+ const struct dentry * p_dentry,
72683+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
72684+ const int imode)
72685+{
72686+ return 1;
72687+}
72688+
72689+void
72690+gr_acl_handle_exit(void)
72691+{
72692+ return;
72693+}
72694+
72695+int
72696+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
72697+{
72698+ return 1;
72699+}
72700+
72701+void
72702+gr_set_role_label(const kuid_t uid, const kgid_t gid)
72703+{
72704+ return;
72705+}
72706+
72707+int
72708+gr_acl_handle_procpidmem(const struct task_struct *task)
72709+{
72710+ return 0;
72711+}
72712+
72713+int
72714+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
72715+{
72716+ return 0;
72717+}
72718+
72719+int
72720+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
72721+{
72722+ return 0;
72723+}
72724+
72725+int
72726+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
72727+{
72728+ return 0;
72729+}
72730+
72731+int
72732+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
72733+{
72734+ return 0;
72735+}
72736+
72737+int gr_acl_enable_at_secure(void)
72738+{
72739+ return 0;
72740+}
72741+
72742+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
72743+{
72744+ return dentry->d_sb->s_dev;
72745+}
72746+
72747+void gr_put_exec_file(struct task_struct *task)
72748+{
72749+ return;
72750+}
72751+
72752+#ifdef CONFIG_SECURITY
72753+EXPORT_SYMBOL(gr_check_user_change);
72754+EXPORT_SYMBOL(gr_check_group_change);
72755+#endif
72756diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
72757new file mode 100644
72758index 0000000..387032b
72759--- /dev/null
72760+++ b/grsecurity/grsec_exec.c
72761@@ -0,0 +1,187 @@
72762+#include <linux/kernel.h>
72763+#include <linux/sched.h>
72764+#include <linux/file.h>
72765+#include <linux/binfmts.h>
72766+#include <linux/fs.h>
72767+#include <linux/types.h>
72768+#include <linux/grdefs.h>
72769+#include <linux/grsecurity.h>
72770+#include <linux/grinternal.h>
72771+#include <linux/capability.h>
72772+#include <linux/module.h>
72773+#include <linux/compat.h>
72774+
72775+#include <asm/uaccess.h>
72776+
72777+#ifdef CONFIG_GRKERNSEC_EXECLOG
72778+static char gr_exec_arg_buf[132];
72779+static DEFINE_MUTEX(gr_exec_arg_mutex);
72780+#endif
72781+
72782+struct user_arg_ptr {
72783+#ifdef CONFIG_COMPAT
72784+ bool is_compat;
72785+#endif
72786+ union {
72787+ const char __user *const __user *native;
72788+#ifdef CONFIG_COMPAT
72789+ const compat_uptr_t __user *compat;
72790+#endif
72791+ } ptr;
72792+};
72793+
72794+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
72795+
72796+void
72797+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
72798+{
72799+#ifdef CONFIG_GRKERNSEC_EXECLOG
72800+ char *grarg = gr_exec_arg_buf;
72801+ unsigned int i, x, execlen = 0;
72802+ char c;
72803+
72804+ if (!((grsec_enable_execlog && grsec_enable_group &&
72805+ in_group_p(grsec_audit_gid))
72806+ || (grsec_enable_execlog && !grsec_enable_group)))
72807+ return;
72808+
72809+ mutex_lock(&gr_exec_arg_mutex);
72810+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
72811+
72812+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
72813+ const char __user *p;
72814+ unsigned int len;
72815+
72816+ p = get_user_arg_ptr(argv, i);
72817+ if (IS_ERR(p))
72818+ goto log;
72819+
72820+ len = strnlen_user(p, 128 - execlen);
72821+ if (len > 128 - execlen)
72822+ len = 128 - execlen;
72823+ else if (len > 0)
72824+ len--;
72825+ if (copy_from_user(grarg + execlen, p, len))
72826+ goto log;
72827+
72828+ /* rewrite unprintable characters */
72829+ for (x = 0; x < len; x++) {
72830+ c = *(grarg + execlen + x);
72831+ if (c < 32 || c > 126)
72832+ *(grarg + execlen + x) = ' ';
72833+ }
72834+
72835+ execlen += len;
72836+ *(grarg + execlen) = ' ';
72837+ *(grarg + execlen + 1) = '\0';
72838+ execlen++;
72839+ }
72840+
72841+ log:
72842+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
72843+ bprm->file->f_path.mnt, grarg);
72844+ mutex_unlock(&gr_exec_arg_mutex);
72845+#endif
72846+ return;
72847+}
72848+
72849+#ifdef CONFIG_GRKERNSEC
72850+extern int gr_acl_is_capable(const int cap);
72851+extern int gr_acl_is_capable_nolog(const int cap);
72852+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
72853+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
72854+extern int gr_chroot_is_capable(const int cap);
72855+extern int gr_chroot_is_capable_nolog(const int cap);
72856+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
72857+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
72858+#endif
72859+
72860+const char *captab_log[] = {
72861+ "CAP_CHOWN",
72862+ "CAP_DAC_OVERRIDE",
72863+ "CAP_DAC_READ_SEARCH",
72864+ "CAP_FOWNER",
72865+ "CAP_FSETID",
72866+ "CAP_KILL",
72867+ "CAP_SETGID",
72868+ "CAP_SETUID",
72869+ "CAP_SETPCAP",
72870+ "CAP_LINUX_IMMUTABLE",
72871+ "CAP_NET_BIND_SERVICE",
72872+ "CAP_NET_BROADCAST",
72873+ "CAP_NET_ADMIN",
72874+ "CAP_NET_RAW",
72875+ "CAP_IPC_LOCK",
72876+ "CAP_IPC_OWNER",
72877+ "CAP_SYS_MODULE",
72878+ "CAP_SYS_RAWIO",
72879+ "CAP_SYS_CHROOT",
72880+ "CAP_SYS_PTRACE",
72881+ "CAP_SYS_PACCT",
72882+ "CAP_SYS_ADMIN",
72883+ "CAP_SYS_BOOT",
72884+ "CAP_SYS_NICE",
72885+ "CAP_SYS_RESOURCE",
72886+ "CAP_SYS_TIME",
72887+ "CAP_SYS_TTY_CONFIG",
72888+ "CAP_MKNOD",
72889+ "CAP_LEASE",
72890+ "CAP_AUDIT_WRITE",
72891+ "CAP_AUDIT_CONTROL",
72892+ "CAP_SETFCAP",
72893+ "CAP_MAC_OVERRIDE",
72894+ "CAP_MAC_ADMIN",
72895+ "CAP_SYSLOG",
72896+ "CAP_WAKE_ALARM"
72897+};
72898+
72899+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
72900+
72901+int gr_is_capable(const int cap)
72902+{
72903+#ifdef CONFIG_GRKERNSEC
72904+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
72905+ return 1;
72906+ return 0;
72907+#else
72908+ return 1;
72909+#endif
72910+}
72911+
72912+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72913+{
72914+#ifdef CONFIG_GRKERNSEC
72915+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
72916+ return 1;
72917+ return 0;
72918+#else
72919+ return 1;
72920+#endif
72921+}
72922+
72923+int gr_is_capable_nolog(const int cap)
72924+{
72925+#ifdef CONFIG_GRKERNSEC
72926+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
72927+ return 1;
72928+ return 0;
72929+#else
72930+ return 1;
72931+#endif
72932+}
72933+
72934+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
72935+{
72936+#ifdef CONFIG_GRKERNSEC
72937+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
72938+ return 1;
72939+ return 0;
72940+#else
72941+ return 1;
72942+#endif
72943+}
72944+
72945+EXPORT_SYMBOL(gr_is_capable);
72946+EXPORT_SYMBOL(gr_is_capable_nolog);
72947+EXPORT_SYMBOL(gr_task_is_capable);
72948+EXPORT_SYMBOL(gr_task_is_capable_nolog);
72949diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
72950new file mode 100644
72951index 0000000..06cc6ea
72952--- /dev/null
72953+++ b/grsecurity/grsec_fifo.c
72954@@ -0,0 +1,24 @@
72955+#include <linux/kernel.h>
72956+#include <linux/sched.h>
72957+#include <linux/fs.h>
72958+#include <linux/file.h>
72959+#include <linux/grinternal.h>
72960+
72961+int
72962+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
72963+ const struct dentry *dir, const int flag, const int acc_mode)
72964+{
72965+#ifdef CONFIG_GRKERNSEC_FIFO
72966+ const struct cred *cred = current_cred();
72967+
72968+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
72969+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
72970+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
72971+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
72972+ if (!inode_permission(dentry->d_inode, acc_mode))
72973+ 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));
72974+ return -EACCES;
72975+ }
72976+#endif
72977+ return 0;
72978+}
72979diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
72980new file mode 100644
72981index 0000000..8ca18bf
72982--- /dev/null
72983+++ b/grsecurity/grsec_fork.c
72984@@ -0,0 +1,23 @@
72985+#include <linux/kernel.h>
72986+#include <linux/sched.h>
72987+#include <linux/grsecurity.h>
72988+#include <linux/grinternal.h>
72989+#include <linux/errno.h>
72990+
72991+void
72992+gr_log_forkfail(const int retval)
72993+{
72994+#ifdef CONFIG_GRKERNSEC_FORKFAIL
72995+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
72996+ switch (retval) {
72997+ case -EAGAIN:
72998+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
72999+ break;
73000+ case -ENOMEM:
73001+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
73002+ break;
73003+ }
73004+ }
73005+#endif
73006+ return;
73007+}
73008diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
73009new file mode 100644
73010index 0000000..a88e901
73011--- /dev/null
73012+++ b/grsecurity/grsec_init.c
73013@@ -0,0 +1,272 @@
73014+#include <linux/kernel.h>
73015+#include <linux/sched.h>
73016+#include <linux/mm.h>
73017+#include <linux/gracl.h>
73018+#include <linux/slab.h>
73019+#include <linux/vmalloc.h>
73020+#include <linux/percpu.h>
73021+#include <linux/module.h>
73022+
73023+int grsec_enable_ptrace_readexec;
73024+int grsec_enable_setxid;
73025+int grsec_enable_symlinkown;
73026+kgid_t grsec_symlinkown_gid;
73027+int grsec_enable_brute;
73028+int grsec_enable_link;
73029+int grsec_enable_dmesg;
73030+int grsec_enable_harden_ptrace;
73031+int grsec_enable_harden_ipc;
73032+int grsec_enable_fifo;
73033+int grsec_enable_execlog;
73034+int grsec_enable_signal;
73035+int grsec_enable_forkfail;
73036+int grsec_enable_audit_ptrace;
73037+int grsec_enable_time;
73038+int grsec_enable_group;
73039+kgid_t grsec_audit_gid;
73040+int grsec_enable_chdir;
73041+int grsec_enable_mount;
73042+int grsec_enable_rofs;
73043+int grsec_deny_new_usb;
73044+int grsec_enable_chroot_findtask;
73045+int grsec_enable_chroot_mount;
73046+int grsec_enable_chroot_shmat;
73047+int grsec_enable_chroot_fchdir;
73048+int grsec_enable_chroot_double;
73049+int grsec_enable_chroot_pivot;
73050+int grsec_enable_chroot_chdir;
73051+int grsec_enable_chroot_chmod;
73052+int grsec_enable_chroot_mknod;
73053+int grsec_enable_chroot_nice;
73054+int grsec_enable_chroot_execlog;
73055+int grsec_enable_chroot_caps;
73056+int grsec_enable_chroot_sysctl;
73057+int grsec_enable_chroot_unix;
73058+int grsec_enable_tpe;
73059+kgid_t grsec_tpe_gid;
73060+int grsec_enable_blackhole;
73061+#ifdef CONFIG_IPV6_MODULE
73062+EXPORT_SYMBOL(grsec_enable_blackhole);
73063+#endif
73064+int grsec_lastack_retries;
73065+int grsec_enable_tpe_all;
73066+int grsec_enable_tpe_invert;
73067+int grsec_enable_socket_all;
73068+kgid_t grsec_socket_all_gid;
73069+int grsec_enable_socket_client;
73070+kgid_t grsec_socket_client_gid;
73071+int grsec_enable_socket_server;
73072+kgid_t grsec_socket_server_gid;
73073+int grsec_resource_logging;
73074+int grsec_disable_privio;
73075+int grsec_enable_log_rwxmaps;
73076+int grsec_lock;
73077+
73078+DEFINE_SPINLOCK(grsec_alert_lock);
73079+unsigned long grsec_alert_wtime = 0;
73080+unsigned long grsec_alert_fyet = 0;
73081+
73082+DEFINE_SPINLOCK(grsec_audit_lock);
73083+
73084+DEFINE_RWLOCK(grsec_exec_file_lock);
73085+
73086+char *gr_shared_page[4];
73087+
73088+char *gr_alert_log_fmt;
73089+char *gr_audit_log_fmt;
73090+char *gr_alert_log_buf;
73091+char *gr_audit_log_buf;
73092+
73093+void __init
73094+grsecurity_init(void)
73095+{
73096+ int j;
73097+ /* create the per-cpu shared pages */
73098+
73099+#ifdef CONFIG_X86
73100+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
73101+#endif
73102+
73103+ for (j = 0; j < 4; j++) {
73104+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
73105+ if (gr_shared_page[j] == NULL) {
73106+ panic("Unable to allocate grsecurity shared page");
73107+ return;
73108+ }
73109+ }
73110+
73111+ /* allocate log buffers */
73112+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
73113+ if (!gr_alert_log_fmt) {
73114+ panic("Unable to allocate grsecurity alert log format buffer");
73115+ return;
73116+ }
73117+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
73118+ if (!gr_audit_log_fmt) {
73119+ panic("Unable to allocate grsecurity audit log format buffer");
73120+ return;
73121+ }
73122+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
73123+ if (!gr_alert_log_buf) {
73124+ panic("Unable to allocate grsecurity alert log buffer");
73125+ return;
73126+ }
73127+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
73128+ if (!gr_audit_log_buf) {
73129+ panic("Unable to allocate grsecurity audit log buffer");
73130+ return;
73131+ }
73132+
73133+#ifdef CONFIG_GRKERNSEC_IO
73134+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
73135+ grsec_disable_privio = 1;
73136+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
73137+ grsec_disable_privio = 1;
73138+#else
73139+ grsec_disable_privio = 0;
73140+#endif
73141+#endif
73142+
73143+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
73144+ /* for backward compatibility, tpe_invert always defaults to on if
73145+ enabled in the kernel
73146+ */
73147+ grsec_enable_tpe_invert = 1;
73148+#endif
73149+
73150+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
73151+#ifndef CONFIG_GRKERNSEC_SYSCTL
73152+ grsec_lock = 1;
73153+#endif
73154+
73155+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73156+ grsec_enable_log_rwxmaps = 1;
73157+#endif
73158+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
73159+ grsec_enable_group = 1;
73160+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
73161+#endif
73162+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
73163+ grsec_enable_ptrace_readexec = 1;
73164+#endif
73165+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73166+ grsec_enable_chdir = 1;
73167+#endif
73168+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
73169+ grsec_enable_harden_ptrace = 1;
73170+#endif
73171+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
73172+ grsec_enable_harden_ipc = 1;
73173+#endif
73174+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73175+ grsec_enable_mount = 1;
73176+#endif
73177+#ifdef CONFIG_GRKERNSEC_LINK
73178+ grsec_enable_link = 1;
73179+#endif
73180+#ifdef CONFIG_GRKERNSEC_BRUTE
73181+ grsec_enable_brute = 1;
73182+#endif
73183+#ifdef CONFIG_GRKERNSEC_DMESG
73184+ grsec_enable_dmesg = 1;
73185+#endif
73186+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73187+ grsec_enable_blackhole = 1;
73188+ grsec_lastack_retries = 4;
73189+#endif
73190+#ifdef CONFIG_GRKERNSEC_FIFO
73191+ grsec_enable_fifo = 1;
73192+#endif
73193+#ifdef CONFIG_GRKERNSEC_EXECLOG
73194+ grsec_enable_execlog = 1;
73195+#endif
73196+#ifdef CONFIG_GRKERNSEC_SETXID
73197+ grsec_enable_setxid = 1;
73198+#endif
73199+#ifdef CONFIG_GRKERNSEC_SIGNAL
73200+ grsec_enable_signal = 1;
73201+#endif
73202+#ifdef CONFIG_GRKERNSEC_FORKFAIL
73203+ grsec_enable_forkfail = 1;
73204+#endif
73205+#ifdef CONFIG_GRKERNSEC_TIME
73206+ grsec_enable_time = 1;
73207+#endif
73208+#ifdef CONFIG_GRKERNSEC_RESLOG
73209+ grsec_resource_logging = 1;
73210+#endif
73211+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73212+ grsec_enable_chroot_findtask = 1;
73213+#endif
73214+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73215+ grsec_enable_chroot_unix = 1;
73216+#endif
73217+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73218+ grsec_enable_chroot_mount = 1;
73219+#endif
73220+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73221+ grsec_enable_chroot_fchdir = 1;
73222+#endif
73223+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73224+ grsec_enable_chroot_shmat = 1;
73225+#endif
73226+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
73227+ grsec_enable_audit_ptrace = 1;
73228+#endif
73229+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73230+ grsec_enable_chroot_double = 1;
73231+#endif
73232+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73233+ grsec_enable_chroot_pivot = 1;
73234+#endif
73235+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73236+ grsec_enable_chroot_chdir = 1;
73237+#endif
73238+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73239+ grsec_enable_chroot_chmod = 1;
73240+#endif
73241+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73242+ grsec_enable_chroot_mknod = 1;
73243+#endif
73244+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73245+ grsec_enable_chroot_nice = 1;
73246+#endif
73247+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73248+ grsec_enable_chroot_execlog = 1;
73249+#endif
73250+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73251+ grsec_enable_chroot_caps = 1;
73252+#endif
73253+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73254+ grsec_enable_chroot_sysctl = 1;
73255+#endif
73256+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
73257+ grsec_enable_symlinkown = 1;
73258+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
73259+#endif
73260+#ifdef CONFIG_GRKERNSEC_TPE
73261+ grsec_enable_tpe = 1;
73262+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
73263+#ifdef CONFIG_GRKERNSEC_TPE_ALL
73264+ grsec_enable_tpe_all = 1;
73265+#endif
73266+#endif
73267+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
73268+ grsec_enable_socket_all = 1;
73269+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
73270+#endif
73271+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
73272+ grsec_enable_socket_client = 1;
73273+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
73274+#endif
73275+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
73276+ grsec_enable_socket_server = 1;
73277+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
73278+#endif
73279+#endif
73280+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
73281+ grsec_deny_new_usb = 1;
73282+#endif
73283+
73284+ return;
73285+}
73286diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
73287new file mode 100644
73288index 0000000..78d1680
73289--- /dev/null
73290+++ b/grsecurity/grsec_ipc.c
73291@@ -0,0 +1,48 @@
73292+#include <linux/kernel.h>
73293+#include <linux/mm.h>
73294+#include <linux/sched.h>
73295+#include <linux/file.h>
73296+#include <linux/ipc.h>
73297+#include <linux/ipc_namespace.h>
73298+#include <linux/grsecurity.h>
73299+#include <linux/grinternal.h>
73300+
73301+int
73302+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
73303+{
73304+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
73305+ int write;
73306+ int orig_granted_mode;
73307+ kuid_t euid;
73308+ kgid_t egid;
73309+
73310+ if (!grsec_enable_harden_ipc)
73311+ return 0;
73312+
73313+ euid = current_euid();
73314+ egid = current_egid();
73315+
73316+ write = requested_mode & 00002;
73317+ orig_granted_mode = ipcp->mode;
73318+
73319+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
73320+ orig_granted_mode >>= 6;
73321+ else {
73322+ /* if likely wrong permissions, lock to user */
73323+ if (orig_granted_mode & 0007)
73324+ orig_granted_mode = 0;
73325+ /* otherwise do a egid-only check */
73326+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
73327+ orig_granted_mode >>= 3;
73328+ /* otherwise, no access */
73329+ else
73330+ orig_granted_mode = 0;
73331+ }
73332+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
73333+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
73334+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
73335+ return 0;
73336+ }
73337+#endif
73338+ return 1;
73339+}
73340diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
73341new file mode 100644
73342index 0000000..5e05e20
73343--- /dev/null
73344+++ b/grsecurity/grsec_link.c
73345@@ -0,0 +1,58 @@
73346+#include <linux/kernel.h>
73347+#include <linux/sched.h>
73348+#include <linux/fs.h>
73349+#include <linux/file.h>
73350+#include <linux/grinternal.h>
73351+
73352+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
73353+{
73354+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
73355+ const struct inode *link_inode = link->dentry->d_inode;
73356+
73357+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
73358+ /* ignore root-owned links, e.g. /proc/self */
73359+ gr_is_global_nonroot(link_inode->i_uid) && target &&
73360+ !uid_eq(link_inode->i_uid, target->i_uid)) {
73361+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
73362+ return 1;
73363+ }
73364+#endif
73365+ return 0;
73366+}
73367+
73368+int
73369+gr_handle_follow_link(const struct inode *parent,
73370+ const struct inode *inode,
73371+ const struct dentry *dentry, const struct vfsmount *mnt)
73372+{
73373+#ifdef CONFIG_GRKERNSEC_LINK
73374+ const struct cred *cred = current_cred();
73375+
73376+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
73377+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
73378+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
73379+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
73380+ return -EACCES;
73381+ }
73382+#endif
73383+ return 0;
73384+}
73385+
73386+int
73387+gr_handle_hardlink(const struct dentry *dentry,
73388+ const struct vfsmount *mnt,
73389+ struct inode *inode, const int mode, const struct filename *to)
73390+{
73391+#ifdef CONFIG_GRKERNSEC_LINK
73392+ const struct cred *cred = current_cred();
73393+
73394+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
73395+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
73396+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
73397+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
73398+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
73399+ return -EPERM;
73400+ }
73401+#endif
73402+ return 0;
73403+}
73404diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
73405new file mode 100644
73406index 0000000..dbe0a6b
73407--- /dev/null
73408+++ b/grsecurity/grsec_log.c
73409@@ -0,0 +1,341 @@
73410+#include <linux/kernel.h>
73411+#include <linux/sched.h>
73412+#include <linux/file.h>
73413+#include <linux/tty.h>
73414+#include <linux/fs.h>
73415+#include <linux/mm.h>
73416+#include <linux/grinternal.h>
73417+
73418+#ifdef CONFIG_TREE_PREEMPT_RCU
73419+#define DISABLE_PREEMPT() preempt_disable()
73420+#define ENABLE_PREEMPT() preempt_enable()
73421+#else
73422+#define DISABLE_PREEMPT()
73423+#define ENABLE_PREEMPT()
73424+#endif
73425+
73426+#define BEGIN_LOCKS(x) \
73427+ DISABLE_PREEMPT(); \
73428+ rcu_read_lock(); \
73429+ read_lock(&tasklist_lock); \
73430+ read_lock(&grsec_exec_file_lock); \
73431+ if (x != GR_DO_AUDIT) \
73432+ spin_lock(&grsec_alert_lock); \
73433+ else \
73434+ spin_lock(&grsec_audit_lock)
73435+
73436+#define END_LOCKS(x) \
73437+ if (x != GR_DO_AUDIT) \
73438+ spin_unlock(&grsec_alert_lock); \
73439+ else \
73440+ spin_unlock(&grsec_audit_lock); \
73441+ read_unlock(&grsec_exec_file_lock); \
73442+ read_unlock(&tasklist_lock); \
73443+ rcu_read_unlock(); \
73444+ ENABLE_PREEMPT(); \
73445+ if (x == GR_DONT_AUDIT) \
73446+ gr_handle_alertkill(current)
73447+
73448+enum {
73449+ FLOODING,
73450+ NO_FLOODING
73451+};
73452+
73453+extern char *gr_alert_log_fmt;
73454+extern char *gr_audit_log_fmt;
73455+extern char *gr_alert_log_buf;
73456+extern char *gr_audit_log_buf;
73457+
73458+static int gr_log_start(int audit)
73459+{
73460+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
73461+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
73462+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73463+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
73464+ unsigned long curr_secs = get_seconds();
73465+
73466+ if (audit == GR_DO_AUDIT)
73467+ goto set_fmt;
73468+
73469+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
73470+ grsec_alert_wtime = curr_secs;
73471+ grsec_alert_fyet = 0;
73472+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
73473+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
73474+ grsec_alert_fyet++;
73475+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
73476+ grsec_alert_wtime = curr_secs;
73477+ grsec_alert_fyet++;
73478+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
73479+ return FLOODING;
73480+ }
73481+ else return FLOODING;
73482+
73483+set_fmt:
73484+#endif
73485+ memset(buf, 0, PAGE_SIZE);
73486+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
73487+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
73488+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
73489+ } else if (current->signal->curr_ip) {
73490+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
73491+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
73492+ } else if (gr_acl_is_enabled()) {
73493+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
73494+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
73495+ } else {
73496+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
73497+ strcpy(buf, fmt);
73498+ }
73499+
73500+ return NO_FLOODING;
73501+}
73502+
73503+static void gr_log_middle(int audit, const char *msg, va_list ap)
73504+ __attribute__ ((format (printf, 2, 0)));
73505+
73506+static void gr_log_middle(int audit, const char *msg, va_list ap)
73507+{
73508+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73509+ unsigned int len = strlen(buf);
73510+
73511+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
73512+
73513+ return;
73514+}
73515+
73516+static void gr_log_middle_varargs(int audit, const char *msg, ...)
73517+ __attribute__ ((format (printf, 2, 3)));
73518+
73519+static void gr_log_middle_varargs(int audit, const char *msg, ...)
73520+{
73521+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73522+ unsigned int len = strlen(buf);
73523+ va_list ap;
73524+
73525+ va_start(ap, msg);
73526+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
73527+ va_end(ap);
73528+
73529+ return;
73530+}
73531+
73532+static void gr_log_end(int audit, int append_default)
73533+{
73534+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73535+ if (append_default) {
73536+ struct task_struct *task = current;
73537+ struct task_struct *parent = task->real_parent;
73538+ const struct cred *cred = __task_cred(task);
73539+ const struct cred *pcred = __task_cred(parent);
73540+ unsigned int len = strlen(buf);
73541+
73542+ 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));
73543+ }
73544+
73545+ printk("%s\n", buf);
73546+
73547+ return;
73548+}
73549+
73550+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
73551+{
73552+ int logtype;
73553+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
73554+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
73555+ void *voidptr = NULL;
73556+ int num1 = 0, num2 = 0;
73557+ unsigned long ulong1 = 0, ulong2 = 0;
73558+ struct dentry *dentry = NULL;
73559+ struct vfsmount *mnt = NULL;
73560+ struct file *file = NULL;
73561+ struct task_struct *task = NULL;
73562+ struct vm_area_struct *vma = NULL;
73563+ const struct cred *cred, *pcred;
73564+ va_list ap;
73565+
73566+ BEGIN_LOCKS(audit);
73567+ logtype = gr_log_start(audit);
73568+ if (logtype == FLOODING) {
73569+ END_LOCKS(audit);
73570+ return;
73571+ }
73572+ va_start(ap, argtypes);
73573+ switch (argtypes) {
73574+ case GR_TTYSNIFF:
73575+ task = va_arg(ap, struct task_struct *);
73576+ 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));
73577+ break;
73578+ case GR_SYSCTL_HIDDEN:
73579+ str1 = va_arg(ap, char *);
73580+ gr_log_middle_varargs(audit, msg, result, str1);
73581+ break;
73582+ case GR_RBAC:
73583+ dentry = va_arg(ap, struct dentry *);
73584+ mnt = va_arg(ap, struct vfsmount *);
73585+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
73586+ break;
73587+ case GR_RBAC_STR:
73588+ dentry = va_arg(ap, struct dentry *);
73589+ mnt = va_arg(ap, struct vfsmount *);
73590+ str1 = va_arg(ap, char *);
73591+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
73592+ break;
73593+ case GR_STR_RBAC:
73594+ str1 = va_arg(ap, char *);
73595+ dentry = va_arg(ap, struct dentry *);
73596+ mnt = va_arg(ap, struct vfsmount *);
73597+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
73598+ break;
73599+ case GR_RBAC_MODE2:
73600+ dentry = va_arg(ap, struct dentry *);
73601+ mnt = va_arg(ap, struct vfsmount *);
73602+ str1 = va_arg(ap, char *);
73603+ str2 = va_arg(ap, char *);
73604+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
73605+ break;
73606+ case GR_RBAC_MODE3:
73607+ dentry = va_arg(ap, struct dentry *);
73608+ mnt = va_arg(ap, struct vfsmount *);
73609+ str1 = va_arg(ap, char *);
73610+ str2 = va_arg(ap, char *);
73611+ str3 = va_arg(ap, char *);
73612+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
73613+ break;
73614+ case GR_FILENAME:
73615+ dentry = va_arg(ap, struct dentry *);
73616+ mnt = va_arg(ap, struct vfsmount *);
73617+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
73618+ break;
73619+ case GR_STR_FILENAME:
73620+ str1 = va_arg(ap, char *);
73621+ dentry = va_arg(ap, struct dentry *);
73622+ mnt = va_arg(ap, struct vfsmount *);
73623+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
73624+ break;
73625+ case GR_FILENAME_STR:
73626+ dentry = va_arg(ap, struct dentry *);
73627+ mnt = va_arg(ap, struct vfsmount *);
73628+ str1 = va_arg(ap, char *);
73629+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
73630+ break;
73631+ case GR_FILENAME_TWO_INT:
73632+ dentry = va_arg(ap, struct dentry *);
73633+ mnt = va_arg(ap, struct vfsmount *);
73634+ num1 = va_arg(ap, int);
73635+ num2 = va_arg(ap, int);
73636+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
73637+ break;
73638+ case GR_FILENAME_TWO_INT_STR:
73639+ dentry = va_arg(ap, struct dentry *);
73640+ mnt = va_arg(ap, struct vfsmount *);
73641+ num1 = va_arg(ap, int);
73642+ num2 = va_arg(ap, int);
73643+ str1 = va_arg(ap, char *);
73644+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
73645+ break;
73646+ case GR_TEXTREL:
73647+ file = va_arg(ap, struct file *);
73648+ ulong1 = va_arg(ap, unsigned long);
73649+ ulong2 = va_arg(ap, unsigned long);
73650+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
73651+ break;
73652+ case GR_PTRACE:
73653+ task = va_arg(ap, struct task_struct *);
73654+ 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));
73655+ break;
73656+ case GR_RESOURCE:
73657+ task = va_arg(ap, struct task_struct *);
73658+ cred = __task_cred(task);
73659+ pcred = __task_cred(task->real_parent);
73660+ ulong1 = va_arg(ap, unsigned long);
73661+ str1 = va_arg(ap, char *);
73662+ ulong2 = va_arg(ap, unsigned long);
73663+ 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));
73664+ break;
73665+ case GR_CAP:
73666+ task = va_arg(ap, struct task_struct *);
73667+ cred = __task_cred(task);
73668+ pcred = __task_cred(task->real_parent);
73669+ str1 = va_arg(ap, char *);
73670+ 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));
73671+ break;
73672+ case GR_SIG:
73673+ str1 = va_arg(ap, char *);
73674+ voidptr = va_arg(ap, void *);
73675+ gr_log_middle_varargs(audit, msg, str1, voidptr);
73676+ break;
73677+ case GR_SIG2:
73678+ task = va_arg(ap, struct task_struct *);
73679+ cred = __task_cred(task);
73680+ pcred = __task_cred(task->real_parent);
73681+ num1 = va_arg(ap, int);
73682+ 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));
73683+ break;
73684+ case GR_CRASH1:
73685+ task = va_arg(ap, struct task_struct *);
73686+ cred = __task_cred(task);
73687+ pcred = __task_cred(task->real_parent);
73688+ ulong1 = va_arg(ap, unsigned long);
73689+ 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);
73690+ break;
73691+ case GR_CRASH2:
73692+ task = va_arg(ap, struct task_struct *);
73693+ cred = __task_cred(task);
73694+ pcred = __task_cred(task->real_parent);
73695+ ulong1 = va_arg(ap, unsigned long);
73696+ 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);
73697+ break;
73698+ case GR_RWXMAP:
73699+ file = va_arg(ap, struct file *);
73700+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
73701+ break;
73702+ case GR_RWXMAPVMA:
73703+ vma = va_arg(ap, struct vm_area_struct *);
73704+ if (vma->vm_file)
73705+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
73706+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
73707+ str1 = "<stack>";
73708+ else if (vma->vm_start <= current->mm->brk &&
73709+ vma->vm_end >= current->mm->start_brk)
73710+ str1 = "<heap>";
73711+ else
73712+ str1 = "<anonymous mapping>";
73713+ gr_log_middle_varargs(audit, msg, str1);
73714+ break;
73715+ case GR_PSACCT:
73716+ {
73717+ unsigned int wday, cday;
73718+ __u8 whr, chr;
73719+ __u8 wmin, cmin;
73720+ __u8 wsec, csec;
73721+ char cur_tty[64] = { 0 };
73722+ char parent_tty[64] = { 0 };
73723+
73724+ task = va_arg(ap, struct task_struct *);
73725+ wday = va_arg(ap, unsigned int);
73726+ cday = va_arg(ap, unsigned int);
73727+ whr = va_arg(ap, int);
73728+ chr = va_arg(ap, int);
73729+ wmin = va_arg(ap, int);
73730+ cmin = va_arg(ap, int);
73731+ wsec = va_arg(ap, int);
73732+ csec = va_arg(ap, int);
73733+ ulong1 = va_arg(ap, unsigned long);
73734+ cred = __task_cred(task);
73735+ pcred = __task_cred(task->real_parent);
73736+
73737+ 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));
73738+ }
73739+ break;
73740+ default:
73741+ gr_log_middle(audit, msg, ap);
73742+ }
73743+ va_end(ap);
73744+ // these don't need DEFAULTSECARGS printed on the end
73745+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
73746+ gr_log_end(audit, 0);
73747+ else
73748+ gr_log_end(audit, 1);
73749+ END_LOCKS(audit);
73750+}
73751diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
73752new file mode 100644
73753index 0000000..f536303
73754--- /dev/null
73755+++ b/grsecurity/grsec_mem.c
73756@@ -0,0 +1,40 @@
73757+#include <linux/kernel.h>
73758+#include <linux/sched.h>
73759+#include <linux/mm.h>
73760+#include <linux/mman.h>
73761+#include <linux/grinternal.h>
73762+
73763+void
73764+gr_handle_ioperm(void)
73765+{
73766+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
73767+ return;
73768+}
73769+
73770+void
73771+gr_handle_iopl(void)
73772+{
73773+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
73774+ return;
73775+}
73776+
73777+void
73778+gr_handle_mem_readwrite(u64 from, u64 to)
73779+{
73780+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
73781+ return;
73782+}
73783+
73784+void
73785+gr_handle_vm86(void)
73786+{
73787+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
73788+ return;
73789+}
73790+
73791+void
73792+gr_log_badprocpid(const char *entry)
73793+{
73794+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
73795+ return;
73796+}
73797diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
73798new file mode 100644
73799index 0000000..cd9e124
73800--- /dev/null
73801+++ b/grsecurity/grsec_mount.c
73802@@ -0,0 +1,65 @@
73803+#include <linux/kernel.h>
73804+#include <linux/sched.h>
73805+#include <linux/mount.h>
73806+#include <linux/major.h>
73807+#include <linux/grsecurity.h>
73808+#include <linux/grinternal.h>
73809+
73810+void
73811+gr_log_remount(const char *devname, const int retval)
73812+{
73813+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73814+ if (grsec_enable_mount && (retval >= 0))
73815+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
73816+#endif
73817+ return;
73818+}
73819+
73820+void
73821+gr_log_unmount(const char *devname, const int retval)
73822+{
73823+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73824+ if (grsec_enable_mount && (retval >= 0))
73825+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
73826+#endif
73827+ return;
73828+}
73829+
73830+void
73831+gr_log_mount(const char *from, const char *to, const int retval)
73832+{
73833+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73834+ if (grsec_enable_mount && (retval >= 0))
73835+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
73836+#endif
73837+ return;
73838+}
73839+
73840+int
73841+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
73842+{
73843+#ifdef CONFIG_GRKERNSEC_ROFS
73844+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
73845+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
73846+ return -EPERM;
73847+ } else
73848+ return 0;
73849+#endif
73850+ return 0;
73851+}
73852+
73853+int
73854+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
73855+{
73856+#ifdef CONFIG_GRKERNSEC_ROFS
73857+ struct inode *inode = dentry->d_inode;
73858+
73859+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
73860+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
73861+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
73862+ return -EPERM;
73863+ } else
73864+ return 0;
73865+#endif
73866+ return 0;
73867+}
73868diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
73869new file mode 100644
73870index 0000000..6ee9d50
73871--- /dev/null
73872+++ b/grsecurity/grsec_pax.c
73873@@ -0,0 +1,45 @@
73874+#include <linux/kernel.h>
73875+#include <linux/sched.h>
73876+#include <linux/mm.h>
73877+#include <linux/file.h>
73878+#include <linux/grinternal.h>
73879+#include <linux/grsecurity.h>
73880+
73881+void
73882+gr_log_textrel(struct vm_area_struct * vma)
73883+{
73884+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73885+ if (grsec_enable_log_rwxmaps)
73886+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
73887+#endif
73888+ return;
73889+}
73890+
73891+void gr_log_ptgnustack(struct file *file)
73892+{
73893+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73894+ if (grsec_enable_log_rwxmaps)
73895+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
73896+#endif
73897+ return;
73898+}
73899+
73900+void
73901+gr_log_rwxmmap(struct file *file)
73902+{
73903+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73904+ if (grsec_enable_log_rwxmaps)
73905+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
73906+#endif
73907+ return;
73908+}
73909+
73910+void
73911+gr_log_rwxmprotect(struct vm_area_struct *vma)
73912+{
73913+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73914+ if (grsec_enable_log_rwxmaps)
73915+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
73916+#endif
73917+ return;
73918+}
73919diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
73920new file mode 100644
73921index 0000000..f7f29aa
73922--- /dev/null
73923+++ b/grsecurity/grsec_ptrace.c
73924@@ -0,0 +1,30 @@
73925+#include <linux/kernel.h>
73926+#include <linux/sched.h>
73927+#include <linux/grinternal.h>
73928+#include <linux/security.h>
73929+
73930+void
73931+gr_audit_ptrace(struct task_struct *task)
73932+{
73933+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
73934+ if (grsec_enable_audit_ptrace)
73935+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
73936+#endif
73937+ return;
73938+}
73939+
73940+int
73941+gr_ptrace_readexec(struct file *file, int unsafe_flags)
73942+{
73943+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
73944+ const struct dentry *dentry = file->f_path.dentry;
73945+ const struct vfsmount *mnt = file->f_path.mnt;
73946+
73947+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
73948+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
73949+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
73950+ return -EACCES;
73951+ }
73952+#endif
73953+ return 0;
73954+}
73955diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
73956new file mode 100644
73957index 0000000..3860c7e
73958--- /dev/null
73959+++ b/grsecurity/grsec_sig.c
73960@@ -0,0 +1,236 @@
73961+#include <linux/kernel.h>
73962+#include <linux/sched.h>
73963+#include <linux/fs.h>
73964+#include <linux/delay.h>
73965+#include <linux/grsecurity.h>
73966+#include <linux/grinternal.h>
73967+#include <linux/hardirq.h>
73968+
73969+char *signames[] = {
73970+ [SIGSEGV] = "Segmentation fault",
73971+ [SIGILL] = "Illegal instruction",
73972+ [SIGABRT] = "Abort",
73973+ [SIGBUS] = "Invalid alignment/Bus error"
73974+};
73975+
73976+void
73977+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
73978+{
73979+#ifdef CONFIG_GRKERNSEC_SIGNAL
73980+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
73981+ (sig == SIGABRT) || (sig == SIGBUS))) {
73982+ if (task_pid_nr(t) == task_pid_nr(current)) {
73983+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
73984+ } else {
73985+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
73986+ }
73987+ }
73988+#endif
73989+ return;
73990+}
73991+
73992+int
73993+gr_handle_signal(const struct task_struct *p, const int sig)
73994+{
73995+#ifdef CONFIG_GRKERNSEC
73996+ /* ignore the 0 signal for protected task checks */
73997+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
73998+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
73999+ return -EPERM;
74000+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
74001+ return -EPERM;
74002+ }
74003+#endif
74004+ return 0;
74005+}
74006+
74007+#ifdef CONFIG_GRKERNSEC
74008+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
74009+
74010+int gr_fake_force_sig(int sig, struct task_struct *t)
74011+{
74012+ unsigned long int flags;
74013+ int ret, blocked, ignored;
74014+ struct k_sigaction *action;
74015+
74016+ spin_lock_irqsave(&t->sighand->siglock, flags);
74017+ action = &t->sighand->action[sig-1];
74018+ ignored = action->sa.sa_handler == SIG_IGN;
74019+ blocked = sigismember(&t->blocked, sig);
74020+ if (blocked || ignored) {
74021+ action->sa.sa_handler = SIG_DFL;
74022+ if (blocked) {
74023+ sigdelset(&t->blocked, sig);
74024+ recalc_sigpending_and_wake(t);
74025+ }
74026+ }
74027+ if (action->sa.sa_handler == SIG_DFL)
74028+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
74029+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
74030+
74031+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
74032+
74033+ return ret;
74034+}
74035+#endif
74036+
74037+#define GR_USER_BAN_TIME (15 * 60)
74038+#define GR_DAEMON_BRUTE_TIME (30 * 60)
74039+
74040+void gr_handle_brute_attach(int dumpable)
74041+{
74042+#ifdef CONFIG_GRKERNSEC_BRUTE
74043+ struct task_struct *p = current;
74044+ kuid_t uid = GLOBAL_ROOT_UID;
74045+ int daemon = 0;
74046+
74047+ if (!grsec_enable_brute)
74048+ return;
74049+
74050+ rcu_read_lock();
74051+ read_lock(&tasklist_lock);
74052+ read_lock(&grsec_exec_file_lock);
74053+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
74054+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
74055+ p->real_parent->brute = 1;
74056+ daemon = 1;
74057+ } else {
74058+ const struct cred *cred = __task_cred(p), *cred2;
74059+ struct task_struct *tsk, *tsk2;
74060+
74061+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
74062+ struct user_struct *user;
74063+
74064+ uid = cred->uid;
74065+
74066+ /* this is put upon execution past expiration */
74067+ user = find_user(uid);
74068+ if (user == NULL)
74069+ goto unlock;
74070+ user->suid_banned = 1;
74071+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
74072+ if (user->suid_ban_expires == ~0UL)
74073+ user->suid_ban_expires--;
74074+
74075+ /* only kill other threads of the same binary, from the same user */
74076+ do_each_thread(tsk2, tsk) {
74077+ cred2 = __task_cred(tsk);
74078+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
74079+ gr_fake_force_sig(SIGKILL, tsk);
74080+ } while_each_thread(tsk2, tsk);
74081+ }
74082+ }
74083+unlock:
74084+ read_unlock(&grsec_exec_file_lock);
74085+ read_unlock(&tasklist_lock);
74086+ rcu_read_unlock();
74087+
74088+ if (gr_is_global_nonroot(uid))
74089+ 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);
74090+ else if (daemon)
74091+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
74092+
74093+#endif
74094+ return;
74095+}
74096+
74097+void gr_handle_brute_check(void)
74098+{
74099+#ifdef CONFIG_GRKERNSEC_BRUTE
74100+ struct task_struct *p = current;
74101+
74102+ if (unlikely(p->brute)) {
74103+ if (!grsec_enable_brute)
74104+ p->brute = 0;
74105+ else if (time_before(get_seconds(), p->brute_expires))
74106+ msleep(30 * 1000);
74107+ }
74108+#endif
74109+ return;
74110+}
74111+
74112+void gr_handle_kernel_exploit(void)
74113+{
74114+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74115+ const struct cred *cred;
74116+ struct task_struct *tsk, *tsk2;
74117+ struct user_struct *user;
74118+ kuid_t uid;
74119+
74120+ if (in_irq() || in_serving_softirq() || in_nmi())
74121+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
74122+
74123+ uid = current_uid();
74124+
74125+ if (gr_is_global_root(uid))
74126+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
74127+ else {
74128+ /* kill all the processes of this user, hold a reference
74129+ to their creds struct, and prevent them from creating
74130+ another process until system reset
74131+ */
74132+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
74133+ GR_GLOBAL_UID(uid));
74134+ /* we intentionally leak this ref */
74135+ user = get_uid(current->cred->user);
74136+ if (user)
74137+ user->kernel_banned = 1;
74138+
74139+ /* kill all processes of this user */
74140+ read_lock(&tasklist_lock);
74141+ do_each_thread(tsk2, tsk) {
74142+ cred = __task_cred(tsk);
74143+ if (uid_eq(cred->uid, uid))
74144+ gr_fake_force_sig(SIGKILL, tsk);
74145+ } while_each_thread(tsk2, tsk);
74146+ read_unlock(&tasklist_lock);
74147+ }
74148+#endif
74149+}
74150+
74151+#ifdef CONFIG_GRKERNSEC_BRUTE
74152+static bool suid_ban_expired(struct user_struct *user)
74153+{
74154+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
74155+ user->suid_banned = 0;
74156+ user->suid_ban_expires = 0;
74157+ free_uid(user);
74158+ return true;
74159+ }
74160+
74161+ return false;
74162+}
74163+#endif
74164+
74165+int gr_process_kernel_exec_ban(void)
74166+{
74167+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74168+ if (unlikely(current->cred->user->kernel_banned))
74169+ return -EPERM;
74170+#endif
74171+ return 0;
74172+}
74173+
74174+int gr_process_kernel_setuid_ban(struct user_struct *user)
74175+{
74176+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74177+ if (unlikely(user->kernel_banned))
74178+ gr_fake_force_sig(SIGKILL, current);
74179+#endif
74180+ return 0;
74181+}
74182+
74183+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
74184+{
74185+#ifdef CONFIG_GRKERNSEC_BRUTE
74186+ struct user_struct *user = current->cred->user;
74187+ if (unlikely(user->suid_banned)) {
74188+ if (suid_ban_expired(user))
74189+ return 0;
74190+ /* disallow execution of suid binaries only */
74191+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
74192+ return -EPERM;
74193+ }
74194+#endif
74195+ return 0;
74196+}
74197diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
74198new file mode 100644
74199index 0000000..4030d57
74200--- /dev/null
74201+++ b/grsecurity/grsec_sock.c
74202@@ -0,0 +1,244 @@
74203+#include <linux/kernel.h>
74204+#include <linux/module.h>
74205+#include <linux/sched.h>
74206+#include <linux/file.h>
74207+#include <linux/net.h>
74208+#include <linux/in.h>
74209+#include <linux/ip.h>
74210+#include <net/sock.h>
74211+#include <net/inet_sock.h>
74212+#include <linux/grsecurity.h>
74213+#include <linux/grinternal.h>
74214+#include <linux/gracl.h>
74215+
74216+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
74217+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
74218+
74219+EXPORT_SYMBOL(gr_search_udp_recvmsg);
74220+EXPORT_SYMBOL(gr_search_udp_sendmsg);
74221+
74222+#ifdef CONFIG_UNIX_MODULE
74223+EXPORT_SYMBOL(gr_acl_handle_unix);
74224+EXPORT_SYMBOL(gr_acl_handle_mknod);
74225+EXPORT_SYMBOL(gr_handle_chroot_unix);
74226+EXPORT_SYMBOL(gr_handle_create);
74227+#endif
74228+
74229+#ifdef CONFIG_GRKERNSEC
74230+#define gr_conn_table_size 32749
74231+struct conn_table_entry {
74232+ struct conn_table_entry *next;
74233+ struct signal_struct *sig;
74234+};
74235+
74236+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
74237+DEFINE_SPINLOCK(gr_conn_table_lock);
74238+
74239+extern const char * gr_socktype_to_name(unsigned char type);
74240+extern const char * gr_proto_to_name(unsigned char proto);
74241+extern const char * gr_sockfamily_to_name(unsigned char family);
74242+
74243+static __inline__ int
74244+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
74245+{
74246+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
74247+}
74248+
74249+static __inline__ int
74250+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
74251+ __u16 sport, __u16 dport)
74252+{
74253+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
74254+ sig->gr_sport == sport && sig->gr_dport == dport))
74255+ return 1;
74256+ else
74257+ return 0;
74258+}
74259+
74260+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
74261+{
74262+ struct conn_table_entry **match;
74263+ unsigned int index;
74264+
74265+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
74266+ sig->gr_sport, sig->gr_dport,
74267+ gr_conn_table_size);
74268+
74269+ newent->sig = sig;
74270+
74271+ match = &gr_conn_table[index];
74272+ newent->next = *match;
74273+ *match = newent;
74274+
74275+ return;
74276+}
74277+
74278+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
74279+{
74280+ struct conn_table_entry *match, *last = NULL;
74281+ unsigned int index;
74282+
74283+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
74284+ sig->gr_sport, sig->gr_dport,
74285+ gr_conn_table_size);
74286+
74287+ match = gr_conn_table[index];
74288+ while (match && !conn_match(match->sig,
74289+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
74290+ sig->gr_dport)) {
74291+ last = match;
74292+ match = match->next;
74293+ }
74294+
74295+ if (match) {
74296+ if (last)
74297+ last->next = match->next;
74298+ else
74299+ gr_conn_table[index] = NULL;
74300+ kfree(match);
74301+ }
74302+
74303+ return;
74304+}
74305+
74306+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
74307+ __u16 sport, __u16 dport)
74308+{
74309+ struct conn_table_entry *match;
74310+ unsigned int index;
74311+
74312+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
74313+
74314+ match = gr_conn_table[index];
74315+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
74316+ match = match->next;
74317+
74318+ if (match)
74319+ return match->sig;
74320+ else
74321+ return NULL;
74322+}
74323+
74324+#endif
74325+
74326+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
74327+{
74328+#ifdef CONFIG_GRKERNSEC
74329+ struct signal_struct *sig = task->signal;
74330+ struct conn_table_entry *newent;
74331+
74332+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
74333+ if (newent == NULL)
74334+ return;
74335+ /* no bh lock needed since we are called with bh disabled */
74336+ spin_lock(&gr_conn_table_lock);
74337+ gr_del_task_from_ip_table_nolock(sig);
74338+ sig->gr_saddr = inet->inet_rcv_saddr;
74339+ sig->gr_daddr = inet->inet_daddr;
74340+ sig->gr_sport = inet->inet_sport;
74341+ sig->gr_dport = inet->inet_dport;
74342+ gr_add_to_task_ip_table_nolock(sig, newent);
74343+ spin_unlock(&gr_conn_table_lock);
74344+#endif
74345+ return;
74346+}
74347+
74348+void gr_del_task_from_ip_table(struct task_struct *task)
74349+{
74350+#ifdef CONFIG_GRKERNSEC
74351+ spin_lock_bh(&gr_conn_table_lock);
74352+ gr_del_task_from_ip_table_nolock(task->signal);
74353+ spin_unlock_bh(&gr_conn_table_lock);
74354+#endif
74355+ return;
74356+}
74357+
74358+void
74359+gr_attach_curr_ip(const struct sock *sk)
74360+{
74361+#ifdef CONFIG_GRKERNSEC
74362+ struct signal_struct *p, *set;
74363+ const struct inet_sock *inet = inet_sk(sk);
74364+
74365+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
74366+ return;
74367+
74368+ set = current->signal;
74369+
74370+ spin_lock_bh(&gr_conn_table_lock);
74371+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
74372+ inet->inet_dport, inet->inet_sport);
74373+ if (unlikely(p != NULL)) {
74374+ set->curr_ip = p->curr_ip;
74375+ set->used_accept = 1;
74376+ gr_del_task_from_ip_table_nolock(p);
74377+ spin_unlock_bh(&gr_conn_table_lock);
74378+ return;
74379+ }
74380+ spin_unlock_bh(&gr_conn_table_lock);
74381+
74382+ set->curr_ip = inet->inet_daddr;
74383+ set->used_accept = 1;
74384+#endif
74385+ return;
74386+}
74387+
74388+int
74389+gr_handle_sock_all(const int family, const int type, const int protocol)
74390+{
74391+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74392+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
74393+ (family != AF_UNIX)) {
74394+ if (family == AF_INET)
74395+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
74396+ else
74397+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
74398+ return -EACCES;
74399+ }
74400+#endif
74401+ return 0;
74402+}
74403+
74404+int
74405+gr_handle_sock_server(const struct sockaddr *sck)
74406+{
74407+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74408+ if (grsec_enable_socket_server &&
74409+ in_group_p(grsec_socket_server_gid) &&
74410+ sck && (sck->sa_family != AF_UNIX) &&
74411+ (sck->sa_family != AF_LOCAL)) {
74412+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
74413+ return -EACCES;
74414+ }
74415+#endif
74416+ return 0;
74417+}
74418+
74419+int
74420+gr_handle_sock_server_other(const struct sock *sck)
74421+{
74422+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74423+ if (grsec_enable_socket_server &&
74424+ in_group_p(grsec_socket_server_gid) &&
74425+ sck && (sck->sk_family != AF_UNIX) &&
74426+ (sck->sk_family != AF_LOCAL)) {
74427+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
74428+ return -EACCES;
74429+ }
74430+#endif
74431+ return 0;
74432+}
74433+
74434+int
74435+gr_handle_sock_client(const struct sockaddr *sck)
74436+{
74437+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74438+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
74439+ sck && (sck->sa_family != AF_UNIX) &&
74440+ (sck->sa_family != AF_LOCAL)) {
74441+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
74442+ return -EACCES;
74443+ }
74444+#endif
74445+ return 0;
74446+}
74447diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
74448new file mode 100644
74449index 0000000..8159888
74450--- /dev/null
74451+++ b/grsecurity/grsec_sysctl.c
74452@@ -0,0 +1,479 @@
74453+#include <linux/kernel.h>
74454+#include <linux/sched.h>
74455+#include <linux/sysctl.h>
74456+#include <linux/grsecurity.h>
74457+#include <linux/grinternal.h>
74458+
74459+int
74460+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
74461+{
74462+#ifdef CONFIG_GRKERNSEC_SYSCTL
74463+ if (dirname == NULL || name == NULL)
74464+ return 0;
74465+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
74466+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
74467+ return -EACCES;
74468+ }
74469+#endif
74470+ return 0;
74471+}
74472+
74473+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
74474+static int __maybe_unused __read_only one = 1;
74475+#endif
74476+
74477+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
74478+ defined(CONFIG_GRKERNSEC_DENYUSB)
74479+struct ctl_table grsecurity_table[] = {
74480+#ifdef CONFIG_GRKERNSEC_SYSCTL
74481+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
74482+#ifdef CONFIG_GRKERNSEC_IO
74483+ {
74484+ .procname = "disable_priv_io",
74485+ .data = &grsec_disable_privio,
74486+ .maxlen = sizeof(int),
74487+ .mode = 0600,
74488+ .proc_handler = &proc_dointvec,
74489+ },
74490+#endif
74491+#endif
74492+#ifdef CONFIG_GRKERNSEC_LINK
74493+ {
74494+ .procname = "linking_restrictions",
74495+ .data = &grsec_enable_link,
74496+ .maxlen = sizeof(int),
74497+ .mode = 0600,
74498+ .proc_handler = &proc_dointvec,
74499+ },
74500+#endif
74501+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74502+ {
74503+ .procname = "enforce_symlinksifowner",
74504+ .data = &grsec_enable_symlinkown,
74505+ .maxlen = sizeof(int),
74506+ .mode = 0600,
74507+ .proc_handler = &proc_dointvec,
74508+ },
74509+ {
74510+ .procname = "symlinkown_gid",
74511+ .data = &grsec_symlinkown_gid,
74512+ .maxlen = sizeof(int),
74513+ .mode = 0600,
74514+ .proc_handler = &proc_dointvec,
74515+ },
74516+#endif
74517+#ifdef CONFIG_GRKERNSEC_BRUTE
74518+ {
74519+ .procname = "deter_bruteforce",
74520+ .data = &grsec_enable_brute,
74521+ .maxlen = sizeof(int),
74522+ .mode = 0600,
74523+ .proc_handler = &proc_dointvec,
74524+ },
74525+#endif
74526+#ifdef CONFIG_GRKERNSEC_FIFO
74527+ {
74528+ .procname = "fifo_restrictions",
74529+ .data = &grsec_enable_fifo,
74530+ .maxlen = sizeof(int),
74531+ .mode = 0600,
74532+ .proc_handler = &proc_dointvec,
74533+ },
74534+#endif
74535+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74536+ {
74537+ .procname = "ptrace_readexec",
74538+ .data = &grsec_enable_ptrace_readexec,
74539+ .maxlen = sizeof(int),
74540+ .mode = 0600,
74541+ .proc_handler = &proc_dointvec,
74542+ },
74543+#endif
74544+#ifdef CONFIG_GRKERNSEC_SETXID
74545+ {
74546+ .procname = "consistent_setxid",
74547+ .data = &grsec_enable_setxid,
74548+ .maxlen = sizeof(int),
74549+ .mode = 0600,
74550+ .proc_handler = &proc_dointvec,
74551+ },
74552+#endif
74553+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74554+ {
74555+ .procname = "ip_blackhole",
74556+ .data = &grsec_enable_blackhole,
74557+ .maxlen = sizeof(int),
74558+ .mode = 0600,
74559+ .proc_handler = &proc_dointvec,
74560+ },
74561+ {
74562+ .procname = "lastack_retries",
74563+ .data = &grsec_lastack_retries,
74564+ .maxlen = sizeof(int),
74565+ .mode = 0600,
74566+ .proc_handler = &proc_dointvec,
74567+ },
74568+#endif
74569+#ifdef CONFIG_GRKERNSEC_EXECLOG
74570+ {
74571+ .procname = "exec_logging",
74572+ .data = &grsec_enable_execlog,
74573+ .maxlen = sizeof(int),
74574+ .mode = 0600,
74575+ .proc_handler = &proc_dointvec,
74576+ },
74577+#endif
74578+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74579+ {
74580+ .procname = "rwxmap_logging",
74581+ .data = &grsec_enable_log_rwxmaps,
74582+ .maxlen = sizeof(int),
74583+ .mode = 0600,
74584+ .proc_handler = &proc_dointvec,
74585+ },
74586+#endif
74587+#ifdef CONFIG_GRKERNSEC_SIGNAL
74588+ {
74589+ .procname = "signal_logging",
74590+ .data = &grsec_enable_signal,
74591+ .maxlen = sizeof(int),
74592+ .mode = 0600,
74593+ .proc_handler = &proc_dointvec,
74594+ },
74595+#endif
74596+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74597+ {
74598+ .procname = "forkfail_logging",
74599+ .data = &grsec_enable_forkfail,
74600+ .maxlen = sizeof(int),
74601+ .mode = 0600,
74602+ .proc_handler = &proc_dointvec,
74603+ },
74604+#endif
74605+#ifdef CONFIG_GRKERNSEC_TIME
74606+ {
74607+ .procname = "timechange_logging",
74608+ .data = &grsec_enable_time,
74609+ .maxlen = sizeof(int),
74610+ .mode = 0600,
74611+ .proc_handler = &proc_dointvec,
74612+ },
74613+#endif
74614+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74615+ {
74616+ .procname = "chroot_deny_shmat",
74617+ .data = &grsec_enable_chroot_shmat,
74618+ .maxlen = sizeof(int),
74619+ .mode = 0600,
74620+ .proc_handler = &proc_dointvec,
74621+ },
74622+#endif
74623+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74624+ {
74625+ .procname = "chroot_deny_unix",
74626+ .data = &grsec_enable_chroot_unix,
74627+ .maxlen = sizeof(int),
74628+ .mode = 0600,
74629+ .proc_handler = &proc_dointvec,
74630+ },
74631+#endif
74632+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74633+ {
74634+ .procname = "chroot_deny_mount",
74635+ .data = &grsec_enable_chroot_mount,
74636+ .maxlen = sizeof(int),
74637+ .mode = 0600,
74638+ .proc_handler = &proc_dointvec,
74639+ },
74640+#endif
74641+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74642+ {
74643+ .procname = "chroot_deny_fchdir",
74644+ .data = &grsec_enable_chroot_fchdir,
74645+ .maxlen = sizeof(int),
74646+ .mode = 0600,
74647+ .proc_handler = &proc_dointvec,
74648+ },
74649+#endif
74650+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74651+ {
74652+ .procname = "chroot_deny_chroot",
74653+ .data = &grsec_enable_chroot_double,
74654+ .maxlen = sizeof(int),
74655+ .mode = 0600,
74656+ .proc_handler = &proc_dointvec,
74657+ },
74658+#endif
74659+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74660+ {
74661+ .procname = "chroot_deny_pivot",
74662+ .data = &grsec_enable_chroot_pivot,
74663+ .maxlen = sizeof(int),
74664+ .mode = 0600,
74665+ .proc_handler = &proc_dointvec,
74666+ },
74667+#endif
74668+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74669+ {
74670+ .procname = "chroot_enforce_chdir",
74671+ .data = &grsec_enable_chroot_chdir,
74672+ .maxlen = sizeof(int),
74673+ .mode = 0600,
74674+ .proc_handler = &proc_dointvec,
74675+ },
74676+#endif
74677+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74678+ {
74679+ .procname = "chroot_deny_chmod",
74680+ .data = &grsec_enable_chroot_chmod,
74681+ .maxlen = sizeof(int),
74682+ .mode = 0600,
74683+ .proc_handler = &proc_dointvec,
74684+ },
74685+#endif
74686+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74687+ {
74688+ .procname = "chroot_deny_mknod",
74689+ .data = &grsec_enable_chroot_mknod,
74690+ .maxlen = sizeof(int),
74691+ .mode = 0600,
74692+ .proc_handler = &proc_dointvec,
74693+ },
74694+#endif
74695+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74696+ {
74697+ .procname = "chroot_restrict_nice",
74698+ .data = &grsec_enable_chroot_nice,
74699+ .maxlen = sizeof(int),
74700+ .mode = 0600,
74701+ .proc_handler = &proc_dointvec,
74702+ },
74703+#endif
74704+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74705+ {
74706+ .procname = "chroot_execlog",
74707+ .data = &grsec_enable_chroot_execlog,
74708+ .maxlen = sizeof(int),
74709+ .mode = 0600,
74710+ .proc_handler = &proc_dointvec,
74711+ },
74712+#endif
74713+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74714+ {
74715+ .procname = "chroot_caps",
74716+ .data = &grsec_enable_chroot_caps,
74717+ .maxlen = sizeof(int),
74718+ .mode = 0600,
74719+ .proc_handler = &proc_dointvec,
74720+ },
74721+#endif
74722+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74723+ {
74724+ .procname = "chroot_deny_sysctl",
74725+ .data = &grsec_enable_chroot_sysctl,
74726+ .maxlen = sizeof(int),
74727+ .mode = 0600,
74728+ .proc_handler = &proc_dointvec,
74729+ },
74730+#endif
74731+#ifdef CONFIG_GRKERNSEC_TPE
74732+ {
74733+ .procname = "tpe",
74734+ .data = &grsec_enable_tpe,
74735+ .maxlen = sizeof(int),
74736+ .mode = 0600,
74737+ .proc_handler = &proc_dointvec,
74738+ },
74739+ {
74740+ .procname = "tpe_gid",
74741+ .data = &grsec_tpe_gid,
74742+ .maxlen = sizeof(int),
74743+ .mode = 0600,
74744+ .proc_handler = &proc_dointvec,
74745+ },
74746+#endif
74747+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74748+ {
74749+ .procname = "tpe_invert",
74750+ .data = &grsec_enable_tpe_invert,
74751+ .maxlen = sizeof(int),
74752+ .mode = 0600,
74753+ .proc_handler = &proc_dointvec,
74754+ },
74755+#endif
74756+#ifdef CONFIG_GRKERNSEC_TPE_ALL
74757+ {
74758+ .procname = "tpe_restrict_all",
74759+ .data = &grsec_enable_tpe_all,
74760+ .maxlen = sizeof(int),
74761+ .mode = 0600,
74762+ .proc_handler = &proc_dointvec,
74763+ },
74764+#endif
74765+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74766+ {
74767+ .procname = "socket_all",
74768+ .data = &grsec_enable_socket_all,
74769+ .maxlen = sizeof(int),
74770+ .mode = 0600,
74771+ .proc_handler = &proc_dointvec,
74772+ },
74773+ {
74774+ .procname = "socket_all_gid",
74775+ .data = &grsec_socket_all_gid,
74776+ .maxlen = sizeof(int),
74777+ .mode = 0600,
74778+ .proc_handler = &proc_dointvec,
74779+ },
74780+#endif
74781+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74782+ {
74783+ .procname = "socket_client",
74784+ .data = &grsec_enable_socket_client,
74785+ .maxlen = sizeof(int),
74786+ .mode = 0600,
74787+ .proc_handler = &proc_dointvec,
74788+ },
74789+ {
74790+ .procname = "socket_client_gid",
74791+ .data = &grsec_socket_client_gid,
74792+ .maxlen = sizeof(int),
74793+ .mode = 0600,
74794+ .proc_handler = &proc_dointvec,
74795+ },
74796+#endif
74797+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74798+ {
74799+ .procname = "socket_server",
74800+ .data = &grsec_enable_socket_server,
74801+ .maxlen = sizeof(int),
74802+ .mode = 0600,
74803+ .proc_handler = &proc_dointvec,
74804+ },
74805+ {
74806+ .procname = "socket_server_gid",
74807+ .data = &grsec_socket_server_gid,
74808+ .maxlen = sizeof(int),
74809+ .mode = 0600,
74810+ .proc_handler = &proc_dointvec,
74811+ },
74812+#endif
74813+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74814+ {
74815+ .procname = "audit_group",
74816+ .data = &grsec_enable_group,
74817+ .maxlen = sizeof(int),
74818+ .mode = 0600,
74819+ .proc_handler = &proc_dointvec,
74820+ },
74821+ {
74822+ .procname = "audit_gid",
74823+ .data = &grsec_audit_gid,
74824+ .maxlen = sizeof(int),
74825+ .mode = 0600,
74826+ .proc_handler = &proc_dointvec,
74827+ },
74828+#endif
74829+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74830+ {
74831+ .procname = "audit_chdir",
74832+ .data = &grsec_enable_chdir,
74833+ .maxlen = sizeof(int),
74834+ .mode = 0600,
74835+ .proc_handler = &proc_dointvec,
74836+ },
74837+#endif
74838+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74839+ {
74840+ .procname = "audit_mount",
74841+ .data = &grsec_enable_mount,
74842+ .maxlen = sizeof(int),
74843+ .mode = 0600,
74844+ .proc_handler = &proc_dointvec,
74845+ },
74846+#endif
74847+#ifdef CONFIG_GRKERNSEC_DMESG
74848+ {
74849+ .procname = "dmesg",
74850+ .data = &grsec_enable_dmesg,
74851+ .maxlen = sizeof(int),
74852+ .mode = 0600,
74853+ .proc_handler = &proc_dointvec,
74854+ },
74855+#endif
74856+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74857+ {
74858+ .procname = "chroot_findtask",
74859+ .data = &grsec_enable_chroot_findtask,
74860+ .maxlen = sizeof(int),
74861+ .mode = 0600,
74862+ .proc_handler = &proc_dointvec,
74863+ },
74864+#endif
74865+#ifdef CONFIG_GRKERNSEC_RESLOG
74866+ {
74867+ .procname = "resource_logging",
74868+ .data = &grsec_resource_logging,
74869+ .maxlen = sizeof(int),
74870+ .mode = 0600,
74871+ .proc_handler = &proc_dointvec,
74872+ },
74873+#endif
74874+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74875+ {
74876+ .procname = "audit_ptrace",
74877+ .data = &grsec_enable_audit_ptrace,
74878+ .maxlen = sizeof(int),
74879+ .mode = 0600,
74880+ .proc_handler = &proc_dointvec,
74881+ },
74882+#endif
74883+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74884+ {
74885+ .procname = "harden_ptrace",
74886+ .data = &grsec_enable_harden_ptrace,
74887+ .maxlen = sizeof(int),
74888+ .mode = 0600,
74889+ .proc_handler = &proc_dointvec,
74890+ },
74891+#endif
74892+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74893+ {
74894+ .procname = "harden_ipc",
74895+ .data = &grsec_enable_harden_ipc,
74896+ .maxlen = sizeof(int),
74897+ .mode = 0600,
74898+ .proc_handler = &proc_dointvec,
74899+ },
74900+#endif
74901+ {
74902+ .procname = "grsec_lock",
74903+ .data = &grsec_lock,
74904+ .maxlen = sizeof(int),
74905+ .mode = 0600,
74906+ .proc_handler = &proc_dointvec,
74907+ },
74908+#endif
74909+#ifdef CONFIG_GRKERNSEC_ROFS
74910+ {
74911+ .procname = "romount_protect",
74912+ .data = &grsec_enable_rofs,
74913+ .maxlen = sizeof(int),
74914+ .mode = 0600,
74915+ .proc_handler = &proc_dointvec_minmax,
74916+ .extra1 = &one,
74917+ .extra2 = &one,
74918+ },
74919+#endif
74920+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
74921+ {
74922+ .procname = "deny_new_usb",
74923+ .data = &grsec_deny_new_usb,
74924+ .maxlen = sizeof(int),
74925+ .mode = 0600,
74926+ .proc_handler = &proc_dointvec,
74927+ },
74928+#endif
74929+ { }
74930+};
74931+#endif
74932diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
74933new file mode 100644
74934index 0000000..0dc13c3
74935--- /dev/null
74936+++ b/grsecurity/grsec_time.c
74937@@ -0,0 +1,16 @@
74938+#include <linux/kernel.h>
74939+#include <linux/sched.h>
74940+#include <linux/grinternal.h>
74941+#include <linux/module.h>
74942+
74943+void
74944+gr_log_timechange(void)
74945+{
74946+#ifdef CONFIG_GRKERNSEC_TIME
74947+ if (grsec_enable_time)
74948+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
74949+#endif
74950+ return;
74951+}
74952+
74953+EXPORT_SYMBOL(gr_log_timechange);
74954diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
74955new file mode 100644
74956index 0000000..ee57dcf
74957--- /dev/null
74958+++ b/grsecurity/grsec_tpe.c
74959@@ -0,0 +1,73 @@
74960+#include <linux/kernel.h>
74961+#include <linux/sched.h>
74962+#include <linux/file.h>
74963+#include <linux/fs.h>
74964+#include <linux/grinternal.h>
74965+
74966+extern int gr_acl_tpe_check(void);
74967+
74968+int
74969+gr_tpe_allow(const struct file *file)
74970+{
74971+#ifdef CONFIG_GRKERNSEC
74972+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
74973+ const struct cred *cred = current_cred();
74974+ char *msg = NULL;
74975+ char *msg2 = NULL;
74976+
74977+ // never restrict root
74978+ if (gr_is_global_root(cred->uid))
74979+ return 1;
74980+
74981+ if (grsec_enable_tpe) {
74982+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74983+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
74984+ msg = "not being in trusted group";
74985+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
74986+ msg = "being in untrusted group";
74987+#else
74988+ if (in_group_p(grsec_tpe_gid))
74989+ msg = "being in untrusted group";
74990+#endif
74991+ }
74992+ if (!msg && gr_acl_tpe_check())
74993+ msg = "being in untrusted role";
74994+
74995+ // not in any affected group/role
74996+ if (!msg)
74997+ goto next_check;
74998+
74999+ if (gr_is_global_nonroot(inode->i_uid))
75000+ msg2 = "file in non-root-owned directory";
75001+ else if (inode->i_mode & S_IWOTH)
75002+ msg2 = "file in world-writable directory";
75003+ else if (inode->i_mode & S_IWGRP)
75004+ msg2 = "file in group-writable directory";
75005+
75006+ if (msg && msg2) {
75007+ char fullmsg[70] = {0};
75008+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
75009+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
75010+ return 0;
75011+ }
75012+ msg = NULL;
75013+next_check:
75014+#ifdef CONFIG_GRKERNSEC_TPE_ALL
75015+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
75016+ return 1;
75017+
75018+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
75019+ msg = "directory not owned by user";
75020+ else if (inode->i_mode & S_IWOTH)
75021+ msg = "file in world-writable directory";
75022+ else if (inode->i_mode & S_IWGRP)
75023+ msg = "file in group-writable directory";
75024+
75025+ if (msg) {
75026+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
75027+ return 0;
75028+ }
75029+#endif
75030+#endif
75031+ return 1;
75032+}
75033diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
75034new file mode 100644
75035index 0000000..ae02d8e
75036--- /dev/null
75037+++ b/grsecurity/grsec_usb.c
75038@@ -0,0 +1,15 @@
75039+#include <linux/kernel.h>
75040+#include <linux/grinternal.h>
75041+#include <linux/module.h>
75042+
75043+int gr_handle_new_usb(void)
75044+{
75045+#ifdef CONFIG_GRKERNSEC_DENYUSB
75046+ if (grsec_deny_new_usb) {
75047+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
75048+ return 1;
75049+ }
75050+#endif
75051+ return 0;
75052+}
75053+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
75054diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
75055new file mode 100644
75056index 0000000..9f7b1ac
75057--- /dev/null
75058+++ b/grsecurity/grsum.c
75059@@ -0,0 +1,61 @@
75060+#include <linux/err.h>
75061+#include <linux/kernel.h>
75062+#include <linux/sched.h>
75063+#include <linux/mm.h>
75064+#include <linux/scatterlist.h>
75065+#include <linux/crypto.h>
75066+#include <linux/gracl.h>
75067+
75068+
75069+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
75070+#error "crypto and sha256 must be built into the kernel"
75071+#endif
75072+
75073+int
75074+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
75075+{
75076+ char *p;
75077+ struct crypto_hash *tfm;
75078+ struct hash_desc desc;
75079+ struct scatterlist sg;
75080+ unsigned char temp_sum[GR_SHA_LEN];
75081+ volatile int retval = 0;
75082+ volatile int dummy = 0;
75083+ unsigned int i;
75084+
75085+ sg_init_table(&sg, 1);
75086+
75087+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
75088+ if (IS_ERR(tfm)) {
75089+ /* should never happen, since sha256 should be built in */
75090+ return 1;
75091+ }
75092+
75093+ desc.tfm = tfm;
75094+ desc.flags = 0;
75095+
75096+ crypto_hash_init(&desc);
75097+
75098+ p = salt;
75099+ sg_set_buf(&sg, p, GR_SALT_LEN);
75100+ crypto_hash_update(&desc, &sg, sg.length);
75101+
75102+ p = entry->pw;
75103+ sg_set_buf(&sg, p, strlen(p));
75104+
75105+ crypto_hash_update(&desc, &sg, sg.length);
75106+
75107+ crypto_hash_final(&desc, temp_sum);
75108+
75109+ memset(entry->pw, 0, GR_PW_LEN);
75110+
75111+ for (i = 0; i < GR_SHA_LEN; i++)
75112+ if (sum[i] != temp_sum[i])
75113+ retval = 1;
75114+ else
75115+ dummy = 1; // waste a cycle
75116+
75117+ crypto_free_hash(tfm);
75118+
75119+ return retval;
75120+}
75121diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
75122index 77ff547..181834f 100644
75123--- a/include/asm-generic/4level-fixup.h
75124+++ b/include/asm-generic/4level-fixup.h
75125@@ -13,8 +13,10 @@
75126 #define pmd_alloc(mm, pud, address) \
75127 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
75128 NULL: pmd_offset(pud, address))
75129+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
75130
75131 #define pud_alloc(mm, pgd, address) (pgd)
75132+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
75133 #define pud_offset(pgd, start) (pgd)
75134 #define pud_none(pud) 0
75135 #define pud_bad(pud) 0
75136diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
75137index b7babf0..97f4c4f 100644
75138--- a/include/asm-generic/atomic-long.h
75139+++ b/include/asm-generic/atomic-long.h
75140@@ -22,6 +22,12 @@
75141
75142 typedef atomic64_t atomic_long_t;
75143
75144+#ifdef CONFIG_PAX_REFCOUNT
75145+typedef atomic64_unchecked_t atomic_long_unchecked_t;
75146+#else
75147+typedef atomic64_t atomic_long_unchecked_t;
75148+#endif
75149+
75150 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
75151
75152 static inline long atomic_long_read(atomic_long_t *l)
75153@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
75154 return (long)atomic64_read(v);
75155 }
75156
75157+#ifdef CONFIG_PAX_REFCOUNT
75158+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
75159+{
75160+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75161+
75162+ return (long)atomic64_read_unchecked(v);
75163+}
75164+#endif
75165+
75166 static inline void atomic_long_set(atomic_long_t *l, long i)
75167 {
75168 atomic64_t *v = (atomic64_t *)l;
75169@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
75170 atomic64_set(v, i);
75171 }
75172
75173+#ifdef CONFIG_PAX_REFCOUNT
75174+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
75175+{
75176+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75177+
75178+ atomic64_set_unchecked(v, i);
75179+}
75180+#endif
75181+
75182 static inline void atomic_long_inc(atomic_long_t *l)
75183 {
75184 atomic64_t *v = (atomic64_t *)l;
75185@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
75186 atomic64_inc(v);
75187 }
75188
75189+#ifdef CONFIG_PAX_REFCOUNT
75190+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
75191+{
75192+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75193+
75194+ atomic64_inc_unchecked(v);
75195+}
75196+#endif
75197+
75198 static inline void atomic_long_dec(atomic_long_t *l)
75199 {
75200 atomic64_t *v = (atomic64_t *)l;
75201@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
75202 atomic64_dec(v);
75203 }
75204
75205+#ifdef CONFIG_PAX_REFCOUNT
75206+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
75207+{
75208+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75209+
75210+ atomic64_dec_unchecked(v);
75211+}
75212+#endif
75213+
75214 static inline void atomic_long_add(long i, atomic_long_t *l)
75215 {
75216 atomic64_t *v = (atomic64_t *)l;
75217@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
75218 atomic64_add(i, v);
75219 }
75220
75221+#ifdef CONFIG_PAX_REFCOUNT
75222+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
75223+{
75224+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75225+
75226+ atomic64_add_unchecked(i, v);
75227+}
75228+#endif
75229+
75230 static inline void atomic_long_sub(long i, atomic_long_t *l)
75231 {
75232 atomic64_t *v = (atomic64_t *)l;
75233@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
75234 atomic64_sub(i, v);
75235 }
75236
75237+#ifdef CONFIG_PAX_REFCOUNT
75238+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
75239+{
75240+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75241+
75242+ atomic64_sub_unchecked(i, v);
75243+}
75244+#endif
75245+
75246 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
75247 {
75248 atomic64_t *v = (atomic64_t *)l;
75249@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
75250 return atomic64_add_negative(i, v);
75251 }
75252
75253-static inline long atomic_long_add_return(long i, atomic_long_t *l)
75254+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
75255 {
75256 atomic64_t *v = (atomic64_t *)l;
75257
75258 return (long)atomic64_add_return(i, v);
75259 }
75260
75261+#ifdef CONFIG_PAX_REFCOUNT
75262+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
75263+{
75264+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75265+
75266+ return (long)atomic64_add_return_unchecked(i, v);
75267+}
75268+#endif
75269+
75270 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
75271 {
75272 atomic64_t *v = (atomic64_t *)l;
75273@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
75274 return (long)atomic64_inc_return(v);
75275 }
75276
75277+#ifdef CONFIG_PAX_REFCOUNT
75278+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
75279+{
75280+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75281+
75282+ return (long)atomic64_inc_return_unchecked(v);
75283+}
75284+#endif
75285+
75286 static inline long atomic_long_dec_return(atomic_long_t *l)
75287 {
75288 atomic64_t *v = (atomic64_t *)l;
75289@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
75290
75291 typedef atomic_t atomic_long_t;
75292
75293+#ifdef CONFIG_PAX_REFCOUNT
75294+typedef atomic_unchecked_t atomic_long_unchecked_t;
75295+#else
75296+typedef atomic_t atomic_long_unchecked_t;
75297+#endif
75298+
75299 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
75300 static inline long atomic_long_read(atomic_long_t *l)
75301 {
75302@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
75303 return (long)atomic_read(v);
75304 }
75305
75306+#ifdef CONFIG_PAX_REFCOUNT
75307+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
75308+{
75309+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75310+
75311+ return (long)atomic_read_unchecked(v);
75312+}
75313+#endif
75314+
75315 static inline void atomic_long_set(atomic_long_t *l, long i)
75316 {
75317 atomic_t *v = (atomic_t *)l;
75318@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
75319 atomic_set(v, i);
75320 }
75321
75322+#ifdef CONFIG_PAX_REFCOUNT
75323+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
75324+{
75325+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75326+
75327+ atomic_set_unchecked(v, i);
75328+}
75329+#endif
75330+
75331 static inline void atomic_long_inc(atomic_long_t *l)
75332 {
75333 atomic_t *v = (atomic_t *)l;
75334@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
75335 atomic_inc(v);
75336 }
75337
75338+#ifdef CONFIG_PAX_REFCOUNT
75339+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
75340+{
75341+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75342+
75343+ atomic_inc_unchecked(v);
75344+}
75345+#endif
75346+
75347 static inline void atomic_long_dec(atomic_long_t *l)
75348 {
75349 atomic_t *v = (atomic_t *)l;
75350@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
75351 atomic_dec(v);
75352 }
75353
75354+#ifdef CONFIG_PAX_REFCOUNT
75355+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
75356+{
75357+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75358+
75359+ atomic_dec_unchecked(v);
75360+}
75361+#endif
75362+
75363 static inline void atomic_long_add(long i, atomic_long_t *l)
75364 {
75365 atomic_t *v = (atomic_t *)l;
75366@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
75367 atomic_add(i, v);
75368 }
75369
75370+#ifdef CONFIG_PAX_REFCOUNT
75371+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
75372+{
75373+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75374+
75375+ atomic_add_unchecked(i, v);
75376+}
75377+#endif
75378+
75379 static inline void atomic_long_sub(long i, atomic_long_t *l)
75380 {
75381 atomic_t *v = (atomic_t *)l;
75382@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
75383 atomic_sub(i, v);
75384 }
75385
75386+#ifdef CONFIG_PAX_REFCOUNT
75387+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
75388+{
75389+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75390+
75391+ atomic_sub_unchecked(i, v);
75392+}
75393+#endif
75394+
75395 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
75396 {
75397 atomic_t *v = (atomic_t *)l;
75398@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
75399 return (long)atomic_add_return(i, v);
75400 }
75401
75402+#ifdef CONFIG_PAX_REFCOUNT
75403+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
75404+{
75405+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75406+
75407+ return (long)atomic_add_return_unchecked(i, v);
75408+}
75409+
75410+#endif
75411+
75412 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
75413 {
75414 atomic_t *v = (atomic_t *)l;
75415@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
75416 return (long)atomic_inc_return(v);
75417 }
75418
75419+#ifdef CONFIG_PAX_REFCOUNT
75420+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
75421+{
75422+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75423+
75424+ return (long)atomic_inc_return_unchecked(v);
75425+}
75426+#endif
75427+
75428 static inline long atomic_long_dec_return(atomic_long_t *l)
75429 {
75430 atomic_t *v = (atomic_t *)l;
75431@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
75432
75433 #endif /* BITS_PER_LONG == 64 */
75434
75435+#ifdef CONFIG_PAX_REFCOUNT
75436+static inline void pax_refcount_needs_these_functions(void)
75437+{
75438+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
75439+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
75440+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
75441+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
75442+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
75443+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
75444+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
75445+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
75446+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
75447+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
75448+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
75449+#ifdef CONFIG_X86
75450+ atomic_clear_mask_unchecked(0, NULL);
75451+ atomic_set_mask_unchecked(0, NULL);
75452+#endif
75453+
75454+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
75455+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
75456+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
75457+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
75458+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
75459+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
75460+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
75461+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
75462+}
75463+#else
75464+#define atomic_read_unchecked(v) atomic_read(v)
75465+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
75466+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
75467+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
75468+#define atomic_inc_unchecked(v) atomic_inc(v)
75469+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
75470+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
75471+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
75472+#define atomic_dec_unchecked(v) atomic_dec(v)
75473+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
75474+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
75475+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
75476+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
75477+
75478+#define atomic_long_read_unchecked(v) atomic_long_read(v)
75479+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
75480+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
75481+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
75482+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
75483+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
75484+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
75485+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
75486+#endif
75487+
75488 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
75489diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
75490index 33bd2de..f31bff97 100644
75491--- a/include/asm-generic/atomic.h
75492+++ b/include/asm-generic/atomic.h
75493@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
75494 * Atomically clears the bits set in @mask from @v
75495 */
75496 #ifndef atomic_clear_mask
75497-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
75498+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
75499 {
75500 unsigned long flags;
75501
75502diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
75503index b18ce4f..2ee2843 100644
75504--- a/include/asm-generic/atomic64.h
75505+++ b/include/asm-generic/atomic64.h
75506@@ -16,6 +16,8 @@ typedef struct {
75507 long long counter;
75508 } atomic64_t;
75509
75510+typedef atomic64_t atomic64_unchecked_t;
75511+
75512 #define ATOMIC64_INIT(i) { (i) }
75513
75514 extern long long atomic64_read(const atomic64_t *v);
75515@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
75516 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
75517 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
75518
75519+#define atomic64_read_unchecked(v) atomic64_read(v)
75520+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
75521+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
75522+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
75523+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
75524+#define atomic64_inc_unchecked(v) atomic64_inc(v)
75525+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
75526+#define atomic64_dec_unchecked(v) atomic64_dec(v)
75527+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
75528+
75529 #endif /* _ASM_GENERIC_ATOMIC64_H */
75530diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
75531index a60a7cc..0fe12f2 100644
75532--- a/include/asm-generic/bitops/__fls.h
75533+++ b/include/asm-generic/bitops/__fls.h
75534@@ -9,7 +9,7 @@
75535 *
75536 * Undefined if no set bit exists, so code should check against 0 first.
75537 */
75538-static __always_inline unsigned long __fls(unsigned long word)
75539+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
75540 {
75541 int num = BITS_PER_LONG - 1;
75542
75543diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
75544index 0576d1f..dad6c71 100644
75545--- a/include/asm-generic/bitops/fls.h
75546+++ b/include/asm-generic/bitops/fls.h
75547@@ -9,7 +9,7 @@
75548 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
75549 */
75550
75551-static __always_inline int fls(int x)
75552+static __always_inline int __intentional_overflow(-1) fls(int x)
75553 {
75554 int r = 32;
75555
75556diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
75557index b097cf8..3d40e14 100644
75558--- a/include/asm-generic/bitops/fls64.h
75559+++ b/include/asm-generic/bitops/fls64.h
75560@@ -15,7 +15,7 @@
75561 * at position 64.
75562 */
75563 #if BITS_PER_LONG == 32
75564-static __always_inline int fls64(__u64 x)
75565+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
75566 {
75567 __u32 h = x >> 32;
75568 if (h)
75569@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
75570 return fls(x);
75571 }
75572 #elif BITS_PER_LONG == 64
75573-static __always_inline int fls64(__u64 x)
75574+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
75575 {
75576 if (x == 0)
75577 return 0;
75578diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
75579index 1bfcfe5..e04c5c9 100644
75580--- a/include/asm-generic/cache.h
75581+++ b/include/asm-generic/cache.h
75582@@ -6,7 +6,7 @@
75583 * cache lines need to provide their own cache.h.
75584 */
75585
75586-#define L1_CACHE_SHIFT 5
75587-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
75588+#define L1_CACHE_SHIFT 5UL
75589+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
75590
75591 #endif /* __ASM_GENERIC_CACHE_H */
75592diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
75593index 0d68a1e..b74a761 100644
75594--- a/include/asm-generic/emergency-restart.h
75595+++ b/include/asm-generic/emergency-restart.h
75596@@ -1,7 +1,7 @@
75597 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
75598 #define _ASM_GENERIC_EMERGENCY_RESTART_H
75599
75600-static inline void machine_emergency_restart(void)
75601+static inline __noreturn void machine_emergency_restart(void)
75602 {
75603 machine_restart(NULL);
75604 }
75605diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
75606index 90f99c7..00ce236 100644
75607--- a/include/asm-generic/kmap_types.h
75608+++ b/include/asm-generic/kmap_types.h
75609@@ -2,9 +2,9 @@
75610 #define _ASM_GENERIC_KMAP_TYPES_H
75611
75612 #ifdef __WITH_KM_FENCE
75613-# define KM_TYPE_NR 41
75614+# define KM_TYPE_NR 42
75615 #else
75616-# define KM_TYPE_NR 20
75617+# define KM_TYPE_NR 21
75618 #endif
75619
75620 #endif
75621diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
75622index 9ceb03b..62b0b8f 100644
75623--- a/include/asm-generic/local.h
75624+++ b/include/asm-generic/local.h
75625@@ -23,24 +23,37 @@ typedef struct
75626 atomic_long_t a;
75627 } local_t;
75628
75629+typedef struct {
75630+ atomic_long_unchecked_t a;
75631+} local_unchecked_t;
75632+
75633 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
75634
75635 #define local_read(l) atomic_long_read(&(l)->a)
75636+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
75637 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
75638+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
75639 #define local_inc(l) atomic_long_inc(&(l)->a)
75640+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
75641 #define local_dec(l) atomic_long_dec(&(l)->a)
75642+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
75643 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
75644+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
75645 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
75646+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
75647
75648 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
75649 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
75650 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
75651 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
75652 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
75653+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
75654 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
75655 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
75656+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
75657
75658 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
75659+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
75660 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
75661 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
75662 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
75663diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
75664index 725612b..9cc513a 100644
75665--- a/include/asm-generic/pgtable-nopmd.h
75666+++ b/include/asm-generic/pgtable-nopmd.h
75667@@ -1,14 +1,19 @@
75668 #ifndef _PGTABLE_NOPMD_H
75669 #define _PGTABLE_NOPMD_H
75670
75671-#ifndef __ASSEMBLY__
75672-
75673 #include <asm-generic/pgtable-nopud.h>
75674
75675-struct mm_struct;
75676-
75677 #define __PAGETABLE_PMD_FOLDED
75678
75679+#define PMD_SHIFT PUD_SHIFT
75680+#define PTRS_PER_PMD 1
75681+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
75682+#define PMD_MASK (~(PMD_SIZE-1))
75683+
75684+#ifndef __ASSEMBLY__
75685+
75686+struct mm_struct;
75687+
75688 /*
75689 * Having the pmd type consist of a pud gets the size right, and allows
75690 * us to conceptually access the pud entry that this pmd is folded into
75691@@ -16,11 +21,6 @@ struct mm_struct;
75692 */
75693 typedef struct { pud_t pud; } pmd_t;
75694
75695-#define PMD_SHIFT PUD_SHIFT
75696-#define PTRS_PER_PMD 1
75697-#define PMD_SIZE (1UL << PMD_SHIFT)
75698-#define PMD_MASK (~(PMD_SIZE-1))
75699-
75700 /*
75701 * The "pud_xxx()" functions here are trivial for a folded two-level
75702 * setup: the pmd is never bad, and a pmd always exists (as it's folded
75703diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
75704index 810431d..0ec4804f 100644
75705--- a/include/asm-generic/pgtable-nopud.h
75706+++ b/include/asm-generic/pgtable-nopud.h
75707@@ -1,10 +1,15 @@
75708 #ifndef _PGTABLE_NOPUD_H
75709 #define _PGTABLE_NOPUD_H
75710
75711-#ifndef __ASSEMBLY__
75712-
75713 #define __PAGETABLE_PUD_FOLDED
75714
75715+#define PUD_SHIFT PGDIR_SHIFT
75716+#define PTRS_PER_PUD 1
75717+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
75718+#define PUD_MASK (~(PUD_SIZE-1))
75719+
75720+#ifndef __ASSEMBLY__
75721+
75722 /*
75723 * Having the pud type consist of a pgd gets the size right, and allows
75724 * us to conceptually access the pgd entry that this pud is folded into
75725@@ -12,11 +17,6 @@
75726 */
75727 typedef struct { pgd_t pgd; } pud_t;
75728
75729-#define PUD_SHIFT PGDIR_SHIFT
75730-#define PTRS_PER_PUD 1
75731-#define PUD_SIZE (1UL << PUD_SHIFT)
75732-#define PUD_MASK (~(PUD_SIZE-1))
75733-
75734 /*
75735 * The "pgd_xxx()" functions here are trivial for a folded two-level
75736 * setup: the pud is never bad, and a pud always exists (as it's folded
75737@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
75738 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
75739
75740 #define pgd_populate(mm, pgd, pud) do { } while (0)
75741+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
75742 /*
75743 * (puds are folded into pgds so this doesn't get actually called,
75744 * but the define is needed for a generic inline function.)
75745diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
75746index db09234..86683e3 100644
75747--- a/include/asm-generic/pgtable.h
75748+++ b/include/asm-generic/pgtable.h
75749@@ -736,6 +736,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
75750 }
75751 #endif /* CONFIG_NUMA_BALANCING */
75752
75753+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
75754+#ifdef CONFIG_PAX_KERNEXEC
75755+#error KERNEXEC requires pax_open_kernel
75756+#else
75757+static inline unsigned long pax_open_kernel(void) { return 0; }
75758+#endif
75759+#endif
75760+
75761+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
75762+#ifdef CONFIG_PAX_KERNEXEC
75763+#error KERNEXEC requires pax_close_kernel
75764+#else
75765+static inline unsigned long pax_close_kernel(void) { return 0; }
75766+#endif
75767+#endif
75768+
75769 #endif /* CONFIG_MMU */
75770
75771 #endif /* !__ASSEMBLY__ */
75772diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
75773index dc1269c..48a4f51 100644
75774--- a/include/asm-generic/uaccess.h
75775+++ b/include/asm-generic/uaccess.h
75776@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
75777 return __clear_user(to, n);
75778 }
75779
75780+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
75781+#ifdef CONFIG_PAX_MEMORY_UDEREF
75782+#error UDEREF requires pax_open_userland
75783+#else
75784+static inline unsigned long pax_open_userland(void) { return 0; }
75785+#endif
75786+#endif
75787+
75788+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
75789+#ifdef CONFIG_PAX_MEMORY_UDEREF
75790+#error UDEREF requires pax_close_userland
75791+#else
75792+static inline unsigned long pax_close_userland(void) { return 0; }
75793+#endif
75794+#endif
75795+
75796 #endif /* __ASM_GENERIC_UACCESS_H */
75797diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
75798index bc2121f..2f41f9a 100644
75799--- a/include/asm-generic/vmlinux.lds.h
75800+++ b/include/asm-generic/vmlinux.lds.h
75801@@ -232,6 +232,7 @@
75802 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
75803 VMLINUX_SYMBOL(__start_rodata) = .; \
75804 *(.rodata) *(.rodata.*) \
75805+ *(.data..read_only) \
75806 *(__vermagic) /* Kernel version magic */ \
75807 . = ALIGN(8); \
75808 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
75809@@ -716,17 +717,18 @@
75810 * section in the linker script will go there too. @phdr should have
75811 * a leading colon.
75812 *
75813- * Note that this macros defines __per_cpu_load as an absolute symbol.
75814+ * Note that this macros defines per_cpu_load as an absolute symbol.
75815 * If there is no need to put the percpu section at a predetermined
75816 * address, use PERCPU_SECTION.
75817 */
75818 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
75819- VMLINUX_SYMBOL(__per_cpu_load) = .; \
75820- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
75821+ per_cpu_load = .; \
75822+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
75823 - LOAD_OFFSET) { \
75824+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
75825 PERCPU_INPUT(cacheline) \
75826 } phdr \
75827- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
75828+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
75829
75830 /**
75831 * PERCPU_SECTION - define output section for percpu area, simple version
75832diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
75833index e73c19e..5b89e00 100644
75834--- a/include/crypto/algapi.h
75835+++ b/include/crypto/algapi.h
75836@@ -34,7 +34,7 @@ struct crypto_type {
75837 unsigned int maskclear;
75838 unsigned int maskset;
75839 unsigned int tfmsize;
75840-};
75841+} __do_const;
75842
75843 struct crypto_instance {
75844 struct crypto_alg alg;
75845diff --git a/include/drm/drmP.h b/include/drm/drmP.h
75846index 1d4a920..da65658 100644
75847--- a/include/drm/drmP.h
75848+++ b/include/drm/drmP.h
75849@@ -66,6 +66,7 @@
75850 #include <linux/workqueue.h>
75851 #include <linux/poll.h>
75852 #include <asm/pgalloc.h>
75853+#include <asm/local.h>
75854 #include <drm/drm.h>
75855 #include <drm/drm_sarea.h>
75856 #include <drm/drm_vma_manager.h>
75857@@ -278,10 +279,12 @@ do { \
75858 * \param cmd command.
75859 * \param arg argument.
75860 */
75861-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
75862+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
75863+ struct drm_file *file_priv);
75864+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
75865 struct drm_file *file_priv);
75866
75867-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
75868+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
75869 unsigned long arg);
75870
75871 #define DRM_IOCTL_NR(n) _IOC_NR(n)
75872@@ -297,10 +300,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
75873 struct drm_ioctl_desc {
75874 unsigned int cmd;
75875 int flags;
75876- drm_ioctl_t *func;
75877+ drm_ioctl_t func;
75878 unsigned int cmd_drv;
75879 const char *name;
75880-};
75881+} __do_const;
75882
75883 /**
75884 * Creates a driver or general drm_ioctl_desc array entry for the given
75885@@ -1013,7 +1016,8 @@ struct drm_info_list {
75886 int (*show)(struct seq_file*, void*); /** show callback */
75887 u32 driver_features; /**< Required driver features for this entry */
75888 void *data;
75889-};
75890+} __do_const;
75891+typedef struct drm_info_list __no_const drm_info_list_no_const;
75892
75893 /**
75894 * debugfs node structure. This structure represents a debugfs file.
75895@@ -1097,7 +1101,7 @@ struct drm_device {
75896
75897 /** \name Usage Counters */
75898 /*@{ */
75899- int open_count; /**< Outstanding files open */
75900+ local_t open_count; /**< Outstanding files open */
75901 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
75902 atomic_t vma_count; /**< Outstanding vma areas open */
75903 int buf_use; /**< Buffers in use -- cannot alloc */
75904diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
75905index ef6ad3a..be34b16 100644
75906--- a/include/drm/drm_crtc_helper.h
75907+++ b/include/drm/drm_crtc_helper.h
75908@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
75909 struct drm_connector *connector);
75910 /* disable encoder when not in use - more explicit than dpms off */
75911 void (*disable)(struct drm_encoder *encoder);
75912-};
75913+} __no_const;
75914
75915 /**
75916 * drm_connector_helper_funcs - helper operations for connectors
75917diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
75918index 940ece4..8cb727f 100644
75919--- a/include/drm/i915_pciids.h
75920+++ b/include/drm/i915_pciids.h
75921@@ -37,7 +37,7 @@
75922 */
75923 #define INTEL_VGA_DEVICE(id, info) { \
75924 0x8086, id, \
75925- ~0, ~0, \
75926+ PCI_ANY_ID, PCI_ANY_ID, \
75927 0x030000, 0xff0000, \
75928 (unsigned long) info }
75929
75930diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
75931index 72dcbe8..8db58d7 100644
75932--- a/include/drm/ttm/ttm_memory.h
75933+++ b/include/drm/ttm/ttm_memory.h
75934@@ -48,7 +48,7 @@
75935
75936 struct ttm_mem_shrink {
75937 int (*do_shrink) (struct ttm_mem_shrink *);
75938-};
75939+} __no_const;
75940
75941 /**
75942 * struct ttm_mem_global - Global memory accounting structure.
75943diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
75944index d1f61bf..2239439 100644
75945--- a/include/drm/ttm/ttm_page_alloc.h
75946+++ b/include/drm/ttm/ttm_page_alloc.h
75947@@ -78,6 +78,7 @@ void ttm_dma_page_alloc_fini(void);
75948 */
75949 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
75950
75951+struct device;
75952 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
75953 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
75954
75955diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
75956index 4b840e8..155d235 100644
75957--- a/include/keys/asymmetric-subtype.h
75958+++ b/include/keys/asymmetric-subtype.h
75959@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
75960 /* Verify the signature on a key of this subtype (optional) */
75961 int (*verify_signature)(const struct key *key,
75962 const struct public_key_signature *sig);
75963-};
75964+} __do_const;
75965
75966 /**
75967 * asymmetric_key_subtype - Get the subtype from an asymmetric key
75968diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
75969index c1da539..1dcec55 100644
75970--- a/include/linux/atmdev.h
75971+++ b/include/linux/atmdev.h
75972@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
75973 #endif
75974
75975 struct k_atm_aal_stats {
75976-#define __HANDLE_ITEM(i) atomic_t i
75977+#define __HANDLE_ITEM(i) atomic_unchecked_t i
75978 __AAL_STAT_ITEMS
75979 #undef __HANDLE_ITEM
75980 };
75981@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
75982 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
75983 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
75984 struct module *owner;
75985-};
75986+} __do_const ;
75987
75988 struct atmphy_ops {
75989 int (*start)(struct atm_dev *dev);
75990diff --git a/include/linux/audit.h b/include/linux/audit.h
75991index a406419..c2bb164 100644
75992--- a/include/linux/audit.h
75993+++ b/include/linux/audit.h
75994@@ -195,7 +195,7 @@ static inline void audit_ptrace(struct task_struct *t)
75995 extern unsigned int audit_serial(void);
75996 extern int auditsc_get_stamp(struct audit_context *ctx,
75997 struct timespec *t, unsigned int *serial);
75998-extern int audit_set_loginuid(kuid_t loginuid);
75999+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
76000
76001 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
76002 {
76003diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
76004index fd8bf32..2cccd5a 100644
76005--- a/include/linux/binfmts.h
76006+++ b/include/linux/binfmts.h
76007@@ -74,8 +74,10 @@ struct linux_binfmt {
76008 int (*load_binary)(struct linux_binprm *);
76009 int (*load_shlib)(struct file *);
76010 int (*core_dump)(struct coredump_params *cprm);
76011+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
76012+ void (*handle_mmap)(struct file *);
76013 unsigned long min_coredump; /* minimal dump size */
76014-};
76015+} __do_const;
76016
76017 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
76018
76019diff --git a/include/linux/bitops.h b/include/linux/bitops.h
76020index abc9ca7..e54ee27 100644
76021--- a/include/linux/bitops.h
76022+++ b/include/linux/bitops.h
76023@@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
76024 * @word: value to rotate
76025 * @shift: bits to roll
76026 */
76027-static inline __u32 rol32(__u32 word, unsigned int shift)
76028+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
76029 {
76030 return (word << shift) | (word >> (32 - shift));
76031 }
76032@@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
76033 * @word: value to rotate
76034 * @shift: bits to roll
76035 */
76036-static inline __u32 ror32(__u32 word, unsigned int shift)
76037+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
76038 {
76039 return (word >> shift) | (word << (32 - shift));
76040 }
76041@@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
76042 return (__s32)(value << shift) >> shift;
76043 }
76044
76045-static inline unsigned fls_long(unsigned long l)
76046+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
76047 {
76048 if (sizeof(l) == 4)
76049 return fls(l);
76050diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
76051index 1b135d4..59fc876 100644
76052--- a/include/linux/blkdev.h
76053+++ b/include/linux/blkdev.h
76054@@ -1578,7 +1578,7 @@ struct block_device_operations {
76055 /* this callback is with swap_lock and sometimes page table lock held */
76056 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
76057 struct module *owner;
76058-};
76059+} __do_const;
76060
76061 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
76062 unsigned long);
76063diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
76064index afc1343..9735539 100644
76065--- a/include/linux/blktrace_api.h
76066+++ b/include/linux/blktrace_api.h
76067@@ -25,7 +25,7 @@ struct blk_trace {
76068 struct dentry *dropped_file;
76069 struct dentry *msg_file;
76070 struct list_head running_list;
76071- atomic_t dropped;
76072+ atomic_unchecked_t dropped;
76073 };
76074
76075 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
76076diff --git a/include/linux/cache.h b/include/linux/cache.h
76077index 4c57065..40346da 100644
76078--- a/include/linux/cache.h
76079+++ b/include/linux/cache.h
76080@@ -16,6 +16,14 @@
76081 #define __read_mostly
76082 #endif
76083
76084+#ifndef __read_only
76085+#ifdef CONFIG_PAX_KERNEXEC
76086+#error KERNEXEC requires __read_only
76087+#else
76088+#define __read_only __read_mostly
76089+#endif
76090+#endif
76091+
76092 #ifndef ____cacheline_aligned
76093 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
76094 #endif
76095diff --git a/include/linux/capability.h b/include/linux/capability.h
76096index a6ee1f9..e1ca49d 100644
76097--- a/include/linux/capability.h
76098+++ b/include/linux/capability.h
76099@@ -212,8 +212,13 @@ extern bool capable(int cap);
76100 extern bool ns_capable(struct user_namespace *ns, int cap);
76101 extern bool inode_capable(const struct inode *inode, int cap);
76102 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
76103+extern bool capable_nolog(int cap);
76104+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
76105+extern bool inode_capable_nolog(const struct inode *inode, int cap);
76106
76107 /* audit system wants to get cap info from files as well */
76108 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
76109
76110+extern int is_privileged_binary(const struct dentry *dentry);
76111+
76112 #endif /* !_LINUX_CAPABILITY_H */
76113diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
76114index 8609d57..86e4d79 100644
76115--- a/include/linux/cdrom.h
76116+++ b/include/linux/cdrom.h
76117@@ -87,7 +87,6 @@ struct cdrom_device_ops {
76118
76119 /* driver specifications */
76120 const int capability; /* capability flags */
76121- int n_minors; /* number of active minor devices */
76122 /* handle uniform packets for scsi type devices (scsi,atapi) */
76123 int (*generic_packet) (struct cdrom_device_info *,
76124 struct packet_command *);
76125diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
76126index 4ce9056..86caac6 100644
76127--- a/include/linux/cleancache.h
76128+++ b/include/linux/cleancache.h
76129@@ -31,7 +31,7 @@ struct cleancache_ops {
76130 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
76131 void (*invalidate_inode)(int, struct cleancache_filekey);
76132 void (*invalidate_fs)(int);
76133-};
76134+} __no_const;
76135
76136 extern struct cleancache_ops *
76137 cleancache_register_ops(struct cleancache_ops *ops);
76138diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
76139index 7e59253..d6e4cae 100644
76140--- a/include/linux/clk-provider.h
76141+++ b/include/linux/clk-provider.h
76142@@ -141,6 +141,7 @@ struct clk_ops {
76143 unsigned long);
76144 void (*init)(struct clk_hw *hw);
76145 };
76146+typedef struct clk_ops __no_const clk_ops_no_const;
76147
76148 /**
76149 * struct clk_init_data - holds init data that's common to all clocks and is
76150diff --git a/include/linux/compat.h b/include/linux/compat.h
76151index eb8a49d..6b66ed9 100644
76152--- a/include/linux/compat.h
76153+++ b/include/linux/compat.h
76154@@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
76155 compat_size_t __user *len_ptr);
76156
76157 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
76158-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
76159+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
76160 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
76161 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
76162 compat_ssize_t msgsz, int msgflg);
76163@@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
76164 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
76165 compat_ulong_t addr, compat_ulong_t data);
76166 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
76167- compat_long_t addr, compat_long_t data);
76168+ compat_ulong_t addr, compat_ulong_t data);
76169
76170 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
76171 /*
76172diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
76173index ded4299..ddcbe31 100644
76174--- a/include/linux/compiler-gcc4.h
76175+++ b/include/linux/compiler-gcc4.h
76176@@ -39,9 +39,34 @@
76177 # define __compiletime_warning(message) __attribute__((warning(message)))
76178 # define __compiletime_error(message) __attribute__((error(message)))
76179 #endif /* __CHECKER__ */
76180+
76181+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
76182+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
76183+#define __bos0(ptr) __bos((ptr), 0)
76184+#define __bos1(ptr) __bos((ptr), 1)
76185 #endif /* GCC_VERSION >= 40300 */
76186
76187 #if GCC_VERSION >= 40500
76188+
76189+#ifdef RANDSTRUCT_PLUGIN
76190+#define __randomize_layout __attribute__((randomize_layout))
76191+#define __no_randomize_layout __attribute__((no_randomize_layout))
76192+#endif
76193+
76194+#ifdef CONSTIFY_PLUGIN
76195+#define __no_const __attribute__((no_const))
76196+#define __do_const __attribute__((do_const))
76197+#endif
76198+
76199+#ifdef SIZE_OVERFLOW_PLUGIN
76200+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
76201+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
76202+#endif
76203+
76204+#ifdef LATENT_ENTROPY_PLUGIN
76205+#define __latent_entropy __attribute__((latent_entropy))
76206+#endif
76207+
76208 /*
76209 * Mark a position in code as unreachable. This can be used to
76210 * suppress control flow warnings after asm blocks that transfer
76211diff --git a/include/linux/compiler.h b/include/linux/compiler.h
76212index 92669cd..cc564c0 100644
76213--- a/include/linux/compiler.h
76214+++ b/include/linux/compiler.h
76215@@ -5,11 +5,14 @@
76216
76217 #ifdef __CHECKER__
76218 # define __user __attribute__((noderef, address_space(1)))
76219+# define __force_user __force __user
76220 # define __kernel __attribute__((address_space(0)))
76221+# define __force_kernel __force __kernel
76222 # define __safe __attribute__((safe))
76223 # define __force __attribute__((force))
76224 # define __nocast __attribute__((nocast))
76225 # define __iomem __attribute__((noderef, address_space(2)))
76226+# define __force_iomem __force __iomem
76227 # define __must_hold(x) __attribute__((context(x,1,1)))
76228 # define __acquires(x) __attribute__((context(x,0,1)))
76229 # define __releases(x) __attribute__((context(x,1,0)))
76230@@ -17,20 +20,37 @@
76231 # define __release(x) __context__(x,-1)
76232 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
76233 # define __percpu __attribute__((noderef, address_space(3)))
76234+# define __force_percpu __force __percpu
76235 #ifdef CONFIG_SPARSE_RCU_POINTER
76236 # define __rcu __attribute__((noderef, address_space(4)))
76237+# define __force_rcu __force __rcu
76238 #else
76239 # define __rcu
76240+# define __force_rcu
76241 #endif
76242 extern void __chk_user_ptr(const volatile void __user *);
76243 extern void __chk_io_ptr(const volatile void __iomem *);
76244 #else
76245-# define __user
76246-# define __kernel
76247+# ifdef CHECKER_PLUGIN
76248+//# define __user
76249+//# define __force_user
76250+//# define __kernel
76251+//# define __force_kernel
76252+# else
76253+# ifdef STRUCTLEAK_PLUGIN
76254+# define __user __attribute__((user))
76255+# else
76256+# define __user
76257+# endif
76258+# define __force_user
76259+# define __kernel
76260+# define __force_kernel
76261+# endif
76262 # define __safe
76263 # define __force
76264 # define __nocast
76265 # define __iomem
76266+# define __force_iomem
76267 # define __chk_user_ptr(x) (void)0
76268 # define __chk_io_ptr(x) (void)0
76269 # define __builtin_warning(x, y...) (1)
76270@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
76271 # define __release(x) (void)0
76272 # define __cond_lock(x,c) (c)
76273 # define __percpu
76274+# define __force_percpu
76275 # define __rcu
76276+# define __force_rcu
76277 #endif
76278
76279 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
76280@@ -275,6 +297,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
76281 # define __attribute_const__ /* unimplemented */
76282 #endif
76283
76284+#ifndef __randomize_layout
76285+# define __randomize_layout
76286+#endif
76287+
76288+#ifndef __no_randomize_layout
76289+# define __no_randomize_layout
76290+#endif
76291+
76292+#ifndef __no_const
76293+# define __no_const
76294+#endif
76295+
76296+#ifndef __do_const
76297+# define __do_const
76298+#endif
76299+
76300+#ifndef __size_overflow
76301+# define __size_overflow(...)
76302+#endif
76303+
76304+#ifndef __intentional_overflow
76305+# define __intentional_overflow(...)
76306+#endif
76307+
76308+#ifndef __latent_entropy
76309+# define __latent_entropy
76310+#endif
76311+
76312 /*
76313 * Tell gcc if a function is cold. The compiler will assume any path
76314 * directly leading to the call is unlikely.
76315@@ -284,6 +334,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
76316 #define __cold
76317 #endif
76318
76319+#ifndef __alloc_size
76320+#define __alloc_size(...)
76321+#endif
76322+
76323+#ifndef __bos
76324+#define __bos(ptr, arg)
76325+#endif
76326+
76327+#ifndef __bos0
76328+#define __bos0(ptr)
76329+#endif
76330+
76331+#ifndef __bos1
76332+#define __bos1(ptr)
76333+#endif
76334+
76335 /* Simple shorthand for a section definition */
76336 #ifndef __section
76337 # define __section(S) __attribute__ ((__section__(#S)))
76338@@ -349,7 +415,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
76339 * use is to mediate communication between process-level code and irq/NMI
76340 * handlers, all running on the same CPU.
76341 */
76342-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
76343+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
76344+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
76345
76346 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
76347 #ifdef CONFIG_KPROBES
76348diff --git a/include/linux/completion.h b/include/linux/completion.h
76349index 5d5aaae..0ea9b84 100644
76350--- a/include/linux/completion.h
76351+++ b/include/linux/completion.h
76352@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
76353
76354 extern void wait_for_completion(struct completion *);
76355 extern void wait_for_completion_io(struct completion *);
76356-extern int wait_for_completion_interruptible(struct completion *x);
76357-extern int wait_for_completion_killable(struct completion *x);
76358+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
76359+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
76360 extern unsigned long wait_for_completion_timeout(struct completion *x,
76361- unsigned long timeout);
76362+ unsigned long timeout) __intentional_overflow(-1);
76363 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
76364- unsigned long timeout);
76365+ unsigned long timeout) __intentional_overflow(-1);
76366 extern long wait_for_completion_interruptible_timeout(
76367- struct completion *x, unsigned long timeout);
76368+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
76369 extern long wait_for_completion_killable_timeout(
76370- struct completion *x, unsigned long timeout);
76371+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
76372 extern bool try_wait_for_completion(struct completion *x);
76373 extern bool completion_done(struct completion *x);
76374
76375diff --git a/include/linux/configfs.h b/include/linux/configfs.h
76376index 34025df..d94bbbc 100644
76377--- a/include/linux/configfs.h
76378+++ b/include/linux/configfs.h
76379@@ -125,7 +125,7 @@ struct configfs_attribute {
76380 const char *ca_name;
76381 struct module *ca_owner;
76382 umode_t ca_mode;
76383-};
76384+} __do_const;
76385
76386 /*
76387 * Users often need to create attribute structures for their configurable
76388diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
76389index dc196bb..c55a50f 100644
76390--- a/include/linux/cpufreq.h
76391+++ b/include/linux/cpufreq.h
76392@@ -189,6 +189,7 @@ struct global_attr {
76393 ssize_t (*store)(struct kobject *a, struct attribute *b,
76394 const char *c, size_t count);
76395 };
76396+typedef struct global_attr __no_const global_attr_no_const;
76397
76398 #define define_one_global_ro(_name) \
76399 static struct global_attr _name = \
76400@@ -225,7 +226,7 @@ struct cpufreq_driver {
76401 int (*suspend) (struct cpufreq_policy *policy);
76402 int (*resume) (struct cpufreq_policy *policy);
76403 struct freq_attr **attr;
76404-};
76405+} __do_const;
76406
76407 /* flags */
76408 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
76409diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
76410index 50fcbb0..9d2dbd9 100644
76411--- a/include/linux/cpuidle.h
76412+++ b/include/linux/cpuidle.h
76413@@ -50,7 +50,8 @@ struct cpuidle_state {
76414 int index);
76415
76416 int (*enter_dead) (struct cpuidle_device *dev, int index);
76417-};
76418+} __do_const;
76419+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
76420
76421 /* Idle State Flags */
76422 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
76423@@ -192,7 +193,7 @@ struct cpuidle_governor {
76424 void (*reflect) (struct cpuidle_device *dev, int index);
76425
76426 struct module *owner;
76427-};
76428+} __do_const;
76429
76430 #ifdef CONFIG_CPU_IDLE
76431 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
76432diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
76433index d08e4d2..95fad61 100644
76434--- a/include/linux/cpumask.h
76435+++ b/include/linux/cpumask.h
76436@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
76437 }
76438
76439 /* Valid inputs for n are -1 and 0. */
76440-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
76441+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
76442 {
76443 return n+1;
76444 }
76445
76446-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
76447+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
76448 {
76449 return n+1;
76450 }
76451
76452-static inline unsigned int cpumask_next_and(int n,
76453+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
76454 const struct cpumask *srcp,
76455 const struct cpumask *andp)
76456 {
76457@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
76458 *
76459 * Returns >= nr_cpu_ids if no further cpus set.
76460 */
76461-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
76462+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
76463 {
76464 /* -1 is a legal arg here. */
76465 if (n != -1)
76466@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
76467 *
76468 * Returns >= nr_cpu_ids if no further cpus unset.
76469 */
76470-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
76471+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
76472 {
76473 /* -1 is a legal arg here. */
76474 if (n != -1)
76475@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
76476 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
76477 }
76478
76479-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
76480+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
76481 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
76482
76483 /**
76484diff --git a/include/linux/cred.h b/include/linux/cred.h
76485index 04421e8..117e17a 100644
76486--- a/include/linux/cred.h
76487+++ b/include/linux/cred.h
76488@@ -35,7 +35,7 @@ struct group_info {
76489 int nblocks;
76490 kgid_t small_block[NGROUPS_SMALL];
76491 kgid_t *blocks[0];
76492-};
76493+} __randomize_layout;
76494
76495 /**
76496 * get_group_info - Get a reference to a group info structure
76497@@ -136,7 +136,7 @@ struct cred {
76498 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
76499 struct group_info *group_info; /* supplementary groups for euid/fsgid */
76500 struct rcu_head rcu; /* RCU deletion hook */
76501-};
76502+} __randomize_layout;
76503
76504 extern void __put_cred(struct cred *);
76505 extern void exit_creds(struct task_struct *);
76506@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
76507 static inline void validate_process_creds(void)
76508 {
76509 }
76510+static inline void validate_task_creds(struct task_struct *task)
76511+{
76512+}
76513 #endif
76514
76515 /**
76516diff --git a/include/linux/crypto.h b/include/linux/crypto.h
76517index b92eadf..b4ecdc1 100644
76518--- a/include/linux/crypto.h
76519+++ b/include/linux/crypto.h
76520@@ -373,7 +373,7 @@ struct cipher_tfm {
76521 const u8 *key, unsigned int keylen);
76522 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
76523 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
76524-};
76525+} __no_const;
76526
76527 struct hash_tfm {
76528 int (*init)(struct hash_desc *desc);
76529@@ -394,13 +394,13 @@ struct compress_tfm {
76530 int (*cot_decompress)(struct crypto_tfm *tfm,
76531 const u8 *src, unsigned int slen,
76532 u8 *dst, unsigned int *dlen);
76533-};
76534+} __no_const;
76535
76536 struct rng_tfm {
76537 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
76538 unsigned int dlen);
76539 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
76540-};
76541+} __no_const;
76542
76543 #define crt_ablkcipher crt_u.ablkcipher
76544 #define crt_aead crt_u.aead
76545diff --git a/include/linux/ctype.h b/include/linux/ctype.h
76546index 653589e..4ef254a 100644
76547--- a/include/linux/ctype.h
76548+++ b/include/linux/ctype.h
76549@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
76550 * Fast implementation of tolower() for internal usage. Do not use in your
76551 * code.
76552 */
76553-static inline char _tolower(const char c)
76554+static inline unsigned char _tolower(const unsigned char c)
76555 {
76556 return c | 0x20;
76557 }
76558diff --git a/include/linux/dcache.h b/include/linux/dcache.h
76559index bf72e9a..4ca7927 100644
76560--- a/include/linux/dcache.h
76561+++ b/include/linux/dcache.h
76562@@ -133,7 +133,7 @@ struct dentry {
76563 } d_u;
76564 struct list_head d_subdirs; /* our children */
76565 struct hlist_node d_alias; /* inode alias list */
76566-};
76567+} __randomize_layout;
76568
76569 /*
76570 * dentry->d_lock spinlock nesting subclasses:
76571diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
76572index 7925bf0..d5143d2 100644
76573--- a/include/linux/decompress/mm.h
76574+++ b/include/linux/decompress/mm.h
76575@@ -77,7 +77,7 @@ static void free(void *where)
76576 * warnings when not needed (indeed large_malloc / large_free are not
76577 * needed by inflate */
76578
76579-#define malloc(a) kmalloc(a, GFP_KERNEL)
76580+#define malloc(a) kmalloc((a), GFP_KERNEL)
76581 #define free(a) kfree(a)
76582
76583 #define large_malloc(a) vmalloc(a)
76584diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
76585index d48dc00..211ee54 100644
76586--- a/include/linux/devfreq.h
76587+++ b/include/linux/devfreq.h
76588@@ -114,7 +114,7 @@ struct devfreq_governor {
76589 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
76590 int (*event_handler)(struct devfreq *devfreq,
76591 unsigned int event, void *data);
76592-};
76593+} __do_const;
76594
76595 /**
76596 * struct devfreq - Device devfreq structure
76597diff --git a/include/linux/device.h b/include/linux/device.h
76598index 952b010..d5b7691 100644
76599--- a/include/linux/device.h
76600+++ b/include/linux/device.h
76601@@ -310,7 +310,7 @@ struct subsys_interface {
76602 struct list_head node;
76603 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
76604 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
76605-};
76606+} __do_const;
76607
76608 int subsys_interface_register(struct subsys_interface *sif);
76609 void subsys_interface_unregister(struct subsys_interface *sif);
76610@@ -506,7 +506,7 @@ struct device_type {
76611 void (*release)(struct device *dev);
76612
76613 const struct dev_pm_ops *pm;
76614-};
76615+} __do_const;
76616
76617 /* interface for exporting device attributes */
76618 struct device_attribute {
76619@@ -516,11 +516,12 @@ struct device_attribute {
76620 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
76621 const char *buf, size_t count);
76622 };
76623+typedef struct device_attribute __no_const device_attribute_no_const;
76624
76625 struct dev_ext_attribute {
76626 struct device_attribute attr;
76627 void *var;
76628-};
76629+} __do_const;
76630
76631 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
76632 char *buf);
76633diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
76634index fd4aee2..1f28db9 100644
76635--- a/include/linux/dma-mapping.h
76636+++ b/include/linux/dma-mapping.h
76637@@ -54,7 +54,7 @@ struct dma_map_ops {
76638 u64 (*get_required_mask)(struct device *dev);
76639 #endif
76640 int is_phys;
76641-};
76642+} __do_const;
76643
76644 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
76645
76646diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
76647index 41cf0c3..f3b771c 100644
76648--- a/include/linux/dmaengine.h
76649+++ b/include/linux/dmaengine.h
76650@@ -1114,9 +1114,9 @@ struct dma_pinned_list {
76651 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
76652 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
76653
76654-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
76655+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
76656 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
76657-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
76658+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
76659 struct dma_pinned_list *pinned_list, struct page *page,
76660 unsigned int offset, size_t len);
76661
76662diff --git a/include/linux/efi.h b/include/linux/efi.h
76663index 11ce678..7b8c69c 100644
76664--- a/include/linux/efi.h
76665+++ b/include/linux/efi.h
76666@@ -764,6 +764,7 @@ struct efivar_operations {
76667 efi_set_variable_t *set_variable;
76668 efi_query_variable_store_t *query_variable_store;
76669 };
76670+typedef struct efivar_operations __no_const efivar_operations_no_const;
76671
76672 struct efivars {
76673 /*
76674diff --git a/include/linux/elf.h b/include/linux/elf.h
76675index 67a5fa7..b817372 100644
76676--- a/include/linux/elf.h
76677+++ b/include/linux/elf.h
76678@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
76679 #define elf_note elf32_note
76680 #define elf_addr_t Elf32_Off
76681 #define Elf_Half Elf32_Half
76682+#define elf_dyn Elf32_Dyn
76683
76684 #else
76685
76686@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
76687 #define elf_note elf64_note
76688 #define elf_addr_t Elf64_Off
76689 #define Elf_Half Elf64_Half
76690+#define elf_dyn Elf64_Dyn
76691
76692 #endif
76693
76694diff --git a/include/linux/err.h b/include/linux/err.h
76695index 15f92e0..e825a8e 100644
76696--- a/include/linux/err.h
76697+++ b/include/linux/err.h
76698@@ -19,12 +19,12 @@
76699
76700 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
76701
76702-static inline void * __must_check ERR_PTR(long error)
76703+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
76704 {
76705 return (void *) error;
76706 }
76707
76708-static inline long __must_check PTR_ERR(__force const void *ptr)
76709+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
76710 {
76711 return (long) ptr;
76712 }
76713diff --git a/include/linux/extcon.h b/include/linux/extcon.h
76714index 21c59af..6057a03 100644
76715--- a/include/linux/extcon.h
76716+++ b/include/linux/extcon.h
76717@@ -135,7 +135,7 @@ struct extcon_dev {
76718 /* /sys/class/extcon/.../mutually_exclusive/... */
76719 struct attribute_group attr_g_muex;
76720 struct attribute **attrs_muex;
76721- struct device_attribute *d_attrs_muex;
76722+ device_attribute_no_const *d_attrs_muex;
76723 };
76724
76725 /**
76726diff --git a/include/linux/fb.h b/include/linux/fb.h
76727index 70c4836..ff3daec 100644
76728--- a/include/linux/fb.h
76729+++ b/include/linux/fb.h
76730@@ -304,7 +304,7 @@ struct fb_ops {
76731 /* called at KDB enter and leave time to prepare the console */
76732 int (*fb_debug_enter)(struct fb_info *info);
76733 int (*fb_debug_leave)(struct fb_info *info);
76734-};
76735+} __do_const;
76736
76737 #ifdef CONFIG_FB_TILEBLITTING
76738 #define FB_TILE_CURSOR_NONE 0
76739diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
76740index 085197b..0fa6f0b 100644
76741--- a/include/linux/fdtable.h
76742+++ b/include/linux/fdtable.h
76743@@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
76744 void put_files_struct(struct files_struct *fs);
76745 void reset_files_struct(struct files_struct *);
76746 int unshare_files(struct files_struct **);
76747-struct files_struct *dup_fd(struct files_struct *, int *);
76748+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
76749 void do_close_on_exec(struct files_struct *);
76750 int iterate_fd(struct files_struct *, unsigned,
76751 int (*)(const void *, struct file *, unsigned),
76752diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
76753index 8293262..2b3b8bd 100644
76754--- a/include/linux/frontswap.h
76755+++ b/include/linux/frontswap.h
76756@@ -11,7 +11,7 @@ struct frontswap_ops {
76757 int (*load)(unsigned, pgoff_t, struct page *);
76758 void (*invalidate_page)(unsigned, pgoff_t);
76759 void (*invalidate_area)(unsigned);
76760-};
76761+} __no_const;
76762
76763 extern bool frontswap_enabled;
76764 extern struct frontswap_ops *
76765diff --git a/include/linux/fs.h b/include/linux/fs.h
76766index 121f11f..0f2a863 100644
76767--- a/include/linux/fs.h
76768+++ b/include/linux/fs.h
76769@@ -423,7 +423,7 @@ struct address_space {
76770 spinlock_t private_lock; /* for use by the address_space */
76771 struct list_head private_list; /* ditto */
76772 void *private_data; /* ditto */
76773-} __attribute__((aligned(sizeof(long))));
76774+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
76775 /*
76776 * On most architectures that alignment is already the case; but
76777 * must be enforced here for CRIS, to let the least significant bit
76778@@ -466,7 +466,7 @@ struct block_device {
76779 int bd_fsfreeze_count;
76780 /* Mutex for freeze */
76781 struct mutex bd_fsfreeze_mutex;
76782-};
76783+} __randomize_layout;
76784
76785 /*
76786 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
76787@@ -610,7 +610,7 @@ struct inode {
76788 atomic_t i_readcount; /* struct files open RO */
76789 #endif
76790 void *i_private; /* fs or device private pointer */
76791-};
76792+} __randomize_layout;
76793
76794 static inline int inode_unhashed(struct inode *inode)
76795 {
76796@@ -808,7 +808,7 @@ struct file {
76797 #ifdef CONFIG_DEBUG_WRITECOUNT
76798 unsigned long f_mnt_write_state;
76799 #endif
76800-};
76801+} __randomize_layout;
76802
76803 struct file_handle {
76804 __u32 handle_bytes;
76805@@ -978,7 +978,7 @@ struct file_lock {
76806 int state; /* state of grant or error if -ve */
76807 } afs;
76808 } fl_u;
76809-};
76810+} __randomize_layout;
76811
76812 /* The following constant reflects the upper bound of the file/locking space */
76813 #ifndef OFFSET_MAX
76814@@ -1325,7 +1325,7 @@ struct super_block {
76815 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
76816 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
76817 struct rcu_head rcu;
76818-};
76819+} __randomize_layout;
76820
76821 extern struct timespec current_fs_time(struct super_block *sb);
76822
76823@@ -1547,7 +1547,8 @@ struct file_operations {
76824 long (*fallocate)(struct file *file, int mode, loff_t offset,
76825 loff_t len);
76826 int (*show_fdinfo)(struct seq_file *m, struct file *f);
76827-};
76828+} __do_const __randomize_layout;
76829+typedef struct file_operations __no_const file_operations_no_const;
76830
76831 struct inode_operations {
76832 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
76833@@ -2808,4 +2809,14 @@ static inline bool dir_relax(struct inode *inode)
76834 return !IS_DEADDIR(inode);
76835 }
76836
76837+static inline bool is_sidechannel_device(const struct inode *inode)
76838+{
76839+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
76840+ umode_t mode = inode->i_mode;
76841+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
76842+#else
76843+ return false;
76844+#endif
76845+}
76846+
76847 #endif /* _LINUX_FS_H */
76848diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
76849index 0efc3e6..fd23610 100644
76850--- a/include/linux/fs_struct.h
76851+++ b/include/linux/fs_struct.h
76852@@ -6,13 +6,13 @@
76853 #include <linux/seqlock.h>
76854
76855 struct fs_struct {
76856- int users;
76857+ atomic_t users;
76858 spinlock_t lock;
76859 seqcount_t seq;
76860 int umask;
76861 int in_exec;
76862 struct path root, pwd;
76863-};
76864+} __randomize_layout;
76865
76866 extern struct kmem_cache *fs_cachep;
76867
76868diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
76869index 7714849..a4a5c7a 100644
76870--- a/include/linux/fscache-cache.h
76871+++ b/include/linux/fscache-cache.h
76872@@ -113,7 +113,7 @@ struct fscache_operation {
76873 fscache_operation_release_t release;
76874 };
76875
76876-extern atomic_t fscache_op_debug_id;
76877+extern atomic_unchecked_t fscache_op_debug_id;
76878 extern void fscache_op_work_func(struct work_struct *work);
76879
76880 extern void fscache_enqueue_operation(struct fscache_operation *);
76881@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
76882 INIT_WORK(&op->work, fscache_op_work_func);
76883 atomic_set(&op->usage, 1);
76884 op->state = FSCACHE_OP_ST_INITIALISED;
76885- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
76886+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
76887 op->processor = processor;
76888 op->release = release;
76889 INIT_LIST_HEAD(&op->pend_link);
76890diff --git a/include/linux/fscache.h b/include/linux/fscache.h
76891index 115bb81..e7b812b 100644
76892--- a/include/linux/fscache.h
76893+++ b/include/linux/fscache.h
76894@@ -152,7 +152,7 @@ struct fscache_cookie_def {
76895 * - this is mandatory for any object that may have data
76896 */
76897 void (*now_uncached)(void *cookie_netfs_data);
76898-};
76899+} __do_const;
76900
76901 /*
76902 * fscache cached network filesystem type
76903diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
76904index 1c804b0..1432c2b 100644
76905--- a/include/linux/fsnotify.h
76906+++ b/include/linux/fsnotify.h
76907@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
76908 struct inode *inode = file_inode(file);
76909 __u32 mask = FS_ACCESS;
76910
76911+ if (is_sidechannel_device(inode))
76912+ return;
76913+
76914 if (S_ISDIR(inode->i_mode))
76915 mask |= FS_ISDIR;
76916
76917@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
76918 struct inode *inode = file_inode(file);
76919 __u32 mask = FS_MODIFY;
76920
76921+ if (is_sidechannel_device(inode))
76922+ return;
76923+
76924 if (S_ISDIR(inode->i_mode))
76925 mask |= FS_ISDIR;
76926
76927@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
76928 */
76929 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
76930 {
76931- return kstrdup(name, GFP_KERNEL);
76932+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
76933 }
76934
76935 /*
76936diff --git a/include/linux/genhd.h b/include/linux/genhd.h
76937index 9f3c275..8bdff5d 100644
76938--- a/include/linux/genhd.h
76939+++ b/include/linux/genhd.h
76940@@ -194,7 +194,7 @@ struct gendisk {
76941 struct kobject *slave_dir;
76942
76943 struct timer_rand_state *random;
76944- atomic_t sync_io; /* RAID */
76945+ atomic_unchecked_t sync_io; /* RAID */
76946 struct disk_events *ev;
76947 #ifdef CONFIG_BLK_DEV_INTEGRITY
76948 struct blk_integrity *integrity;
76949@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
76950 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
76951
76952 /* drivers/char/random.c */
76953-extern void add_disk_randomness(struct gendisk *disk);
76954+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
76955 extern void rand_initialize_disk(struct gendisk *disk);
76956
76957 static inline sector_t get_start_sect(struct block_device *bdev)
76958diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
76959index c0894dd..2fbf10c 100644
76960--- a/include/linux/genl_magic_func.h
76961+++ b/include/linux/genl_magic_func.h
76962@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
76963 },
76964
76965 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
76966-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
76967+static struct genl_ops ZZZ_genl_ops[] = {
76968 #include GENL_MAGIC_INCLUDE_FILE
76969 };
76970
76971diff --git a/include/linux/gfp.h b/include/linux/gfp.h
76972index 9b4dd49..61fd41d 100644
76973--- a/include/linux/gfp.h
76974+++ b/include/linux/gfp.h
76975@@ -35,6 +35,13 @@ struct vm_area_struct;
76976 #define ___GFP_NO_KSWAPD 0x400000u
76977 #define ___GFP_OTHER_NODE 0x800000u
76978 #define ___GFP_WRITE 0x1000000u
76979+
76980+#ifdef CONFIG_PAX_USERCOPY_SLABS
76981+#define ___GFP_USERCOPY 0x2000000u
76982+#else
76983+#define ___GFP_USERCOPY 0
76984+#endif
76985+
76986 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
76987
76988 /*
76989@@ -92,6 +99,7 @@ struct vm_area_struct;
76990 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
76991 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
76992 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
76993+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
76994
76995 /*
76996 * This may seem redundant, but it's a way of annotating false positives vs.
76997@@ -99,7 +107,7 @@ struct vm_area_struct;
76998 */
76999 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
77000
77001-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
77002+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
77003 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
77004
77005 /* This equals 0, but use constants in case they ever change */
77006@@ -153,6 +161,8 @@ struct vm_area_struct;
77007 /* 4GB DMA on some platforms */
77008 #define GFP_DMA32 __GFP_DMA32
77009
77010+#define GFP_USERCOPY __GFP_USERCOPY
77011+
77012 /* Convert GFP flags to their corresponding migrate type */
77013 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
77014 {
77015diff --git a/include/linux/gracl.h b/include/linux/gracl.h
77016new file mode 100644
77017index 0000000..edb2cb6
77018--- /dev/null
77019+++ b/include/linux/gracl.h
77020@@ -0,0 +1,340 @@
77021+#ifndef GR_ACL_H
77022+#define GR_ACL_H
77023+
77024+#include <linux/grdefs.h>
77025+#include <linux/resource.h>
77026+#include <linux/capability.h>
77027+#include <linux/dcache.h>
77028+#include <asm/resource.h>
77029+
77030+/* Major status information */
77031+
77032+#define GR_VERSION "grsecurity 3.0"
77033+#define GRSECURITY_VERSION 0x3000
77034+
77035+enum {
77036+ GR_SHUTDOWN = 0,
77037+ GR_ENABLE = 1,
77038+ GR_SPROLE = 2,
77039+ GR_OLDRELOAD = 3,
77040+ GR_SEGVMOD = 4,
77041+ GR_STATUS = 5,
77042+ GR_UNSPROLE = 6,
77043+ GR_PASSSET = 7,
77044+ GR_SPROLEPAM = 8,
77045+ GR_RELOAD = 9,
77046+};
77047+
77048+/* Password setup definitions
77049+ * kernel/grhash.c */
77050+enum {
77051+ GR_PW_LEN = 128,
77052+ GR_SALT_LEN = 16,
77053+ GR_SHA_LEN = 32,
77054+};
77055+
77056+enum {
77057+ GR_SPROLE_LEN = 64,
77058+};
77059+
77060+enum {
77061+ GR_NO_GLOB = 0,
77062+ GR_REG_GLOB,
77063+ GR_CREATE_GLOB
77064+};
77065+
77066+#define GR_NLIMITS 32
77067+
77068+/* Begin Data Structures */
77069+
77070+struct sprole_pw {
77071+ unsigned char *rolename;
77072+ unsigned char salt[GR_SALT_LEN];
77073+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
77074+};
77075+
77076+struct name_entry {
77077+ __u32 key;
77078+ ino_t inode;
77079+ dev_t device;
77080+ char *name;
77081+ __u16 len;
77082+ __u8 deleted;
77083+ struct name_entry *prev;
77084+ struct name_entry *next;
77085+};
77086+
77087+struct inodev_entry {
77088+ struct name_entry *nentry;
77089+ struct inodev_entry *prev;
77090+ struct inodev_entry *next;
77091+};
77092+
77093+struct acl_role_db {
77094+ struct acl_role_label **r_hash;
77095+ __u32 r_size;
77096+};
77097+
77098+struct inodev_db {
77099+ struct inodev_entry **i_hash;
77100+ __u32 i_size;
77101+};
77102+
77103+struct name_db {
77104+ struct name_entry **n_hash;
77105+ __u32 n_size;
77106+};
77107+
77108+struct crash_uid {
77109+ uid_t uid;
77110+ unsigned long expires;
77111+};
77112+
77113+struct gr_hash_struct {
77114+ void **table;
77115+ void **nametable;
77116+ void *first;
77117+ __u32 table_size;
77118+ __u32 used_size;
77119+ int type;
77120+};
77121+
77122+/* Userspace Grsecurity ACL data structures */
77123+
77124+struct acl_subject_label {
77125+ char *filename;
77126+ ino_t inode;
77127+ dev_t device;
77128+ __u32 mode;
77129+ kernel_cap_t cap_mask;
77130+ kernel_cap_t cap_lower;
77131+ kernel_cap_t cap_invert_audit;
77132+
77133+ struct rlimit res[GR_NLIMITS];
77134+ __u32 resmask;
77135+
77136+ __u8 user_trans_type;
77137+ __u8 group_trans_type;
77138+ uid_t *user_transitions;
77139+ gid_t *group_transitions;
77140+ __u16 user_trans_num;
77141+ __u16 group_trans_num;
77142+
77143+ __u32 sock_families[2];
77144+ __u32 ip_proto[8];
77145+ __u32 ip_type;
77146+ struct acl_ip_label **ips;
77147+ __u32 ip_num;
77148+ __u32 inaddr_any_override;
77149+
77150+ __u32 crashes;
77151+ unsigned long expires;
77152+
77153+ struct acl_subject_label *parent_subject;
77154+ struct gr_hash_struct *hash;
77155+ struct acl_subject_label *prev;
77156+ struct acl_subject_label *next;
77157+
77158+ struct acl_object_label **obj_hash;
77159+ __u32 obj_hash_size;
77160+ __u16 pax_flags;
77161+};
77162+
77163+struct role_allowed_ip {
77164+ __u32 addr;
77165+ __u32 netmask;
77166+
77167+ struct role_allowed_ip *prev;
77168+ struct role_allowed_ip *next;
77169+};
77170+
77171+struct role_transition {
77172+ char *rolename;
77173+
77174+ struct role_transition *prev;
77175+ struct role_transition *next;
77176+};
77177+
77178+struct acl_role_label {
77179+ char *rolename;
77180+ uid_t uidgid;
77181+ __u16 roletype;
77182+
77183+ __u16 auth_attempts;
77184+ unsigned long expires;
77185+
77186+ struct acl_subject_label *root_label;
77187+ struct gr_hash_struct *hash;
77188+
77189+ struct acl_role_label *prev;
77190+ struct acl_role_label *next;
77191+
77192+ struct role_transition *transitions;
77193+ struct role_allowed_ip *allowed_ips;
77194+ uid_t *domain_children;
77195+ __u16 domain_child_num;
77196+
77197+ umode_t umask;
77198+
77199+ struct acl_subject_label **subj_hash;
77200+ __u32 subj_hash_size;
77201+};
77202+
77203+struct user_acl_role_db {
77204+ struct acl_role_label **r_table;
77205+ __u32 num_pointers; /* Number of allocations to track */
77206+ __u32 num_roles; /* Number of roles */
77207+ __u32 num_domain_children; /* Number of domain children */
77208+ __u32 num_subjects; /* Number of subjects */
77209+ __u32 num_objects; /* Number of objects */
77210+};
77211+
77212+struct acl_object_label {
77213+ char *filename;
77214+ ino_t inode;
77215+ dev_t device;
77216+ __u32 mode;
77217+
77218+ struct acl_subject_label *nested;
77219+ struct acl_object_label *globbed;
77220+
77221+ /* next two structures not used */
77222+
77223+ struct acl_object_label *prev;
77224+ struct acl_object_label *next;
77225+};
77226+
77227+struct acl_ip_label {
77228+ char *iface;
77229+ __u32 addr;
77230+ __u32 netmask;
77231+ __u16 low, high;
77232+ __u8 mode;
77233+ __u32 type;
77234+ __u32 proto[8];
77235+
77236+ /* next two structures not used */
77237+
77238+ struct acl_ip_label *prev;
77239+ struct acl_ip_label *next;
77240+};
77241+
77242+struct gr_arg {
77243+ struct user_acl_role_db role_db;
77244+ unsigned char pw[GR_PW_LEN];
77245+ unsigned char salt[GR_SALT_LEN];
77246+ unsigned char sum[GR_SHA_LEN];
77247+ unsigned char sp_role[GR_SPROLE_LEN];
77248+ struct sprole_pw *sprole_pws;
77249+ dev_t segv_device;
77250+ ino_t segv_inode;
77251+ uid_t segv_uid;
77252+ __u16 num_sprole_pws;
77253+ __u16 mode;
77254+};
77255+
77256+struct gr_arg_wrapper {
77257+ struct gr_arg *arg;
77258+ __u32 version;
77259+ __u32 size;
77260+};
77261+
77262+struct subject_map {
77263+ struct acl_subject_label *user;
77264+ struct acl_subject_label *kernel;
77265+ struct subject_map *prev;
77266+ struct subject_map *next;
77267+};
77268+
77269+struct acl_subj_map_db {
77270+ struct subject_map **s_hash;
77271+ __u32 s_size;
77272+};
77273+
77274+struct gr_policy_state {
77275+ struct sprole_pw **acl_special_roles;
77276+ __u16 num_sprole_pws;
77277+ struct acl_role_label *kernel_role;
77278+ struct acl_role_label *role_list;
77279+ struct acl_role_label *default_role;
77280+ struct acl_role_db acl_role_set;
77281+ struct acl_subj_map_db subj_map_set;
77282+ struct name_db name_set;
77283+ struct inodev_db inodev_set;
77284+};
77285+
77286+struct gr_alloc_state {
77287+ unsigned long alloc_stack_next;
77288+ unsigned long alloc_stack_size;
77289+ void **alloc_stack;
77290+};
77291+
77292+struct gr_reload_state {
77293+ struct gr_policy_state oldpolicy;
77294+ struct gr_alloc_state oldalloc;
77295+ struct gr_policy_state newpolicy;
77296+ struct gr_alloc_state newalloc;
77297+ struct gr_policy_state *oldpolicy_ptr;
77298+ struct gr_alloc_state *oldalloc_ptr;
77299+ unsigned char oldmode;
77300+};
77301+
77302+/* End Data Structures Section */
77303+
77304+/* Hash functions generated by empirical testing by Brad Spengler
77305+ Makes good use of the low bits of the inode. Generally 0-1 times
77306+ in loop for successful match. 0-3 for unsuccessful match.
77307+ Shift/add algorithm with modulus of table size and an XOR*/
77308+
77309+static __inline__ unsigned int
77310+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
77311+{
77312+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
77313+}
77314+
77315+ static __inline__ unsigned int
77316+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
77317+{
77318+ return ((const unsigned long)userp % sz);
77319+}
77320+
77321+static __inline__ unsigned int
77322+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
77323+{
77324+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
77325+}
77326+
77327+static __inline__ unsigned int
77328+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
77329+{
77330+ return full_name_hash((const unsigned char *)name, len) % sz;
77331+}
77332+
77333+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
77334+ subj = NULL; \
77335+ iter = 0; \
77336+ while (iter < role->subj_hash_size) { \
77337+ if (subj == NULL) \
77338+ subj = role->subj_hash[iter]; \
77339+ if (subj == NULL) { \
77340+ iter++; \
77341+ continue; \
77342+ }
77343+
77344+#define FOR_EACH_SUBJECT_END(subj,iter) \
77345+ subj = subj->next; \
77346+ if (subj == NULL) \
77347+ iter++; \
77348+ }
77349+
77350+
77351+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
77352+ subj = role->hash->first; \
77353+ while (subj != NULL) {
77354+
77355+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
77356+ subj = subj->next; \
77357+ }
77358+
77359+#endif
77360+
77361diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
77362new file mode 100644
77363index 0000000..33ebd1f
77364--- /dev/null
77365+++ b/include/linux/gracl_compat.h
77366@@ -0,0 +1,156 @@
77367+#ifndef GR_ACL_COMPAT_H
77368+#define GR_ACL_COMPAT_H
77369+
77370+#include <linux/resource.h>
77371+#include <asm/resource.h>
77372+
77373+struct sprole_pw_compat {
77374+ compat_uptr_t rolename;
77375+ unsigned char salt[GR_SALT_LEN];
77376+ unsigned char sum[GR_SHA_LEN];
77377+};
77378+
77379+struct gr_hash_struct_compat {
77380+ compat_uptr_t table;
77381+ compat_uptr_t nametable;
77382+ compat_uptr_t first;
77383+ __u32 table_size;
77384+ __u32 used_size;
77385+ int type;
77386+};
77387+
77388+struct acl_subject_label_compat {
77389+ compat_uptr_t filename;
77390+ compat_ino_t inode;
77391+ __u32 device;
77392+ __u32 mode;
77393+ kernel_cap_t cap_mask;
77394+ kernel_cap_t cap_lower;
77395+ kernel_cap_t cap_invert_audit;
77396+
77397+ struct compat_rlimit res[GR_NLIMITS];
77398+ __u32 resmask;
77399+
77400+ __u8 user_trans_type;
77401+ __u8 group_trans_type;
77402+ compat_uptr_t user_transitions;
77403+ compat_uptr_t group_transitions;
77404+ __u16 user_trans_num;
77405+ __u16 group_trans_num;
77406+
77407+ __u32 sock_families[2];
77408+ __u32 ip_proto[8];
77409+ __u32 ip_type;
77410+ compat_uptr_t ips;
77411+ __u32 ip_num;
77412+ __u32 inaddr_any_override;
77413+
77414+ __u32 crashes;
77415+ compat_ulong_t expires;
77416+
77417+ compat_uptr_t parent_subject;
77418+ compat_uptr_t hash;
77419+ compat_uptr_t prev;
77420+ compat_uptr_t next;
77421+
77422+ compat_uptr_t obj_hash;
77423+ __u32 obj_hash_size;
77424+ __u16 pax_flags;
77425+};
77426+
77427+struct role_allowed_ip_compat {
77428+ __u32 addr;
77429+ __u32 netmask;
77430+
77431+ compat_uptr_t prev;
77432+ compat_uptr_t next;
77433+};
77434+
77435+struct role_transition_compat {
77436+ compat_uptr_t rolename;
77437+
77438+ compat_uptr_t prev;
77439+ compat_uptr_t next;
77440+};
77441+
77442+struct acl_role_label_compat {
77443+ compat_uptr_t rolename;
77444+ uid_t uidgid;
77445+ __u16 roletype;
77446+
77447+ __u16 auth_attempts;
77448+ compat_ulong_t expires;
77449+
77450+ compat_uptr_t root_label;
77451+ compat_uptr_t hash;
77452+
77453+ compat_uptr_t prev;
77454+ compat_uptr_t next;
77455+
77456+ compat_uptr_t transitions;
77457+ compat_uptr_t allowed_ips;
77458+ compat_uptr_t domain_children;
77459+ __u16 domain_child_num;
77460+
77461+ umode_t umask;
77462+
77463+ compat_uptr_t subj_hash;
77464+ __u32 subj_hash_size;
77465+};
77466+
77467+struct user_acl_role_db_compat {
77468+ compat_uptr_t r_table;
77469+ __u32 num_pointers;
77470+ __u32 num_roles;
77471+ __u32 num_domain_children;
77472+ __u32 num_subjects;
77473+ __u32 num_objects;
77474+};
77475+
77476+struct acl_object_label_compat {
77477+ compat_uptr_t filename;
77478+ compat_ino_t inode;
77479+ __u32 device;
77480+ __u32 mode;
77481+
77482+ compat_uptr_t nested;
77483+ compat_uptr_t globbed;
77484+
77485+ compat_uptr_t prev;
77486+ compat_uptr_t next;
77487+};
77488+
77489+struct acl_ip_label_compat {
77490+ compat_uptr_t iface;
77491+ __u32 addr;
77492+ __u32 netmask;
77493+ __u16 low, high;
77494+ __u8 mode;
77495+ __u32 type;
77496+ __u32 proto[8];
77497+
77498+ compat_uptr_t prev;
77499+ compat_uptr_t next;
77500+};
77501+
77502+struct gr_arg_compat {
77503+ struct user_acl_role_db_compat role_db;
77504+ unsigned char pw[GR_PW_LEN];
77505+ unsigned char salt[GR_SALT_LEN];
77506+ unsigned char sum[GR_SHA_LEN];
77507+ unsigned char sp_role[GR_SPROLE_LEN];
77508+ compat_uptr_t sprole_pws;
77509+ __u32 segv_device;
77510+ compat_ino_t segv_inode;
77511+ uid_t segv_uid;
77512+ __u16 num_sprole_pws;
77513+ __u16 mode;
77514+};
77515+
77516+struct gr_arg_wrapper_compat {
77517+ compat_uptr_t arg;
77518+ __u32 version;
77519+ __u32 size;
77520+};
77521+
77522+#endif
77523diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
77524new file mode 100644
77525index 0000000..323ecf2
77526--- /dev/null
77527+++ b/include/linux/gralloc.h
77528@@ -0,0 +1,9 @@
77529+#ifndef __GRALLOC_H
77530+#define __GRALLOC_H
77531+
77532+void acl_free_all(void);
77533+int acl_alloc_stack_init(unsigned long size);
77534+void *acl_alloc(unsigned long len);
77535+void *acl_alloc_num(unsigned long num, unsigned long len);
77536+
77537+#endif
77538diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
77539new file mode 100644
77540index 0000000..be66033
77541--- /dev/null
77542+++ b/include/linux/grdefs.h
77543@@ -0,0 +1,140 @@
77544+#ifndef GRDEFS_H
77545+#define GRDEFS_H
77546+
77547+/* Begin grsecurity status declarations */
77548+
77549+enum {
77550+ GR_READY = 0x01,
77551+ GR_STATUS_INIT = 0x00 // disabled state
77552+};
77553+
77554+/* Begin ACL declarations */
77555+
77556+/* Role flags */
77557+
77558+enum {
77559+ GR_ROLE_USER = 0x0001,
77560+ GR_ROLE_GROUP = 0x0002,
77561+ GR_ROLE_DEFAULT = 0x0004,
77562+ GR_ROLE_SPECIAL = 0x0008,
77563+ GR_ROLE_AUTH = 0x0010,
77564+ GR_ROLE_NOPW = 0x0020,
77565+ GR_ROLE_GOD = 0x0040,
77566+ GR_ROLE_LEARN = 0x0080,
77567+ GR_ROLE_TPE = 0x0100,
77568+ GR_ROLE_DOMAIN = 0x0200,
77569+ GR_ROLE_PAM = 0x0400,
77570+ GR_ROLE_PERSIST = 0x0800
77571+};
77572+
77573+/* ACL Subject and Object mode flags */
77574+enum {
77575+ GR_DELETED = 0x80000000
77576+};
77577+
77578+/* ACL Object-only mode flags */
77579+enum {
77580+ GR_READ = 0x00000001,
77581+ GR_APPEND = 0x00000002,
77582+ GR_WRITE = 0x00000004,
77583+ GR_EXEC = 0x00000008,
77584+ GR_FIND = 0x00000010,
77585+ GR_INHERIT = 0x00000020,
77586+ GR_SETID = 0x00000040,
77587+ GR_CREATE = 0x00000080,
77588+ GR_DELETE = 0x00000100,
77589+ GR_LINK = 0x00000200,
77590+ GR_AUDIT_READ = 0x00000400,
77591+ GR_AUDIT_APPEND = 0x00000800,
77592+ GR_AUDIT_WRITE = 0x00001000,
77593+ GR_AUDIT_EXEC = 0x00002000,
77594+ GR_AUDIT_FIND = 0x00004000,
77595+ GR_AUDIT_INHERIT= 0x00008000,
77596+ GR_AUDIT_SETID = 0x00010000,
77597+ GR_AUDIT_CREATE = 0x00020000,
77598+ GR_AUDIT_DELETE = 0x00040000,
77599+ GR_AUDIT_LINK = 0x00080000,
77600+ GR_PTRACERD = 0x00100000,
77601+ GR_NOPTRACE = 0x00200000,
77602+ GR_SUPPRESS = 0x00400000,
77603+ GR_NOLEARN = 0x00800000,
77604+ GR_INIT_TRANSFER= 0x01000000
77605+};
77606+
77607+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
77608+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
77609+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
77610+
77611+/* ACL subject-only mode flags */
77612+enum {
77613+ GR_KILL = 0x00000001,
77614+ GR_VIEW = 0x00000002,
77615+ GR_PROTECTED = 0x00000004,
77616+ GR_LEARN = 0x00000008,
77617+ GR_OVERRIDE = 0x00000010,
77618+ /* just a placeholder, this mode is only used in userspace */
77619+ GR_DUMMY = 0x00000020,
77620+ GR_PROTSHM = 0x00000040,
77621+ GR_KILLPROC = 0x00000080,
77622+ GR_KILLIPPROC = 0x00000100,
77623+ /* just a placeholder, this mode is only used in userspace */
77624+ GR_NOTROJAN = 0x00000200,
77625+ GR_PROTPROCFD = 0x00000400,
77626+ GR_PROCACCT = 0x00000800,
77627+ GR_RELAXPTRACE = 0x00001000,
77628+ //GR_NESTED = 0x00002000,
77629+ GR_INHERITLEARN = 0x00004000,
77630+ GR_PROCFIND = 0x00008000,
77631+ GR_POVERRIDE = 0x00010000,
77632+ GR_KERNELAUTH = 0x00020000,
77633+ GR_ATSECURE = 0x00040000,
77634+ GR_SHMEXEC = 0x00080000
77635+};
77636+
77637+enum {
77638+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
77639+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
77640+ GR_PAX_ENABLE_MPROTECT = 0x0004,
77641+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
77642+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
77643+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
77644+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
77645+ GR_PAX_DISABLE_MPROTECT = 0x0400,
77646+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
77647+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
77648+};
77649+
77650+enum {
77651+ GR_ID_USER = 0x01,
77652+ GR_ID_GROUP = 0x02,
77653+};
77654+
77655+enum {
77656+ GR_ID_ALLOW = 0x01,
77657+ GR_ID_DENY = 0x02,
77658+};
77659+
77660+#define GR_CRASH_RES 31
77661+#define GR_UIDTABLE_MAX 500
77662+
77663+/* begin resource learning section */
77664+enum {
77665+ GR_RLIM_CPU_BUMP = 60,
77666+ GR_RLIM_FSIZE_BUMP = 50000,
77667+ GR_RLIM_DATA_BUMP = 10000,
77668+ GR_RLIM_STACK_BUMP = 1000,
77669+ GR_RLIM_CORE_BUMP = 10000,
77670+ GR_RLIM_RSS_BUMP = 500000,
77671+ GR_RLIM_NPROC_BUMP = 1,
77672+ GR_RLIM_NOFILE_BUMP = 5,
77673+ GR_RLIM_MEMLOCK_BUMP = 50000,
77674+ GR_RLIM_AS_BUMP = 500000,
77675+ GR_RLIM_LOCKS_BUMP = 2,
77676+ GR_RLIM_SIGPENDING_BUMP = 5,
77677+ GR_RLIM_MSGQUEUE_BUMP = 10000,
77678+ GR_RLIM_NICE_BUMP = 1,
77679+ GR_RLIM_RTPRIO_BUMP = 1,
77680+ GR_RLIM_RTTIME_BUMP = 1000000
77681+};
77682+
77683+#endif
77684diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
77685new file mode 100644
77686index 0000000..d25522e
77687--- /dev/null
77688+++ b/include/linux/grinternal.h
77689@@ -0,0 +1,229 @@
77690+#ifndef __GRINTERNAL_H
77691+#define __GRINTERNAL_H
77692+
77693+#ifdef CONFIG_GRKERNSEC
77694+
77695+#include <linux/fs.h>
77696+#include <linux/mnt_namespace.h>
77697+#include <linux/nsproxy.h>
77698+#include <linux/gracl.h>
77699+#include <linux/grdefs.h>
77700+#include <linux/grmsg.h>
77701+
77702+void gr_add_learn_entry(const char *fmt, ...)
77703+ __attribute__ ((format (printf, 1, 2)));
77704+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
77705+ const struct vfsmount *mnt);
77706+__u32 gr_check_create(const struct dentry *new_dentry,
77707+ const struct dentry *parent,
77708+ const struct vfsmount *mnt, const __u32 mode);
77709+int gr_check_protected_task(const struct task_struct *task);
77710+__u32 to_gr_audit(const __u32 reqmode);
77711+int gr_set_acls(const int type);
77712+int gr_acl_is_enabled(void);
77713+char gr_roletype_to_char(void);
77714+
77715+void gr_handle_alertkill(struct task_struct *task);
77716+char *gr_to_filename(const struct dentry *dentry,
77717+ const struct vfsmount *mnt);
77718+char *gr_to_filename1(const struct dentry *dentry,
77719+ const struct vfsmount *mnt);
77720+char *gr_to_filename2(const struct dentry *dentry,
77721+ const struct vfsmount *mnt);
77722+char *gr_to_filename3(const struct dentry *dentry,
77723+ const struct vfsmount *mnt);
77724+
77725+extern int grsec_enable_ptrace_readexec;
77726+extern int grsec_enable_harden_ptrace;
77727+extern int grsec_enable_link;
77728+extern int grsec_enable_fifo;
77729+extern int grsec_enable_execve;
77730+extern int grsec_enable_shm;
77731+extern int grsec_enable_execlog;
77732+extern int grsec_enable_signal;
77733+extern int grsec_enable_audit_ptrace;
77734+extern int grsec_enable_forkfail;
77735+extern int grsec_enable_time;
77736+extern int grsec_enable_rofs;
77737+extern int grsec_deny_new_usb;
77738+extern int grsec_enable_chroot_shmat;
77739+extern int grsec_enable_chroot_mount;
77740+extern int grsec_enable_chroot_double;
77741+extern int grsec_enable_chroot_pivot;
77742+extern int grsec_enable_chroot_chdir;
77743+extern int grsec_enable_chroot_chmod;
77744+extern int grsec_enable_chroot_mknod;
77745+extern int grsec_enable_chroot_fchdir;
77746+extern int grsec_enable_chroot_nice;
77747+extern int grsec_enable_chroot_execlog;
77748+extern int grsec_enable_chroot_caps;
77749+extern int grsec_enable_chroot_sysctl;
77750+extern int grsec_enable_chroot_unix;
77751+extern int grsec_enable_symlinkown;
77752+extern kgid_t grsec_symlinkown_gid;
77753+extern int grsec_enable_tpe;
77754+extern kgid_t grsec_tpe_gid;
77755+extern int grsec_enable_tpe_all;
77756+extern int grsec_enable_tpe_invert;
77757+extern int grsec_enable_socket_all;
77758+extern kgid_t grsec_socket_all_gid;
77759+extern int grsec_enable_socket_client;
77760+extern kgid_t grsec_socket_client_gid;
77761+extern int grsec_enable_socket_server;
77762+extern kgid_t grsec_socket_server_gid;
77763+extern kgid_t grsec_audit_gid;
77764+extern int grsec_enable_group;
77765+extern int grsec_enable_log_rwxmaps;
77766+extern int grsec_enable_mount;
77767+extern int grsec_enable_chdir;
77768+extern int grsec_resource_logging;
77769+extern int grsec_enable_blackhole;
77770+extern int grsec_lastack_retries;
77771+extern int grsec_enable_brute;
77772+extern int grsec_enable_harden_ipc;
77773+extern int grsec_lock;
77774+
77775+extern spinlock_t grsec_alert_lock;
77776+extern unsigned long grsec_alert_wtime;
77777+extern unsigned long grsec_alert_fyet;
77778+
77779+extern spinlock_t grsec_audit_lock;
77780+
77781+extern rwlock_t grsec_exec_file_lock;
77782+
77783+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
77784+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
77785+ (tsk)->exec_file->f_path.mnt) : "/")
77786+
77787+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
77788+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
77789+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
77790+
77791+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
77792+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
77793+ (tsk)->exec_file->f_path.mnt) : "/")
77794+
77795+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
77796+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
77797+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
77798+
77799+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
77800+
77801+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
77802+
77803+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
77804+{
77805+ if (file1 && file2) {
77806+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
77807+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
77808+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
77809+ return true;
77810+ }
77811+
77812+ return false;
77813+}
77814+
77815+#define GR_CHROOT_CAPS {{ \
77816+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
77817+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
77818+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
77819+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
77820+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
77821+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
77822+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
77823+
77824+#define security_learn(normal_msg,args...) \
77825+({ \
77826+ read_lock(&grsec_exec_file_lock); \
77827+ gr_add_learn_entry(normal_msg "\n", ## args); \
77828+ read_unlock(&grsec_exec_file_lock); \
77829+})
77830+
77831+enum {
77832+ GR_DO_AUDIT,
77833+ GR_DONT_AUDIT,
77834+ /* used for non-audit messages that we shouldn't kill the task on */
77835+ GR_DONT_AUDIT_GOOD
77836+};
77837+
77838+enum {
77839+ GR_TTYSNIFF,
77840+ GR_RBAC,
77841+ GR_RBAC_STR,
77842+ GR_STR_RBAC,
77843+ GR_RBAC_MODE2,
77844+ GR_RBAC_MODE3,
77845+ GR_FILENAME,
77846+ GR_SYSCTL_HIDDEN,
77847+ GR_NOARGS,
77848+ GR_ONE_INT,
77849+ GR_ONE_INT_TWO_STR,
77850+ GR_ONE_STR,
77851+ GR_STR_INT,
77852+ GR_TWO_STR_INT,
77853+ GR_TWO_INT,
77854+ GR_TWO_U64,
77855+ GR_THREE_INT,
77856+ GR_FIVE_INT_TWO_STR,
77857+ GR_TWO_STR,
77858+ GR_THREE_STR,
77859+ GR_FOUR_STR,
77860+ GR_STR_FILENAME,
77861+ GR_FILENAME_STR,
77862+ GR_FILENAME_TWO_INT,
77863+ GR_FILENAME_TWO_INT_STR,
77864+ GR_TEXTREL,
77865+ GR_PTRACE,
77866+ GR_RESOURCE,
77867+ GR_CAP,
77868+ GR_SIG,
77869+ GR_SIG2,
77870+ GR_CRASH1,
77871+ GR_CRASH2,
77872+ GR_PSACCT,
77873+ GR_RWXMAP,
77874+ GR_RWXMAPVMA
77875+};
77876+
77877+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
77878+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
77879+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
77880+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
77881+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
77882+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
77883+#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)
77884+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
77885+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
77886+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
77887+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
77888+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
77889+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
77890+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
77891+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
77892+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
77893+#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)
77894+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
77895+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
77896+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
77897+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
77898+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
77899+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
77900+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
77901+#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)
77902+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
77903+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
77904+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
77905+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
77906+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
77907+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
77908+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
77909+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
77910+#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)
77911+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
77912+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
77913+
77914+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
77915+
77916+#endif
77917+
77918+#endif
77919diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
77920new file mode 100644
77921index 0000000..195cbe4
77922--- /dev/null
77923+++ b/include/linux/grmsg.h
77924@@ -0,0 +1,115 @@
77925+#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"
77926+#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"
77927+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
77928+#define GR_STOPMOD_MSG "denied modification of module state by "
77929+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
77930+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
77931+#define GR_IOPERM_MSG "denied use of ioperm() by "
77932+#define GR_IOPL_MSG "denied use of iopl() by "
77933+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
77934+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
77935+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
77936+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
77937+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
77938+#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"
77939+#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"
77940+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
77941+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
77942+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
77943+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
77944+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
77945+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
77946+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
77947+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
77948+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
77949+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
77950+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
77951+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
77952+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
77953+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
77954+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
77955+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
77956+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
77957+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
77958+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
77959+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
77960+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
77961+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
77962+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
77963+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
77964+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
77965+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
77966+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
77967+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
77968+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
77969+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
77970+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
77971+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
77972+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
77973+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
77974+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
77975+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
77976+#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"
77977+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
77978+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
77979+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
77980+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
77981+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
77982+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
77983+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
77984+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
77985+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
77986+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
77987+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
77988+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
77989+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
77990+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
77991+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
77992+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
77993+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
77994+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
77995+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
77996+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
77997+#define GR_FAILFORK_MSG "failed fork with errno %s by "
77998+#define GR_NICE_CHROOT_MSG "denied priority change by "
77999+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
78000+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
78001+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
78002+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
78003+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
78004+#define GR_TIME_MSG "time set by "
78005+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
78006+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
78007+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
78008+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
78009+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
78010+#define GR_BIND_MSG "denied bind() by "
78011+#define GR_CONNECT_MSG "denied connect() by "
78012+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
78013+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
78014+#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"
78015+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
78016+#define GR_CAP_ACL_MSG "use of %s denied for "
78017+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
78018+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
78019+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
78020+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
78021+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
78022+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
78023+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
78024+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
78025+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
78026+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
78027+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
78028+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
78029+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
78030+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
78031+#define GR_VM86_MSG "denied use of vm86 by "
78032+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
78033+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
78034+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
78035+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
78036+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
78037+#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 "
78038+#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 "
78039+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
78040diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
78041new file mode 100644
78042index 0000000..d8b5b48
78043--- /dev/null
78044+++ b/include/linux/grsecurity.h
78045@@ -0,0 +1,245 @@
78046+#ifndef GR_SECURITY_H
78047+#define GR_SECURITY_H
78048+#include <linux/fs.h>
78049+#include <linux/fs_struct.h>
78050+#include <linux/binfmts.h>
78051+#include <linux/gracl.h>
78052+
78053+/* notify of brain-dead configs */
78054+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78055+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
78056+#endif
78057+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
78058+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
78059+#endif
78060+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
78061+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
78062+#endif
78063+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
78064+#error "CONFIG_PAX enabled, but no PaX options are enabled."
78065+#endif
78066+
78067+int gr_handle_new_usb(void);
78068+
78069+void gr_handle_brute_attach(int dumpable);
78070+void gr_handle_brute_check(void);
78071+void gr_handle_kernel_exploit(void);
78072+
78073+char gr_roletype_to_char(void);
78074+
78075+int gr_acl_enable_at_secure(void);
78076+
78077+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
78078+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
78079+
78080+void gr_del_task_from_ip_table(struct task_struct *p);
78081+
78082+int gr_pid_is_chrooted(struct task_struct *p);
78083+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
78084+int gr_handle_chroot_nice(void);
78085+int gr_handle_chroot_sysctl(const int op);
78086+int gr_handle_chroot_setpriority(struct task_struct *p,
78087+ const int niceval);
78088+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
78089+int gr_handle_chroot_chroot(const struct dentry *dentry,
78090+ const struct vfsmount *mnt);
78091+void gr_handle_chroot_chdir(const struct path *path);
78092+int gr_handle_chroot_chmod(const struct dentry *dentry,
78093+ const struct vfsmount *mnt, const int mode);
78094+int gr_handle_chroot_mknod(const struct dentry *dentry,
78095+ const struct vfsmount *mnt, const int mode);
78096+int gr_handle_chroot_mount(const struct dentry *dentry,
78097+ const struct vfsmount *mnt,
78098+ const char *dev_name);
78099+int gr_handle_chroot_pivot(void);
78100+int gr_handle_chroot_unix(const pid_t pid);
78101+
78102+int gr_handle_rawio(const struct inode *inode);
78103+
78104+void gr_handle_ioperm(void);
78105+void gr_handle_iopl(void);
78106+
78107+umode_t gr_acl_umask(void);
78108+
78109+int gr_tpe_allow(const struct file *file);
78110+
78111+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
78112+void gr_clear_chroot_entries(struct task_struct *task);
78113+
78114+void gr_log_forkfail(const int retval);
78115+void gr_log_timechange(void);
78116+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
78117+void gr_log_chdir(const struct dentry *dentry,
78118+ const struct vfsmount *mnt);
78119+void gr_log_chroot_exec(const struct dentry *dentry,
78120+ const struct vfsmount *mnt);
78121+void gr_log_remount(const char *devname, const int retval);
78122+void gr_log_unmount(const char *devname, const int retval);
78123+void gr_log_mount(const char *from, const char *to, const int retval);
78124+void gr_log_textrel(struct vm_area_struct *vma);
78125+void gr_log_ptgnustack(struct file *file);
78126+void gr_log_rwxmmap(struct file *file);
78127+void gr_log_rwxmprotect(struct vm_area_struct *vma);
78128+
78129+int gr_handle_follow_link(const struct inode *parent,
78130+ const struct inode *inode,
78131+ const struct dentry *dentry,
78132+ const struct vfsmount *mnt);
78133+int gr_handle_fifo(const struct dentry *dentry,
78134+ const struct vfsmount *mnt,
78135+ const struct dentry *dir, const int flag,
78136+ const int acc_mode);
78137+int gr_handle_hardlink(const struct dentry *dentry,
78138+ const struct vfsmount *mnt,
78139+ struct inode *inode,
78140+ const int mode, const struct filename *to);
78141+
78142+int gr_is_capable(const int cap);
78143+int gr_is_capable_nolog(const int cap);
78144+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
78145+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
78146+
78147+void gr_copy_label(struct task_struct *tsk);
78148+void gr_handle_crash(struct task_struct *task, const int sig);
78149+int gr_handle_signal(const struct task_struct *p, const int sig);
78150+int gr_check_crash_uid(const kuid_t uid);
78151+int gr_check_protected_task(const struct task_struct *task);
78152+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
78153+int gr_acl_handle_mmap(const struct file *file,
78154+ const unsigned long prot);
78155+int gr_acl_handle_mprotect(const struct file *file,
78156+ const unsigned long prot);
78157+int gr_check_hidden_task(const struct task_struct *tsk);
78158+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
78159+ const struct vfsmount *mnt);
78160+__u32 gr_acl_handle_utime(const struct dentry *dentry,
78161+ const struct vfsmount *mnt);
78162+__u32 gr_acl_handle_access(const struct dentry *dentry,
78163+ const struct vfsmount *mnt, const int fmode);
78164+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
78165+ const struct vfsmount *mnt, umode_t *mode);
78166+__u32 gr_acl_handle_chown(const struct dentry *dentry,
78167+ const struct vfsmount *mnt);
78168+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
78169+ const struct vfsmount *mnt);
78170+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
78171+ const struct vfsmount *mnt);
78172+int gr_handle_ptrace(struct task_struct *task, const long request);
78173+int gr_handle_proc_ptrace(struct task_struct *task);
78174+__u32 gr_acl_handle_execve(const struct dentry *dentry,
78175+ const struct vfsmount *mnt);
78176+int gr_check_crash_exec(const struct file *filp);
78177+int gr_acl_is_enabled(void);
78178+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
78179+ const kgid_t gid);
78180+int gr_set_proc_label(const struct dentry *dentry,
78181+ const struct vfsmount *mnt,
78182+ const int unsafe_flags);
78183+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
78184+ const struct vfsmount *mnt);
78185+__u32 gr_acl_handle_open(const struct dentry *dentry,
78186+ const struct vfsmount *mnt, int acc_mode);
78187+__u32 gr_acl_handle_creat(const struct dentry *dentry,
78188+ const struct dentry *p_dentry,
78189+ const struct vfsmount *p_mnt,
78190+ int open_flags, int acc_mode, const int imode);
78191+void gr_handle_create(const struct dentry *dentry,
78192+ const struct vfsmount *mnt);
78193+void gr_handle_proc_create(const struct dentry *dentry,
78194+ const struct inode *inode);
78195+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
78196+ const struct dentry *parent_dentry,
78197+ const struct vfsmount *parent_mnt,
78198+ const int mode);
78199+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
78200+ const struct dentry *parent_dentry,
78201+ const struct vfsmount *parent_mnt);
78202+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
78203+ const struct vfsmount *mnt);
78204+void gr_handle_delete(const ino_t ino, const dev_t dev);
78205+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
78206+ const struct vfsmount *mnt);
78207+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
78208+ const struct dentry *parent_dentry,
78209+ const struct vfsmount *parent_mnt,
78210+ const struct filename *from);
78211+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
78212+ const struct dentry *parent_dentry,
78213+ const struct vfsmount *parent_mnt,
78214+ const struct dentry *old_dentry,
78215+ const struct vfsmount *old_mnt, const struct filename *to);
78216+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
78217+int gr_acl_handle_rename(struct dentry *new_dentry,
78218+ struct dentry *parent_dentry,
78219+ const struct vfsmount *parent_mnt,
78220+ struct dentry *old_dentry,
78221+ struct inode *old_parent_inode,
78222+ struct vfsmount *old_mnt, const struct filename *newname);
78223+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
78224+ struct dentry *old_dentry,
78225+ struct dentry *new_dentry,
78226+ struct vfsmount *mnt, const __u8 replace);
78227+__u32 gr_check_link(const struct dentry *new_dentry,
78228+ const struct dentry *parent_dentry,
78229+ const struct vfsmount *parent_mnt,
78230+ const struct dentry *old_dentry,
78231+ const struct vfsmount *old_mnt);
78232+int gr_acl_handle_filldir(const struct file *file, const char *name,
78233+ const unsigned int namelen, const ino_t ino);
78234+
78235+__u32 gr_acl_handle_unix(const struct dentry *dentry,
78236+ const struct vfsmount *mnt);
78237+void gr_acl_handle_exit(void);
78238+void gr_acl_handle_psacct(struct task_struct *task, const long code);
78239+int gr_acl_handle_procpidmem(const struct task_struct *task);
78240+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
78241+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
78242+void gr_audit_ptrace(struct task_struct *task);
78243+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
78244+void gr_put_exec_file(struct task_struct *task);
78245+
78246+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
78247+
78248+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
78249+extern void gr_learn_resource(const struct task_struct *task, const int res,
78250+ const unsigned long wanted, const int gt);
78251+#else
78252+static inline void gr_learn_resource(const struct task_struct *task, const int res,
78253+ const unsigned long wanted, const int gt)
78254+{
78255+}
78256+#endif
78257+
78258+#ifdef CONFIG_GRKERNSEC_RESLOG
78259+extern void gr_log_resource(const struct task_struct *task, const int res,
78260+ const unsigned long wanted, const int gt);
78261+#else
78262+static inline void gr_log_resource(const struct task_struct *task, const int res,
78263+ const unsigned long wanted, const int gt)
78264+{
78265+}
78266+#endif
78267+
78268+#ifdef CONFIG_GRKERNSEC
78269+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
78270+void gr_handle_vm86(void);
78271+void gr_handle_mem_readwrite(u64 from, u64 to);
78272+
78273+void gr_log_badprocpid(const char *entry);
78274+
78275+extern int grsec_enable_dmesg;
78276+extern int grsec_disable_privio;
78277+
78278+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
78279+extern kgid_t grsec_proc_gid;
78280+#endif
78281+
78282+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
78283+extern int grsec_enable_chroot_findtask;
78284+#endif
78285+#ifdef CONFIG_GRKERNSEC_SETXID
78286+extern int grsec_enable_setxid;
78287+#endif
78288+#endif
78289+
78290+#endif
78291diff --git a/include/linux/grsock.h b/include/linux/grsock.h
78292new file mode 100644
78293index 0000000..e7ffaaf
78294--- /dev/null
78295+++ b/include/linux/grsock.h
78296@@ -0,0 +1,19 @@
78297+#ifndef __GRSOCK_H
78298+#define __GRSOCK_H
78299+
78300+extern void gr_attach_curr_ip(const struct sock *sk);
78301+extern int gr_handle_sock_all(const int family, const int type,
78302+ const int protocol);
78303+extern int gr_handle_sock_server(const struct sockaddr *sck);
78304+extern int gr_handle_sock_server_other(const struct sock *sck);
78305+extern int gr_handle_sock_client(const struct sockaddr *sck);
78306+extern int gr_search_connect(struct socket * sock,
78307+ struct sockaddr_in * addr);
78308+extern int gr_search_bind(struct socket * sock,
78309+ struct sockaddr_in * addr);
78310+extern int gr_search_listen(struct socket * sock);
78311+extern int gr_search_accept(struct socket * sock);
78312+extern int gr_search_socket(const int domain, const int type,
78313+ const int protocol);
78314+
78315+#endif
78316diff --git a/include/linux/highmem.h b/include/linux/highmem.h
78317index 7fb31da..08b5114 100644
78318--- a/include/linux/highmem.h
78319+++ b/include/linux/highmem.h
78320@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
78321 kunmap_atomic(kaddr);
78322 }
78323
78324+static inline void sanitize_highpage(struct page *page)
78325+{
78326+ void *kaddr;
78327+ unsigned long flags;
78328+
78329+ local_irq_save(flags);
78330+ kaddr = kmap_atomic(page);
78331+ clear_page(kaddr);
78332+ kunmap_atomic(kaddr);
78333+ local_irq_restore(flags);
78334+}
78335+
78336 static inline void zero_user_segments(struct page *page,
78337 unsigned start1, unsigned end1,
78338 unsigned start2, unsigned end2)
78339diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
78340index 1c7b89a..7dda400 100644
78341--- a/include/linux/hwmon-sysfs.h
78342+++ b/include/linux/hwmon-sysfs.h
78343@@ -25,7 +25,8 @@
78344 struct sensor_device_attribute{
78345 struct device_attribute dev_attr;
78346 int index;
78347-};
78348+} __do_const;
78349+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
78350 #define to_sensor_dev_attr(_dev_attr) \
78351 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
78352
78353@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
78354 struct device_attribute dev_attr;
78355 u8 index;
78356 u8 nr;
78357-};
78358+} __do_const;
78359+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
78360 #define to_sensor_dev_attr_2(_dev_attr) \
78361 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
78362
78363diff --git a/include/linux/i2c.h b/include/linux/i2c.h
78364index d9c8dbd3..def6e5a 100644
78365--- a/include/linux/i2c.h
78366+++ b/include/linux/i2c.h
78367@@ -364,6 +364,7 @@ struct i2c_algorithm {
78368 /* To determine what the adapter supports */
78369 u32 (*functionality) (struct i2c_adapter *);
78370 };
78371+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
78372
78373 /**
78374 * struct i2c_bus_recovery_info - I2C bus recovery information
78375diff --git a/include/linux/i2o.h b/include/linux/i2o.h
78376index d23c3c2..eb63c81 100644
78377--- a/include/linux/i2o.h
78378+++ b/include/linux/i2o.h
78379@@ -565,7 +565,7 @@ struct i2o_controller {
78380 struct i2o_device *exec; /* Executive */
78381 #if BITS_PER_LONG == 64
78382 spinlock_t context_list_lock; /* lock for context_list */
78383- atomic_t context_list_counter; /* needed for unique contexts */
78384+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
78385 struct list_head context_list; /* list of context id's
78386 and pointers */
78387 #endif
78388diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
78389index aff7ad8..3942bbd 100644
78390--- a/include/linux/if_pppox.h
78391+++ b/include/linux/if_pppox.h
78392@@ -76,7 +76,7 @@ struct pppox_proto {
78393 int (*ioctl)(struct socket *sock, unsigned int cmd,
78394 unsigned long arg);
78395 struct module *owner;
78396-};
78397+} __do_const;
78398
78399 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
78400 extern void unregister_pppox_proto(int proto_num);
78401diff --git a/include/linux/init.h b/include/linux/init.h
78402index 8e68a64..3f977a0 100644
78403--- a/include/linux/init.h
78404+++ b/include/linux/init.h
78405@@ -37,9 +37,17 @@
78406 * section.
78407 */
78408
78409+#define add_init_latent_entropy __latent_entropy
78410+
78411+#ifdef CONFIG_MEMORY_HOTPLUG
78412+#define add_meminit_latent_entropy
78413+#else
78414+#define add_meminit_latent_entropy __latent_entropy
78415+#endif
78416+
78417 /* These are for everybody (although not all archs will actually
78418 discard it in modules) */
78419-#define __init __section(.init.text) __cold notrace
78420+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
78421 #define __initdata __section(.init.data)
78422 #define __initconst __constsection(.init.rodata)
78423 #define __exitdata __section(.exit.data)
78424@@ -100,7 +108,7 @@
78425 #define __cpuexitconst
78426
78427 /* Used for MEMORY_HOTPLUG */
78428-#define __meminit __section(.meminit.text) __cold notrace
78429+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
78430 #define __meminitdata __section(.meminit.data)
78431 #define __meminitconst __constsection(.meminit.rodata)
78432 #define __memexit __section(.memexit.text) __exitused __cold notrace
78433diff --git a/include/linux/init_task.h b/include/linux/init_task.h
78434index b0ed422..d79ea23 100644
78435--- a/include/linux/init_task.h
78436+++ b/include/linux/init_task.h
78437@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
78438
78439 #define INIT_TASK_COMM "swapper"
78440
78441+#ifdef CONFIG_X86
78442+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
78443+#else
78444+#define INIT_TASK_THREAD_INFO
78445+#endif
78446+
78447 /*
78448 * INIT_TASK is used to set up the first task table, touch at
78449 * your own risk!. Base=0, limit=0x1fffff (=2MB)
78450@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
78451 RCU_POINTER_INITIALIZER(cred, &init_cred), \
78452 .comm = INIT_TASK_COMM, \
78453 .thread = INIT_THREAD, \
78454+ INIT_TASK_THREAD_INFO \
78455 .fs = &init_fs, \
78456 .files = &init_files, \
78457 .signal = &init_signals, \
78458diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
78459index db43b58..5d5084b 100644
78460--- a/include/linux/interrupt.h
78461+++ b/include/linux/interrupt.h
78462@@ -360,7 +360,7 @@ enum
78463 /* map softirq index to softirq name. update 'softirq_to_name' in
78464 * kernel/softirq.c when adding a new softirq.
78465 */
78466-extern char *softirq_to_name[NR_SOFTIRQS];
78467+extern const char * const softirq_to_name[NR_SOFTIRQS];
78468
78469 /* softirq mask and active fields moved to irq_cpustat_t in
78470 * asm/hardirq.h to get better cache usage. KAO
78471@@ -368,8 +368,8 @@ extern char *softirq_to_name[NR_SOFTIRQS];
78472
78473 struct softirq_action
78474 {
78475- void (*action)(struct softirq_action *);
78476-};
78477+ void (*action)(void);
78478+} __no_const;
78479
78480 asmlinkage void do_softirq(void);
78481 asmlinkage void __do_softirq(void);
78482@@ -383,7 +383,7 @@ static inline void do_softirq_own_stack(void)
78483 }
78484 #endif
78485
78486-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
78487+extern void open_softirq(int nr, void (*action)(void));
78488 extern void softirq_init(void);
78489 extern void __raise_softirq_irqoff(unsigned int nr);
78490
78491diff --git a/include/linux/iommu.h b/include/linux/iommu.h
78492index a444c79..8c41ea9 100644
78493--- a/include/linux/iommu.h
78494+++ b/include/linux/iommu.h
78495@@ -130,7 +130,7 @@ struct iommu_ops {
78496 u32 (*domain_get_windows)(struct iommu_domain *domain);
78497
78498 unsigned long pgsize_bitmap;
78499-};
78500+} __do_const;
78501
78502 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
78503 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
78504diff --git a/include/linux/ioport.h b/include/linux/ioport.h
78505index 89b7c24..382af74 100644
78506--- a/include/linux/ioport.h
78507+++ b/include/linux/ioport.h
78508@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
78509 int adjust_resource(struct resource *res, resource_size_t start,
78510 resource_size_t size);
78511 resource_size_t resource_alignment(struct resource *res);
78512-static inline resource_size_t resource_size(const struct resource *res)
78513+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
78514 {
78515 return res->end - res->start + 1;
78516 }
78517diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
78518index f6c82de..de8619e 100644
78519--- a/include/linux/ipc_namespace.h
78520+++ b/include/linux/ipc_namespace.h
78521@@ -70,7 +70,7 @@ struct ipc_namespace {
78522 struct user_namespace *user_ns;
78523
78524 unsigned int proc_inum;
78525-};
78526+} __randomize_layout;
78527
78528 extern struct ipc_namespace init_ipc_ns;
78529 extern atomic_t nr_ipc_ns;
78530diff --git a/include/linux/irq.h b/include/linux/irq.h
78531index 7dc1003..407327b 100644
78532--- a/include/linux/irq.h
78533+++ b/include/linux/irq.h
78534@@ -338,7 +338,8 @@ struct irq_chip {
78535 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
78536
78537 unsigned long flags;
78538-};
78539+} __do_const;
78540+typedef struct irq_chip __no_const irq_chip_no_const;
78541
78542 /*
78543 * irq_chip specific flags
78544diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
78545index cac496b..ffa0567 100644
78546--- a/include/linux/irqchip/arm-gic.h
78547+++ b/include/linux/irqchip/arm-gic.h
78548@@ -61,9 +61,11 @@
78549
78550 #ifndef __ASSEMBLY__
78551
78552+#include <linux/irq.h>
78553+
78554 struct device_node;
78555
78556-extern struct irq_chip gic_arch_extn;
78557+extern irq_chip_no_const gic_arch_extn;
78558
78559 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
78560 u32 offset, struct device_node *);
78561diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
78562index d235e88..8ccbe74 100644
78563--- a/include/linux/jiffies.h
78564+++ b/include/linux/jiffies.h
78565@@ -292,14 +292,14 @@ extern unsigned long preset_lpj;
78566 /*
78567 * Convert various time units to each other:
78568 */
78569-extern unsigned int jiffies_to_msecs(const unsigned long j);
78570-extern unsigned int jiffies_to_usecs(const unsigned long j);
78571-extern unsigned long msecs_to_jiffies(const unsigned int m);
78572-extern unsigned long usecs_to_jiffies(const unsigned int u);
78573-extern unsigned long timespec_to_jiffies(const struct timespec *value);
78574+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
78575+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
78576+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
78577+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
78578+extern unsigned long timespec_to_jiffies(const struct timespec *value) __intentional_overflow(-1);
78579 extern void jiffies_to_timespec(const unsigned long jiffies,
78580 struct timespec *value);
78581-extern unsigned long timeval_to_jiffies(const struct timeval *value);
78582+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
78583 extern void jiffies_to_timeval(const unsigned long jiffies,
78584 struct timeval *value);
78585
78586diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
78587index 6883e19..e854fcb 100644
78588--- a/include/linux/kallsyms.h
78589+++ b/include/linux/kallsyms.h
78590@@ -15,7 +15,8 @@
78591
78592 struct module;
78593
78594-#ifdef CONFIG_KALLSYMS
78595+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
78596+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
78597 /* Lookup the address for a symbol. Returns 0 if not found. */
78598 unsigned long kallsyms_lookup_name(const char *name);
78599
78600@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
78601 /* Stupid that this does nothing, but I didn't create this mess. */
78602 #define __print_symbol(fmt, addr)
78603 #endif /*CONFIG_KALLSYMS*/
78604+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
78605+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
78606+extern unsigned long kallsyms_lookup_name(const char *name);
78607+extern void __print_symbol(const char *fmt, unsigned long address);
78608+extern int sprint_backtrace(char *buffer, unsigned long address);
78609+extern int sprint_symbol(char *buffer, unsigned long address);
78610+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
78611+const char *kallsyms_lookup(unsigned long addr,
78612+ unsigned long *symbolsize,
78613+ unsigned long *offset,
78614+ char **modname, char *namebuf);
78615+extern int kallsyms_lookup_size_offset(unsigned long addr,
78616+ unsigned long *symbolsize,
78617+ unsigned long *offset);
78618+#endif
78619
78620 /* This macro allows us to keep printk typechecking */
78621 static __printf(1, 2)
78622diff --git a/include/linux/key-type.h b/include/linux/key-type.h
78623index a74c3a8..28d3f21 100644
78624--- a/include/linux/key-type.h
78625+++ b/include/linux/key-type.h
78626@@ -131,7 +131,7 @@ struct key_type {
78627 /* internal fields */
78628 struct list_head link; /* link in types list */
78629 struct lock_class_key lock_class; /* key->sem lock class */
78630-};
78631+} __do_const;
78632
78633 extern struct key_type key_type_keyring;
78634
78635diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
78636index dfb4f2f..7927e62 100644
78637--- a/include/linux/kgdb.h
78638+++ b/include/linux/kgdb.h
78639@@ -52,7 +52,7 @@ extern int kgdb_connected;
78640 extern int kgdb_io_module_registered;
78641
78642 extern atomic_t kgdb_setting_breakpoint;
78643-extern atomic_t kgdb_cpu_doing_single_step;
78644+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
78645
78646 extern struct task_struct *kgdb_usethread;
78647 extern struct task_struct *kgdb_contthread;
78648@@ -254,7 +254,7 @@ struct kgdb_arch {
78649 void (*correct_hw_break)(void);
78650
78651 void (*enable_nmi)(bool on);
78652-};
78653+} __do_const;
78654
78655 /**
78656 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
78657@@ -279,7 +279,7 @@ struct kgdb_io {
78658 void (*pre_exception) (void);
78659 void (*post_exception) (void);
78660 int is_console;
78661-};
78662+} __do_const;
78663
78664 extern struct kgdb_arch arch_kgdb_ops;
78665
78666diff --git a/include/linux/kmod.h b/include/linux/kmod.h
78667index 0555cc6..40116ce 100644
78668--- a/include/linux/kmod.h
78669+++ b/include/linux/kmod.h
78670@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
78671 * usually useless though. */
78672 extern __printf(2, 3)
78673 int __request_module(bool wait, const char *name, ...);
78674+extern __printf(3, 4)
78675+int ___request_module(bool wait, char *param_name, const char *name, ...);
78676 #define request_module(mod...) __request_module(true, mod)
78677 #define request_module_nowait(mod...) __request_module(false, mod)
78678 #define try_then_request_module(x, mod...) \
78679@@ -57,6 +59,9 @@ struct subprocess_info {
78680 struct work_struct work;
78681 struct completion *complete;
78682 char *path;
78683+#ifdef CONFIG_GRKERNSEC
78684+ char *origpath;
78685+#endif
78686 char **argv;
78687 char **envp;
78688 int wait;
78689diff --git a/include/linux/kobject.h b/include/linux/kobject.h
78690index e7ba650..0af3acb 100644
78691--- a/include/linux/kobject.h
78692+++ b/include/linux/kobject.h
78693@@ -116,7 +116,7 @@ struct kobj_type {
78694 struct attribute **default_attrs;
78695 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
78696 const void *(*namespace)(struct kobject *kobj);
78697-};
78698+} __do_const;
78699
78700 struct kobj_uevent_env {
78701 char *envp[UEVENT_NUM_ENVP];
78702@@ -139,6 +139,7 @@ struct kobj_attribute {
78703 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
78704 const char *buf, size_t count);
78705 };
78706+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
78707
78708 extern const struct sysfs_ops kobj_sysfs_ops;
78709
78710@@ -166,7 +167,7 @@ struct kset {
78711 spinlock_t list_lock;
78712 struct kobject kobj;
78713 const struct kset_uevent_ops *uevent_ops;
78714-};
78715+} __randomize_layout;
78716
78717 extern void kset_init(struct kset *kset);
78718 extern int __must_check kset_register(struct kset *kset);
78719diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
78720index df32d25..fb52e27 100644
78721--- a/include/linux/kobject_ns.h
78722+++ b/include/linux/kobject_ns.h
78723@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
78724 const void *(*netlink_ns)(struct sock *sk);
78725 const void *(*initial_ns)(void);
78726 void (*drop_ns)(void *);
78727-};
78728+} __do_const;
78729
78730 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
78731 int kobj_ns_type_registered(enum kobj_ns_type type);
78732diff --git a/include/linux/kref.h b/include/linux/kref.h
78733index 484604d..0f6c5b6 100644
78734--- a/include/linux/kref.h
78735+++ b/include/linux/kref.h
78736@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
78737 static inline int kref_sub(struct kref *kref, unsigned int count,
78738 void (*release)(struct kref *kref))
78739 {
78740- WARN_ON(release == NULL);
78741+ BUG_ON(release == NULL);
78742
78743 if (atomic_sub_and_test((int) count, &kref->refcount)) {
78744 release(kref);
78745diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
78746index 9523d2a..16c0424 100644
78747--- a/include/linux/kvm_host.h
78748+++ b/include/linux/kvm_host.h
78749@@ -457,7 +457,7 @@ static inline void kvm_irqfd_exit(void)
78750 {
78751 }
78752 #endif
78753-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
78754+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
78755 struct module *module);
78756 void kvm_exit(void);
78757
78758@@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
78759 struct kvm_guest_debug *dbg);
78760 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
78761
78762-int kvm_arch_init(void *opaque);
78763+int kvm_arch_init(const void *opaque);
78764 void kvm_arch_exit(void);
78765
78766 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
78767diff --git a/include/linux/libata.h b/include/linux/libata.h
78768index bec6dbe..2873d64 100644
78769--- a/include/linux/libata.h
78770+++ b/include/linux/libata.h
78771@@ -975,7 +975,7 @@ struct ata_port_operations {
78772 * fields must be pointers.
78773 */
78774 const struct ata_port_operations *inherits;
78775-};
78776+} __do_const;
78777
78778 struct ata_port_info {
78779 unsigned long flags;
78780diff --git a/include/linux/linkage.h b/include/linux/linkage.h
78781index d3e8ad2..a949f68 100644
78782--- a/include/linux/linkage.h
78783+++ b/include/linux/linkage.h
78784@@ -31,6 +31,7 @@
78785 #endif
78786
78787 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
78788+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
78789 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
78790
78791 /*
78792diff --git a/include/linux/list.h b/include/linux/list.h
78793index ef95941..82db65a 100644
78794--- a/include/linux/list.h
78795+++ b/include/linux/list.h
78796@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
78797 extern void list_del(struct list_head *entry);
78798 #endif
78799
78800+extern void __pax_list_add(struct list_head *new,
78801+ struct list_head *prev,
78802+ struct list_head *next);
78803+static inline void pax_list_add(struct list_head *new, struct list_head *head)
78804+{
78805+ __pax_list_add(new, head, head->next);
78806+}
78807+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
78808+{
78809+ __pax_list_add(new, head->prev, head);
78810+}
78811+extern void pax_list_del(struct list_head *entry);
78812+
78813 /**
78814 * list_replace - replace old entry by new one
78815 * @old : the element to be replaced
78816@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
78817 INIT_LIST_HEAD(entry);
78818 }
78819
78820+extern void pax_list_del_init(struct list_head *entry);
78821+
78822 /**
78823 * list_move - delete from one list and add as another's head
78824 * @list: the entry to move
78825diff --git a/include/linux/math64.h b/include/linux/math64.h
78826index c45c089..298841c 100644
78827--- a/include/linux/math64.h
78828+++ b/include/linux/math64.h
78829@@ -15,7 +15,7 @@
78830 * This is commonly provided by 32bit archs to provide an optimized 64bit
78831 * divide.
78832 */
78833-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78834+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78835 {
78836 *remainder = dividend % divisor;
78837 return dividend / divisor;
78838@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
78839 /**
78840 * div64_u64 - unsigned 64bit divide with 64bit divisor
78841 */
78842-static inline u64 div64_u64(u64 dividend, u64 divisor)
78843+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
78844 {
78845 return dividend / divisor;
78846 }
78847@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
78848 #define div64_ul(x, y) div_u64((x), (y))
78849
78850 #ifndef div_u64_rem
78851-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78852+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78853 {
78854 *remainder = do_div(dividend, divisor);
78855 return dividend;
78856@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
78857 #endif
78858
78859 #ifndef div64_u64
78860-extern u64 div64_u64(u64 dividend, u64 divisor);
78861+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
78862 #endif
78863
78864 #ifndef div64_s64
78865@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
78866 * divide.
78867 */
78868 #ifndef div_u64
78869-static inline u64 div_u64(u64 dividend, u32 divisor)
78870+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
78871 {
78872 u32 remainder;
78873 return div_u64_rem(dividend, divisor, &remainder);
78874diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
78875index 9fe426b..8148be6 100644
78876--- a/include/linux/mempolicy.h
78877+++ b/include/linux/mempolicy.h
78878@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
78879 }
78880
78881 #define vma_policy(vma) ((vma)->vm_policy)
78882+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
78883+{
78884+ vma->vm_policy = pol;
78885+}
78886
78887 static inline void mpol_get(struct mempolicy *pol)
78888 {
78889@@ -241,6 +245,9 @@ mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
78890 }
78891
78892 #define vma_policy(vma) NULL
78893+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
78894+{
78895+}
78896
78897 static inline int
78898 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
78899diff --git a/include/linux/mm.h b/include/linux/mm.h
78900index 9fac6dd..158ca43 100644
78901--- a/include/linux/mm.h
78902+++ b/include/linux/mm.h
78903@@ -117,6 +117,11 @@ extern unsigned int kobjsize(const void *objp);
78904 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
78905 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
78906 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
78907+
78908+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
78909+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
78910+#endif
78911+
78912 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
78913
78914 #ifdef CONFIG_MEM_SOFT_DIRTY
78915@@ -219,8 +224,8 @@ struct vm_operations_struct {
78916 /* called by access_process_vm when get_user_pages() fails, typically
78917 * for use by special VMAs that can switch between memory and hardware
78918 */
78919- int (*access)(struct vm_area_struct *vma, unsigned long addr,
78920- void *buf, int len, int write);
78921+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
78922+ void *buf, size_t len, int write);
78923 #ifdef CONFIG_NUMA
78924 /*
78925 * set_policy() op must add a reference to any non-NULL @new mempolicy
78926@@ -250,6 +255,7 @@ struct vm_operations_struct {
78927 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
78928 unsigned long size, pgoff_t pgoff);
78929 };
78930+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
78931
78932 struct mmu_gather;
78933 struct inode;
78934@@ -1064,8 +1070,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
78935 unsigned long *pfn);
78936 int follow_phys(struct vm_area_struct *vma, unsigned long address,
78937 unsigned int flags, unsigned long *prot, resource_size_t *phys);
78938-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
78939- void *buf, int len, int write);
78940+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
78941+ void *buf, size_t len, int write);
78942
78943 static inline void unmap_shared_mapping_range(struct address_space *mapping,
78944 loff_t const holebegin, loff_t const holelen)
78945@@ -1104,9 +1110,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
78946 }
78947 #endif
78948
78949-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
78950-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
78951- void *buf, int len, int write);
78952+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
78953+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
78954+ void *buf, size_t len, int write);
78955
78956 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
78957 unsigned long start, unsigned long nr_pages,
78958@@ -1138,34 +1144,6 @@ int set_page_dirty(struct page *page);
78959 int set_page_dirty_lock(struct page *page);
78960 int clear_page_dirty_for_io(struct page *page);
78961
78962-/* Is the vma a continuation of the stack vma above it? */
78963-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
78964-{
78965- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
78966-}
78967-
78968-static inline int stack_guard_page_start(struct vm_area_struct *vma,
78969- unsigned long addr)
78970-{
78971- return (vma->vm_flags & VM_GROWSDOWN) &&
78972- (vma->vm_start == addr) &&
78973- !vma_growsdown(vma->vm_prev, addr);
78974-}
78975-
78976-/* Is the vma a continuation of the stack vma below it? */
78977-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
78978-{
78979- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
78980-}
78981-
78982-static inline int stack_guard_page_end(struct vm_area_struct *vma,
78983- unsigned long addr)
78984-{
78985- return (vma->vm_flags & VM_GROWSUP) &&
78986- (vma->vm_end == addr) &&
78987- !vma_growsup(vma->vm_next, addr);
78988-}
78989-
78990 extern pid_t
78991 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
78992
78993@@ -1265,6 +1243,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
78994 }
78995 #endif
78996
78997+#ifdef CONFIG_MMU
78998+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
78999+#else
79000+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
79001+{
79002+ return __pgprot(0);
79003+}
79004+#endif
79005+
79006 int vma_wants_writenotify(struct vm_area_struct *vma);
79007
79008 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
79009@@ -1283,8 +1270,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
79010 {
79011 return 0;
79012 }
79013+
79014+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
79015+ unsigned long address)
79016+{
79017+ return 0;
79018+}
79019 #else
79020 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
79021+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
79022 #endif
79023
79024 #ifdef __PAGETABLE_PMD_FOLDED
79025@@ -1293,8 +1287,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
79026 {
79027 return 0;
79028 }
79029+
79030+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
79031+ unsigned long address)
79032+{
79033+ return 0;
79034+}
79035 #else
79036 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
79037+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
79038 #endif
79039
79040 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
79041@@ -1312,11 +1313,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
79042 NULL: pud_offset(pgd, address);
79043 }
79044
79045+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
79046+{
79047+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
79048+ NULL: pud_offset(pgd, address);
79049+}
79050+
79051 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
79052 {
79053 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
79054 NULL: pmd_offset(pud, address);
79055 }
79056+
79057+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
79058+{
79059+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
79060+ NULL: pmd_offset(pud, address);
79061+}
79062 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
79063
79064 #if USE_SPLIT_PTE_PTLOCKS
79065@@ -1694,7 +1707,7 @@ extern int install_special_mapping(struct mm_struct *mm,
79066 unsigned long addr, unsigned long len,
79067 unsigned long flags, struct page **pages);
79068
79069-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
79070+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
79071
79072 extern unsigned long mmap_region(struct file *file, unsigned long addr,
79073 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
79074@@ -1702,6 +1715,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
79075 unsigned long len, unsigned long prot, unsigned long flags,
79076 unsigned long pgoff, unsigned long *populate);
79077 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
79078+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
79079
79080 #ifdef CONFIG_MMU
79081 extern int __mm_populate(unsigned long addr, unsigned long len,
79082@@ -1730,10 +1744,11 @@ struct vm_unmapped_area_info {
79083 unsigned long high_limit;
79084 unsigned long align_mask;
79085 unsigned long align_offset;
79086+ unsigned long threadstack_offset;
79087 };
79088
79089-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
79090-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
79091+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
79092+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
79093
79094 /*
79095 * Search for an unmapped address range.
79096@@ -1745,7 +1760,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
79097 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
79098 */
79099 static inline unsigned long
79100-vm_unmapped_area(struct vm_unmapped_area_info *info)
79101+vm_unmapped_area(const struct vm_unmapped_area_info *info)
79102 {
79103 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
79104 return unmapped_area(info);
79105@@ -1808,6 +1823,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
79106 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
79107 struct vm_area_struct **pprev);
79108
79109+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
79110+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
79111+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
79112+
79113 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
79114 NULL if none. Assume start_addr < end_addr. */
79115 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
79116@@ -1836,15 +1855,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
79117 return vma;
79118 }
79119
79120-#ifdef CONFIG_MMU
79121-pgprot_t vm_get_page_prot(unsigned long vm_flags);
79122-#else
79123-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
79124-{
79125- return __pgprot(0);
79126-}
79127-#endif
79128-
79129 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
79130 unsigned long change_prot_numa(struct vm_area_struct *vma,
79131 unsigned long start, unsigned long end);
79132@@ -1896,6 +1906,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
79133 static inline void vm_stat_account(struct mm_struct *mm,
79134 unsigned long flags, struct file *file, long pages)
79135 {
79136+
79137+#ifdef CONFIG_PAX_RANDMMAP
79138+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
79139+#endif
79140+
79141 mm->total_vm += pages;
79142 }
79143 #endif /* CONFIG_PROC_FS */
79144@@ -1977,7 +1992,7 @@ extern int unpoison_memory(unsigned long pfn);
79145 extern int sysctl_memory_failure_early_kill;
79146 extern int sysctl_memory_failure_recovery;
79147 extern void shake_page(struct page *p, int access);
79148-extern atomic_long_t num_poisoned_pages;
79149+extern atomic_long_unchecked_t num_poisoned_pages;
79150 extern int soft_offline_page(struct page *page, int flags);
79151
79152 extern void dump_page(struct page *page);
79153@@ -2014,5 +2029,11 @@ void __init setup_nr_node_ids(void);
79154 static inline void setup_nr_node_ids(void) {}
79155 #endif
79156
79157+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
79158+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
79159+#else
79160+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
79161+#endif
79162+
79163 #endif /* __KERNEL__ */
79164 #endif /* _LINUX_MM_H */
79165diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
79166index 290901a..e99b01c 100644
79167--- a/include/linux/mm_types.h
79168+++ b/include/linux/mm_types.h
79169@@ -307,7 +307,9 @@ struct vm_area_struct {
79170 #ifdef CONFIG_NUMA
79171 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
79172 #endif
79173-};
79174+
79175+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
79176+} __randomize_layout;
79177
79178 struct core_thread {
79179 struct task_struct *task;
79180@@ -453,7 +455,25 @@ struct mm_struct {
79181 bool tlb_flush_pending;
79182 #endif
79183 struct uprobes_state uprobes_state;
79184-};
79185+
79186+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
79187+ unsigned long pax_flags;
79188+#endif
79189+
79190+#ifdef CONFIG_PAX_DLRESOLVE
79191+ unsigned long call_dl_resolve;
79192+#endif
79193+
79194+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
79195+ unsigned long call_syscall;
79196+#endif
79197+
79198+#ifdef CONFIG_PAX_ASLR
79199+ unsigned long delta_mmap; /* randomized offset */
79200+ unsigned long delta_stack; /* randomized offset */
79201+#endif
79202+
79203+} __randomize_layout;
79204
79205 static inline void mm_init_cpumask(struct mm_struct *mm)
79206 {
79207diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
79208index c5d5278..f0b68c8 100644
79209--- a/include/linux/mmiotrace.h
79210+++ b/include/linux/mmiotrace.h
79211@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
79212 /* Called from ioremap.c */
79213 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
79214 void __iomem *addr);
79215-extern void mmiotrace_iounmap(volatile void __iomem *addr);
79216+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
79217
79218 /* For anyone to insert markers. Remember trailing newline. */
79219 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
79220@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
79221 {
79222 }
79223
79224-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
79225+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
79226 {
79227 }
79228
79229diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
79230index bd791e4..8617c34f 100644
79231--- a/include/linux/mmzone.h
79232+++ b/include/linux/mmzone.h
79233@@ -396,7 +396,7 @@ struct zone {
79234 unsigned long flags; /* zone flags, see below */
79235
79236 /* Zone statistics */
79237- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79238+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79239
79240 /*
79241 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
79242diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
79243index 45e9214..a7227d6 100644
79244--- a/include/linux/mod_devicetable.h
79245+++ b/include/linux/mod_devicetable.h
79246@@ -13,7 +13,7 @@
79247 typedef unsigned long kernel_ulong_t;
79248 #endif
79249
79250-#define PCI_ANY_ID (~0)
79251+#define PCI_ANY_ID ((__u16)~0)
79252
79253 struct pci_device_id {
79254 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
79255@@ -139,7 +139,7 @@ struct usb_device_id {
79256 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
79257 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
79258
79259-#define HID_ANY_ID (~0)
79260+#define HID_ANY_ID (~0U)
79261 #define HID_BUS_ANY 0xffff
79262 #define HID_GROUP_ANY 0x0000
79263
79264@@ -467,7 +467,7 @@ struct dmi_system_id {
79265 const char *ident;
79266 struct dmi_strmatch matches[4];
79267 void *driver_data;
79268-};
79269+} __do_const;
79270 /*
79271 * struct dmi_device_id appears during expansion of
79272 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
79273diff --git a/include/linux/module.h b/include/linux/module.h
79274index 15cd6b1..f6e2e6a 100644
79275--- a/include/linux/module.h
79276+++ b/include/linux/module.h
79277@@ -17,9 +17,11 @@
79278 #include <linux/moduleparam.h>
79279 #include <linux/tracepoint.h>
79280 #include <linux/export.h>
79281+#include <linux/fs.h>
79282
79283 #include <linux/percpu.h>
79284 #include <asm/module.h>
79285+#include <asm/pgtable.h>
79286
79287 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
79288 #define MODULE_SIG_STRING "~Module signature appended~\n"
79289@@ -43,7 +45,7 @@ struct module_kobject {
79290 struct kobject *drivers_dir;
79291 struct module_param_attrs *mp;
79292 struct completion *kobj_completion;
79293-};
79294+} __randomize_layout;
79295
79296 struct module_attribute {
79297 struct attribute attr;
79298@@ -55,12 +57,13 @@ struct module_attribute {
79299 int (*test)(struct module *);
79300 void (*free)(struct module *);
79301 };
79302+typedef struct module_attribute __no_const module_attribute_no_const;
79303
79304 struct module_version_attribute {
79305 struct module_attribute mattr;
79306 const char *module_name;
79307 const char *version;
79308-} __attribute__ ((__aligned__(sizeof(void *))));
79309+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
79310
79311 extern ssize_t __modver_version_show(struct module_attribute *,
79312 struct module_kobject *, char *);
79313@@ -238,7 +241,7 @@ struct module
79314
79315 /* Sysfs stuff. */
79316 struct module_kobject mkobj;
79317- struct module_attribute *modinfo_attrs;
79318+ module_attribute_no_const *modinfo_attrs;
79319 const char *version;
79320 const char *srcversion;
79321 struct kobject *holders_dir;
79322@@ -287,19 +290,16 @@ struct module
79323 int (*init)(void);
79324
79325 /* If this is non-NULL, vfree after init() returns */
79326- void *module_init;
79327+ void *module_init_rx, *module_init_rw;
79328
79329 /* Here is the actual code + data, vfree'd on unload. */
79330- void *module_core;
79331+ void *module_core_rx, *module_core_rw;
79332
79333 /* Here are the sizes of the init and core sections */
79334- unsigned int init_size, core_size;
79335+ unsigned int init_size_rw, core_size_rw;
79336
79337 /* The size of the executable code in each section. */
79338- unsigned int init_text_size, core_text_size;
79339-
79340- /* Size of RO sections of the module (text+rodata) */
79341- unsigned int init_ro_size, core_ro_size;
79342+ unsigned int init_size_rx, core_size_rx;
79343
79344 /* Arch-specific module values */
79345 struct mod_arch_specific arch;
79346@@ -355,6 +355,10 @@ struct module
79347 #ifdef CONFIG_EVENT_TRACING
79348 struct ftrace_event_call **trace_events;
79349 unsigned int num_trace_events;
79350+ struct file_operations trace_id;
79351+ struct file_operations trace_enable;
79352+ struct file_operations trace_format;
79353+ struct file_operations trace_filter;
79354 #endif
79355 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
79356 unsigned int num_ftrace_callsites;
79357@@ -378,7 +382,7 @@ struct module
79358 ctor_fn_t *ctors;
79359 unsigned int num_ctors;
79360 #endif
79361-};
79362+} __randomize_layout;
79363 #ifndef MODULE_ARCH_INIT
79364 #define MODULE_ARCH_INIT {}
79365 #endif
79366@@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
79367 bool is_module_percpu_address(unsigned long addr);
79368 bool is_module_text_address(unsigned long addr);
79369
79370+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
79371+{
79372+
79373+#ifdef CONFIG_PAX_KERNEXEC
79374+ if (ktla_ktva(addr) >= (unsigned long)start &&
79375+ ktla_ktva(addr) < (unsigned long)start + size)
79376+ return 1;
79377+#endif
79378+
79379+ return ((void *)addr >= start && (void *)addr < start + size);
79380+}
79381+
79382+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
79383+{
79384+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
79385+}
79386+
79387+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
79388+{
79389+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
79390+}
79391+
79392+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
79393+{
79394+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
79395+}
79396+
79397+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
79398+{
79399+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
79400+}
79401+
79402 static inline int within_module_core(unsigned long addr, const struct module *mod)
79403 {
79404- return (unsigned long)mod->module_core <= addr &&
79405- addr < (unsigned long)mod->module_core + mod->core_size;
79406+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
79407 }
79408
79409 static inline int within_module_init(unsigned long addr, const struct module *mod)
79410 {
79411- return (unsigned long)mod->module_init <= addr &&
79412- addr < (unsigned long)mod->module_init + mod->init_size;
79413+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
79414 }
79415
79416 /* Search for module by name: must hold module_mutex. */
79417diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
79418index 560ca53..ef621ef 100644
79419--- a/include/linux/moduleloader.h
79420+++ b/include/linux/moduleloader.h
79421@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
79422 sections. Returns NULL on failure. */
79423 void *module_alloc(unsigned long size);
79424
79425+#ifdef CONFIG_PAX_KERNEXEC
79426+void *module_alloc_exec(unsigned long size);
79427+#else
79428+#define module_alloc_exec(x) module_alloc(x)
79429+#endif
79430+
79431 /* Free memory returned from module_alloc. */
79432 void module_free(struct module *mod, void *module_region);
79433
79434+#ifdef CONFIG_PAX_KERNEXEC
79435+void module_free_exec(struct module *mod, void *module_region);
79436+#else
79437+#define module_free_exec(x, y) module_free((x), (y))
79438+#endif
79439+
79440 /*
79441 * Apply the given relocation to the (simplified) ELF. Return -error
79442 * or 0.
79443@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
79444 unsigned int relsec,
79445 struct module *me)
79446 {
79447+#ifdef CONFIG_MODULES
79448 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
79449+#endif
79450 return -ENOEXEC;
79451 }
79452 #endif
79453@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
79454 unsigned int relsec,
79455 struct module *me)
79456 {
79457+#ifdef CONFIG_MODULES
79458 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
79459+#endif
79460 return -ENOEXEC;
79461 }
79462 #endif
79463diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
79464index c3eb102..073c4a6 100644
79465--- a/include/linux/moduleparam.h
79466+++ b/include/linux/moduleparam.h
79467@@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
79468 * @len is usually just sizeof(string).
79469 */
79470 #define module_param_string(name, string, len, perm) \
79471- static const struct kparam_string __param_string_##name \
79472+ static const struct kparam_string __param_string_##name __used \
79473 = { len, string }; \
79474 __module_param_call(MODULE_PARAM_PREFIX, name, \
79475 &param_ops_string, \
79476@@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
79477 */
79478 #define module_param_array_named(name, array, type, nump, perm) \
79479 param_check_##type(name, &(array)[0]); \
79480- static const struct kparam_array __param_arr_##name \
79481+ static const struct kparam_array __param_arr_##name __used \
79482 = { .max = ARRAY_SIZE(array), .num = nump, \
79483 .ops = &param_ops_##type, \
79484 .elemsize = sizeof(array[0]), .elem = array }; \
79485diff --git a/include/linux/mount.h b/include/linux/mount.h
79486index 371d346..fba2819 100644
79487--- a/include/linux/mount.h
79488+++ b/include/linux/mount.h
79489@@ -56,7 +56,7 @@ struct vfsmount {
79490 struct dentry *mnt_root; /* root of the mounted tree */
79491 struct super_block *mnt_sb; /* pointer to superblock */
79492 int mnt_flags;
79493-};
79494+} __randomize_layout;
79495
79496 struct file; /* forward dec */
79497
79498diff --git a/include/linux/namei.h b/include/linux/namei.h
79499index 492de72..1bddcd4 100644
79500--- a/include/linux/namei.h
79501+++ b/include/linux/namei.h
79502@@ -19,7 +19,7 @@ struct nameidata {
79503 unsigned seq, m_seq;
79504 int last_type;
79505 unsigned depth;
79506- char *saved_names[MAX_NESTED_LINKS + 1];
79507+ const char *saved_names[MAX_NESTED_LINKS + 1];
79508 };
79509
79510 /*
79511@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
79512
79513 extern void nd_jump_link(struct nameidata *nd, struct path *path);
79514
79515-static inline void nd_set_link(struct nameidata *nd, char *path)
79516+static inline void nd_set_link(struct nameidata *nd, const char *path)
79517 {
79518 nd->saved_names[nd->depth] = path;
79519 }
79520
79521-static inline char *nd_get_link(struct nameidata *nd)
79522+static inline const char *nd_get_link(const struct nameidata *nd)
79523 {
79524 return nd->saved_names[nd->depth];
79525 }
79526diff --git a/include/linux/net.h b/include/linux/net.h
79527index 69be3e6..0fb422d 100644
79528--- a/include/linux/net.h
79529+++ b/include/linux/net.h
79530@@ -192,7 +192,7 @@ struct net_proto_family {
79531 int (*create)(struct net *net, struct socket *sock,
79532 int protocol, int kern);
79533 struct module *owner;
79534-};
79535+} __do_const;
79536
79537 struct iovec;
79538 struct kvec;
79539diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
79540index ce2a1f5..cb9bc8c 100644
79541--- a/include/linux/netdevice.h
79542+++ b/include/linux/netdevice.h
79543@@ -1129,6 +1129,7 @@ struct net_device_ops {
79544 struct net_device *dev,
79545 void *priv);
79546 };
79547+typedef struct net_device_ops __no_const net_device_ops_no_const;
79548
79549 /*
79550 * The DEVICE structure.
79551@@ -1211,7 +1212,7 @@ struct net_device {
79552 int iflink;
79553
79554 struct net_device_stats stats;
79555- atomic_long_t rx_dropped; /* dropped packets by core network
79556+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
79557 * Do not use this in drivers.
79558 */
79559
79560diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
79561index 2077489..a15e561 100644
79562--- a/include/linux/netfilter.h
79563+++ b/include/linux/netfilter.h
79564@@ -84,7 +84,7 @@ struct nf_sockopt_ops {
79565 #endif
79566 /* Use the module struct to lock set/get code in place */
79567 struct module *owner;
79568-};
79569+} __do_const;
79570
79571 /* Function to register/unregister hook points. */
79572 int nf_register_hook(struct nf_hook_ops *reg);
79573diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
79574index 28c7436..2d6156a 100644
79575--- a/include/linux/netfilter/nfnetlink.h
79576+++ b/include/linux/netfilter/nfnetlink.h
79577@@ -19,7 +19,7 @@ struct nfnl_callback {
79578 const struct nlattr * const cda[]);
79579 const struct nla_policy *policy; /* netlink attribute policy */
79580 const u_int16_t attr_count; /* number of nlattr's */
79581-};
79582+} __do_const;
79583
79584 struct nfnetlink_subsystem {
79585 const char *name;
79586diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
79587new file mode 100644
79588index 0000000..33f4af8
79589--- /dev/null
79590+++ b/include/linux/netfilter/xt_gradm.h
79591@@ -0,0 +1,9 @@
79592+#ifndef _LINUX_NETFILTER_XT_GRADM_H
79593+#define _LINUX_NETFILTER_XT_GRADM_H 1
79594+
79595+struct xt_gradm_mtinfo {
79596+ __u16 flags;
79597+ __u16 invflags;
79598+};
79599+
79600+#endif
79601diff --git a/include/linux/nls.h b/include/linux/nls.h
79602index 5dc635f..35f5e11 100644
79603--- a/include/linux/nls.h
79604+++ b/include/linux/nls.h
79605@@ -31,7 +31,7 @@ struct nls_table {
79606 const unsigned char *charset2upper;
79607 struct module *owner;
79608 struct nls_table *next;
79609-};
79610+} __do_const;
79611
79612 /* this value hold the maximum octet of charset */
79613 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
79614diff --git a/include/linux/notifier.h b/include/linux/notifier.h
79615index d14a4c3..a078786 100644
79616--- a/include/linux/notifier.h
79617+++ b/include/linux/notifier.h
79618@@ -54,7 +54,8 @@ struct notifier_block {
79619 notifier_fn_t notifier_call;
79620 struct notifier_block __rcu *next;
79621 int priority;
79622-};
79623+} __do_const;
79624+typedef struct notifier_block __no_const notifier_block_no_const;
79625
79626 struct atomic_notifier_head {
79627 spinlock_t lock;
79628diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
79629index b2a0f15..4d7da32 100644
79630--- a/include/linux/oprofile.h
79631+++ b/include/linux/oprofile.h
79632@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
79633 int oprofilefs_create_ro_ulong(struct dentry * root,
79634 char const * name, ulong * val);
79635
79636-/** Create a file for read-only access to an atomic_t. */
79637+/** Create a file for read-only access to an atomic_unchecked_t. */
79638 int oprofilefs_create_ro_atomic(struct dentry * root,
79639- char const * name, atomic_t * val);
79640+ char const * name, atomic_unchecked_t * val);
79641
79642 /** create a directory */
79643 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
79644diff --git a/include/linux/padata.h b/include/linux/padata.h
79645index 4386946..f50c615 100644
79646--- a/include/linux/padata.h
79647+++ b/include/linux/padata.h
79648@@ -129,7 +129,7 @@ struct parallel_data {
79649 struct padata_serial_queue __percpu *squeue;
79650 atomic_t reorder_objects;
79651 atomic_t refcnt;
79652- atomic_t seq_nr;
79653+ atomic_unchecked_t seq_nr;
79654 struct padata_cpumask cpumask;
79655 spinlock_t lock ____cacheline_aligned;
79656 unsigned int processed;
79657diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
79658index a2e2f1d..8a391d2 100644
79659--- a/include/linux/pci_hotplug.h
79660+++ b/include/linux/pci_hotplug.h
79661@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
79662 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
79663 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
79664 int (*reset_slot) (struct hotplug_slot *slot, int probe);
79665-};
79666+} __do_const;
79667+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
79668
79669 /**
79670 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
79671diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
79672index 2e069d1..27054b8 100644
79673--- a/include/linux/perf_event.h
79674+++ b/include/linux/perf_event.h
79675@@ -327,8 +327,8 @@ struct perf_event {
79676
79677 enum perf_event_active_state state;
79678 unsigned int attach_state;
79679- local64_t count;
79680- atomic64_t child_count;
79681+ local64_t count; /* PaX: fix it one day */
79682+ atomic64_unchecked_t child_count;
79683
79684 /*
79685 * These are the total time in nanoseconds that the event
79686@@ -379,8 +379,8 @@ struct perf_event {
79687 * These accumulate total time (in nanoseconds) that children
79688 * events have been enabled and running, respectively.
79689 */
79690- atomic64_t child_total_time_enabled;
79691- atomic64_t child_total_time_running;
79692+ atomic64_unchecked_t child_total_time_enabled;
79693+ atomic64_unchecked_t child_total_time_running;
79694
79695 /*
79696 * Protect attach/detach and child_list:
79697@@ -707,7 +707,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
79698 entry->ip[entry->nr++] = ip;
79699 }
79700
79701-extern int sysctl_perf_event_paranoid;
79702+extern int sysctl_perf_event_legitimately_concerned;
79703 extern int sysctl_perf_event_mlock;
79704 extern int sysctl_perf_event_sample_rate;
79705 extern int sysctl_perf_cpu_time_max_percent;
79706@@ -722,19 +722,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
79707 loff_t *ppos);
79708
79709
79710+static inline bool perf_paranoid_any(void)
79711+{
79712+ return sysctl_perf_event_legitimately_concerned > 2;
79713+}
79714+
79715 static inline bool perf_paranoid_tracepoint_raw(void)
79716 {
79717- return sysctl_perf_event_paranoid > -1;
79718+ return sysctl_perf_event_legitimately_concerned > -1;
79719 }
79720
79721 static inline bool perf_paranoid_cpu(void)
79722 {
79723- return sysctl_perf_event_paranoid > 0;
79724+ return sysctl_perf_event_legitimately_concerned > 0;
79725 }
79726
79727 static inline bool perf_paranoid_kernel(void)
79728 {
79729- return sysctl_perf_event_paranoid > 1;
79730+ return sysctl_perf_event_legitimately_concerned > 1;
79731 }
79732
79733 extern void perf_event_init(void);
79734@@ -850,7 +855,7 @@ struct perf_pmu_events_attr {
79735 struct device_attribute attr;
79736 u64 id;
79737 const char *event_str;
79738-};
79739+} __do_const;
79740
79741 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
79742 static struct perf_pmu_events_attr _var = { \
79743diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
79744index 7246ef3..1539ea4 100644
79745--- a/include/linux/pid_namespace.h
79746+++ b/include/linux/pid_namespace.h
79747@@ -43,7 +43,7 @@ struct pid_namespace {
79748 int hide_pid;
79749 int reboot; /* group exit code if this pidns was rebooted */
79750 unsigned int proc_inum;
79751-};
79752+} __randomize_layout;
79753
79754 extern struct pid_namespace init_pid_ns;
79755
79756diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
79757index b8809fe..ae4ccd0 100644
79758--- a/include/linux/pipe_fs_i.h
79759+++ b/include/linux/pipe_fs_i.h
79760@@ -47,10 +47,10 @@ struct pipe_inode_info {
79761 struct mutex mutex;
79762 wait_queue_head_t wait;
79763 unsigned int nrbufs, curbuf, buffers;
79764- unsigned int readers;
79765- unsigned int writers;
79766- unsigned int files;
79767- unsigned int waiting_writers;
79768+ atomic_t readers;
79769+ atomic_t writers;
79770+ atomic_t files;
79771+ atomic_t waiting_writers;
79772 unsigned int r_counter;
79773 unsigned int w_counter;
79774 struct page *tmp_page;
79775diff --git a/include/linux/pm.h b/include/linux/pm.h
79776index a224c7f..92d8a97 100644
79777--- a/include/linux/pm.h
79778+++ b/include/linux/pm.h
79779@@ -576,6 +576,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
79780 struct dev_pm_domain {
79781 struct dev_pm_ops ops;
79782 };
79783+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
79784
79785 /*
79786 * The PM_EVENT_ messages are also used by drivers implementing the legacy
79787diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
79788index 7c1d252..c5c773e 100644
79789--- a/include/linux/pm_domain.h
79790+++ b/include/linux/pm_domain.h
79791@@ -48,7 +48,7 @@ struct gpd_dev_ops {
79792
79793 struct gpd_cpu_data {
79794 unsigned int saved_exit_latency;
79795- struct cpuidle_state *idle_state;
79796+ cpuidle_state_no_const *idle_state;
79797 };
79798
79799 struct generic_pm_domain {
79800diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
79801index 6fa7cea..7bf6415 100644
79802--- a/include/linux/pm_runtime.h
79803+++ b/include/linux/pm_runtime.h
79804@@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
79805
79806 static inline void pm_runtime_mark_last_busy(struct device *dev)
79807 {
79808- ACCESS_ONCE(dev->power.last_busy) = jiffies;
79809+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
79810 }
79811
79812 #else /* !CONFIG_PM_RUNTIME */
79813diff --git a/include/linux/pnp.h b/include/linux/pnp.h
79814index 195aafc..49a7bc2 100644
79815--- a/include/linux/pnp.h
79816+++ b/include/linux/pnp.h
79817@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
79818 struct pnp_fixup {
79819 char id[7];
79820 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
79821-};
79822+} __do_const;
79823
79824 /* config parameters */
79825 #define PNP_CONFIG_NORMAL 0x0001
79826diff --git a/include/linux/poison.h b/include/linux/poison.h
79827index 2110a81..13a11bb 100644
79828--- a/include/linux/poison.h
79829+++ b/include/linux/poison.h
79830@@ -19,8 +19,8 @@
79831 * under normal circumstances, used to verify that nobody uses
79832 * non-initialized list entries.
79833 */
79834-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
79835-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
79836+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
79837+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
79838
79839 /********** include/linux/timer.h **********/
79840 /*
79841diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
79842index d8b187c3..9a9257a 100644
79843--- a/include/linux/power/smartreflex.h
79844+++ b/include/linux/power/smartreflex.h
79845@@ -238,7 +238,7 @@ struct omap_sr_class_data {
79846 int (*notify)(struct omap_sr *sr, u32 status);
79847 u8 notify_flags;
79848 u8 class_type;
79849-};
79850+} __do_const;
79851
79852 /**
79853 * struct omap_sr_nvalue_table - Smartreflex n-target value info
79854diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
79855index 4ea1d37..80f4b33 100644
79856--- a/include/linux/ppp-comp.h
79857+++ b/include/linux/ppp-comp.h
79858@@ -84,7 +84,7 @@ struct compressor {
79859 struct module *owner;
79860 /* Extra skb space needed by the compressor algorithm */
79861 unsigned int comp_extra;
79862-};
79863+} __do_const;
79864
79865 /*
79866 * The return value from decompress routine is the length of the
79867diff --git a/include/linux/preempt.h b/include/linux/preempt.h
79868index a3d9dc8..8af9922 100644
79869--- a/include/linux/preempt.h
79870+++ b/include/linux/preempt.h
79871@@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
79872 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
79873 #endif
79874
79875+#define raw_preempt_count_add(val) __preempt_count_add(val)
79876+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
79877+
79878 #define __preempt_count_inc() __preempt_count_add(1)
79879 #define __preempt_count_dec() __preempt_count_sub(1)
79880
79881 #define preempt_count_inc() preempt_count_add(1)
79882+#define raw_preempt_count_inc() raw_preempt_count_add(1)
79883 #define preempt_count_dec() preempt_count_sub(1)
79884+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
79885
79886 #ifdef CONFIG_PREEMPT_COUNT
79887
79888@@ -41,6 +46,12 @@ do { \
79889 barrier(); \
79890 } while (0)
79891
79892+#define raw_preempt_disable() \
79893+do { \
79894+ raw_preempt_count_inc(); \
79895+ barrier(); \
79896+} while (0)
79897+
79898 #define sched_preempt_enable_no_resched() \
79899 do { \
79900 barrier(); \
79901@@ -49,6 +60,12 @@ do { \
79902
79903 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
79904
79905+#define raw_preempt_enable_no_resched() \
79906+do { \
79907+ barrier(); \
79908+ raw_preempt_count_dec(); \
79909+} while (0)
79910+
79911 #ifdef CONFIG_PREEMPT
79912 #define preempt_enable() \
79913 do { \
79914@@ -105,8 +122,10 @@ do { \
79915 * region.
79916 */
79917 #define preempt_disable() barrier()
79918+#define raw_preempt_disable() barrier()
79919 #define sched_preempt_enable_no_resched() barrier()
79920 #define preempt_enable_no_resched() barrier()
79921+#define raw_preempt_enable_no_resched() barrier()
79922 #define preempt_enable() barrier()
79923 #define preempt_check_resched() do { } while (0)
79924
79925diff --git a/include/linux/printk.h b/include/linux/printk.h
79926index 6949258..7c4730e 100644
79927--- a/include/linux/printk.h
79928+++ b/include/linux/printk.h
79929@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
79930 void early_printk(const char *s, ...) { }
79931 #endif
79932
79933+extern int kptr_restrict;
79934+
79935 #ifdef CONFIG_PRINTK
79936 asmlinkage __printf(5, 0)
79937 int vprintk_emit(int facility, int level,
79938@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
79939
79940 extern int printk_delay_msec;
79941 extern int dmesg_restrict;
79942-extern int kptr_restrict;
79943
79944 extern void wake_up_klogd(void);
79945
79946diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
79947index 608e60a..c26f864 100644
79948--- a/include/linux/proc_fs.h
79949+++ b/include/linux/proc_fs.h
79950@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
79951 return proc_create_data(name, mode, parent, proc_fops, NULL);
79952 }
79953
79954+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
79955+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
79956+{
79957+#ifdef CONFIG_GRKERNSEC_PROC_USER
79958+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
79959+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79960+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
79961+#else
79962+ return proc_create_data(name, mode, parent, proc_fops, NULL);
79963+#endif
79964+}
79965+
79966+
79967 extern void proc_set_size(struct proc_dir_entry *, loff_t);
79968 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
79969 extern void *PDE_DATA(const struct inode *);
79970diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
79971index 34a1e10..70f6bde 100644
79972--- a/include/linux/proc_ns.h
79973+++ b/include/linux/proc_ns.h
79974@@ -14,7 +14,7 @@ struct proc_ns_operations {
79975 void (*put)(void *ns);
79976 int (*install)(struct nsproxy *nsproxy, void *ns);
79977 unsigned int (*inum)(void *ns);
79978-};
79979+} __do_const __randomize_layout;
79980
79981 struct proc_ns {
79982 void *ns;
79983diff --git a/include/linux/quota.h b/include/linux/quota.h
79984index cc7494a..1e27036 100644
79985--- a/include/linux/quota.h
79986+++ b/include/linux/quota.h
79987@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
79988
79989 extern bool qid_eq(struct kqid left, struct kqid right);
79990 extern bool qid_lt(struct kqid left, struct kqid right);
79991-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
79992+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
79993 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
79994 extern bool qid_valid(struct kqid qid);
79995
79996diff --git a/include/linux/random.h b/include/linux/random.h
79997index 4002b3d..d5ad855 100644
79998--- a/include/linux/random.h
79999+++ b/include/linux/random.h
80000@@ -10,9 +10,19 @@
80001
80002
80003 extern void add_device_randomness(const void *, unsigned int);
80004+
80005+static inline void add_latent_entropy(void)
80006+{
80007+
80008+#ifdef LATENT_ENTROPY_PLUGIN
80009+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
80010+#endif
80011+
80012+}
80013+
80014 extern void add_input_randomness(unsigned int type, unsigned int code,
80015- unsigned int value);
80016-extern void add_interrupt_randomness(int irq, int irq_flags);
80017+ unsigned int value) __latent_entropy;
80018+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
80019
80020 extern void get_random_bytes(void *buf, int nbytes);
80021 extern void get_random_bytes_arch(void *buf, int nbytes);
80022@@ -23,10 +33,10 @@ extern int random_int_secret_init(void);
80023 extern const struct file_operations random_fops, urandom_fops;
80024 #endif
80025
80026-unsigned int get_random_int(void);
80027+unsigned int __intentional_overflow(-1) get_random_int(void);
80028 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
80029
80030-u32 prandom_u32(void);
80031+u32 prandom_u32(void) __intentional_overflow(-1);
80032 void prandom_bytes(void *buf, int nbytes);
80033 void prandom_seed(u32 seed);
80034 void prandom_reseed_late(void);
80035@@ -38,6 +48,11 @@ struct rnd_state {
80036 u32 prandom_u32_state(struct rnd_state *state);
80037 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
80038
80039+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
80040+{
80041+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
80042+}
80043+
80044 /*
80045 * Handle minimum values for seeds
80046 */
80047diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
80048index fea49b5..2ac22bb 100644
80049--- a/include/linux/rbtree_augmented.h
80050+++ b/include/linux/rbtree_augmented.h
80051@@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
80052 old->rbaugmented = rbcompute(old); \
80053 } \
80054 rbstatic const struct rb_augment_callbacks rbname = { \
80055- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
80056+ .propagate = rbname ## _propagate, \
80057+ .copy = rbname ## _copy, \
80058+ .rotate = rbname ## _rotate \
80059 };
80060
80061
80062diff --git a/include/linux/rculist.h b/include/linux/rculist.h
80063index 45a0a9e..e83788e 100644
80064--- a/include/linux/rculist.h
80065+++ b/include/linux/rculist.h
80066@@ -29,8 +29,8 @@
80067 */
80068 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
80069 {
80070- ACCESS_ONCE(list->next) = list;
80071- ACCESS_ONCE(list->prev) = list;
80072+ ACCESS_ONCE_RW(list->next) = list;
80073+ ACCESS_ONCE_RW(list->prev) = list;
80074 }
80075
80076 /*
80077@@ -59,6 +59,9 @@ extern void __list_add_rcu(struct list_head *new,
80078 struct list_head *prev, struct list_head *next);
80079 #endif
80080
80081+extern void __pax_list_add_rcu(struct list_head *new,
80082+ struct list_head *prev, struct list_head *next);
80083+
80084 /**
80085 * list_add_rcu - add a new entry to rcu-protected list
80086 * @new: new entry to be added
80087@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
80088 __list_add_rcu(new, head, head->next);
80089 }
80090
80091+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
80092+{
80093+ __pax_list_add_rcu(new, head, head->next);
80094+}
80095+
80096 /**
80097 * list_add_tail_rcu - add a new entry to rcu-protected list
80098 * @new: new entry to be added
80099@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
80100 __list_add_rcu(new, head->prev, head);
80101 }
80102
80103+static inline void pax_list_add_tail_rcu(struct list_head *new,
80104+ struct list_head *head)
80105+{
80106+ __pax_list_add_rcu(new, head->prev, head);
80107+}
80108+
80109 /**
80110 * list_del_rcu - deletes entry from list without re-initialization
80111 * @entry: the element to delete from the list.
80112@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
80113 entry->prev = LIST_POISON2;
80114 }
80115
80116+extern void pax_list_del_rcu(struct list_head *entry);
80117+
80118 /**
80119 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
80120 * @n: the element to delete from the hash list.
80121diff --git a/include/linux/reboot.h b/include/linux/reboot.h
80122index 9e7db9e..7d4fd72 100644
80123--- a/include/linux/reboot.h
80124+++ b/include/linux/reboot.h
80125@@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
80126 */
80127
80128 extern void migrate_to_reboot_cpu(void);
80129-extern void machine_restart(char *cmd);
80130-extern void machine_halt(void);
80131-extern void machine_power_off(void);
80132+extern void machine_restart(char *cmd) __noreturn;
80133+extern void machine_halt(void) __noreturn;
80134+extern void machine_power_off(void) __noreturn;
80135
80136 extern void machine_shutdown(void);
80137 struct pt_regs;
80138@@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
80139 */
80140
80141 extern void kernel_restart_prepare(char *cmd);
80142-extern void kernel_restart(char *cmd);
80143-extern void kernel_halt(void);
80144-extern void kernel_power_off(void);
80145+extern void kernel_restart(char *cmd) __noreturn;
80146+extern void kernel_halt(void) __noreturn;
80147+extern void kernel_power_off(void) __noreturn;
80148
80149 extern int C_A_D; /* for sysctl */
80150 void ctrl_alt_del(void);
80151@@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
80152 * Emergency restart, callable from an interrupt handler.
80153 */
80154
80155-extern void emergency_restart(void);
80156+extern void emergency_restart(void) __noreturn;
80157 #include <asm/emergency-restart.h>
80158
80159 #endif /* _LINUX_REBOOT_H */
80160diff --git a/include/linux/regset.h b/include/linux/regset.h
80161index 8e0c9fe..ac4d221 100644
80162--- a/include/linux/regset.h
80163+++ b/include/linux/regset.h
80164@@ -161,7 +161,8 @@ struct user_regset {
80165 unsigned int align;
80166 unsigned int bias;
80167 unsigned int core_note_type;
80168-};
80169+} __do_const;
80170+typedef struct user_regset __no_const user_regset_no_const;
80171
80172 /**
80173 * struct user_regset_view - available regsets
80174diff --git a/include/linux/relay.h b/include/linux/relay.h
80175index d7c8359..818daf5 100644
80176--- a/include/linux/relay.h
80177+++ b/include/linux/relay.h
80178@@ -157,7 +157,7 @@ struct rchan_callbacks
80179 * The callback should return 0 if successful, negative if not.
80180 */
80181 int (*remove_buf_file)(struct dentry *dentry);
80182-};
80183+} __no_const;
80184
80185 /*
80186 * CONFIG_RELAY kernel API, kernel/relay.c
80187diff --git a/include/linux/rio.h b/include/linux/rio.h
80188index b71d573..2f940bd 100644
80189--- a/include/linux/rio.h
80190+++ b/include/linux/rio.h
80191@@ -355,7 +355,7 @@ struct rio_ops {
80192 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
80193 u64 rstart, u32 size, u32 flags);
80194 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
80195-};
80196+} __no_const;
80197
80198 #define RIO_RESOURCE_MEM 0x00000100
80199 #define RIO_RESOURCE_DOORBELL 0x00000200
80200diff --git a/include/linux/rmap.h b/include/linux/rmap.h
80201index 6dacb93..6174423 100644
80202--- a/include/linux/rmap.h
80203+++ b/include/linux/rmap.h
80204@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
80205 void anon_vma_init(void); /* create anon_vma_cachep */
80206 int anon_vma_prepare(struct vm_area_struct *);
80207 void unlink_anon_vmas(struct vm_area_struct *);
80208-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
80209-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
80210+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
80211+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
80212
80213 static inline void anon_vma_merge(struct vm_area_struct *vma,
80214 struct vm_area_struct *next)
80215diff --git a/include/linux/sched.h b/include/linux/sched.h
80216index 53f97eb..1d90705 100644
80217--- a/include/linux/sched.h
80218+++ b/include/linux/sched.h
80219@@ -63,6 +63,7 @@ struct bio_list;
80220 struct fs_struct;
80221 struct perf_event_context;
80222 struct blk_plug;
80223+struct linux_binprm;
80224
80225 /*
80226 * List of flags we want to share for kernel threads,
80227@@ -304,7 +305,7 @@ extern char __sched_text_start[], __sched_text_end[];
80228 extern int in_sched_functions(unsigned long addr);
80229
80230 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
80231-extern signed long schedule_timeout(signed long timeout);
80232+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
80233 extern signed long schedule_timeout_interruptible(signed long timeout);
80234 extern signed long schedule_timeout_killable(signed long timeout);
80235 extern signed long schedule_timeout_uninterruptible(signed long timeout);
80236@@ -315,6 +316,19 @@ struct nsproxy;
80237 struct user_namespace;
80238
80239 #ifdef CONFIG_MMU
80240+
80241+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
80242+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
80243+#else
80244+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
80245+{
80246+ return 0;
80247+}
80248+#endif
80249+
80250+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
80251+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
80252+
80253 extern void arch_pick_mmap_layout(struct mm_struct *mm);
80254 extern unsigned long
80255 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
80256@@ -600,6 +614,17 @@ struct signal_struct {
80257 #ifdef CONFIG_TASKSTATS
80258 struct taskstats *stats;
80259 #endif
80260+
80261+#ifdef CONFIG_GRKERNSEC
80262+ u32 curr_ip;
80263+ u32 saved_ip;
80264+ u32 gr_saddr;
80265+ u32 gr_daddr;
80266+ u16 gr_sport;
80267+ u16 gr_dport;
80268+ u8 used_accept:1;
80269+#endif
80270+
80271 #ifdef CONFIG_AUDIT
80272 unsigned audit_tty;
80273 unsigned audit_tty_log_passwd;
80274@@ -626,7 +651,7 @@ struct signal_struct {
80275 struct mutex cred_guard_mutex; /* guard against foreign influences on
80276 * credential calculations
80277 * (notably. ptrace) */
80278-};
80279+} __randomize_layout;
80280
80281 /*
80282 * Bits in flags field of signal_struct.
80283@@ -680,6 +705,14 @@ struct user_struct {
80284 struct key *session_keyring; /* UID's default session keyring */
80285 #endif
80286
80287+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
80288+ unsigned char kernel_banned;
80289+#endif
80290+#ifdef CONFIG_GRKERNSEC_BRUTE
80291+ unsigned char suid_banned;
80292+ unsigned long suid_ban_expires;
80293+#endif
80294+
80295 /* Hash table maintenance information */
80296 struct hlist_node uidhash_node;
80297 kuid_t uid;
80298@@ -687,7 +720,7 @@ struct user_struct {
80299 #ifdef CONFIG_PERF_EVENTS
80300 atomic_long_t locked_vm;
80301 #endif
80302-};
80303+} __randomize_layout;
80304
80305 extern int uids_sysfs_init(void);
80306
80307@@ -1162,8 +1195,8 @@ struct task_struct {
80308 struct list_head thread_group;
80309
80310 struct completion *vfork_done; /* for vfork() */
80311- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
80312- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
80313+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
80314+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
80315
80316 cputime_t utime, stime, utimescaled, stimescaled;
80317 cputime_t gtime;
80318@@ -1188,11 +1221,6 @@ struct task_struct {
80319 struct task_cputime cputime_expires;
80320 struct list_head cpu_timers[3];
80321
80322-/* process credentials */
80323- const struct cred __rcu *real_cred; /* objective and real subjective task
80324- * credentials (COW) */
80325- const struct cred __rcu *cred; /* effective (overridable) subjective task
80326- * credentials (COW) */
80327 char comm[TASK_COMM_LEN]; /* executable name excluding path
80328 - access with [gs]et_task_comm (which lock
80329 it with task_lock())
80330@@ -1209,6 +1237,10 @@ struct task_struct {
80331 #endif
80332 /* CPU-specific state of this task */
80333 struct thread_struct thread;
80334+/* thread_info moved to task_struct */
80335+#ifdef CONFIG_X86
80336+ struct thread_info tinfo;
80337+#endif
80338 /* filesystem information */
80339 struct fs_struct *fs;
80340 /* open file information */
80341@@ -1282,6 +1314,10 @@ struct task_struct {
80342 gfp_t lockdep_reclaim_gfp;
80343 #endif
80344
80345+/* process credentials */
80346+ const struct cred __rcu *real_cred; /* objective and real subjective task
80347+ * credentials (COW) */
80348+
80349 /* journalling filesystem info */
80350 void *journal_info;
80351
80352@@ -1320,6 +1356,10 @@ struct task_struct {
80353 /* cg_list protected by css_set_lock and tsk->alloc_lock */
80354 struct list_head cg_list;
80355 #endif
80356+
80357+ const struct cred __rcu *cred; /* effective (overridable) subjective task
80358+ * credentials (COW) */
80359+
80360 #ifdef CONFIG_FUTEX
80361 struct robust_list_head __user *robust_list;
80362 #ifdef CONFIG_COMPAT
80363@@ -1454,7 +1494,78 @@ struct task_struct {
80364 unsigned int sequential_io;
80365 unsigned int sequential_io_avg;
80366 #endif
80367-};
80368+
80369+#ifdef CONFIG_GRKERNSEC
80370+ /* grsecurity */
80371+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
80372+ u64 exec_id;
80373+#endif
80374+#ifdef CONFIG_GRKERNSEC_SETXID
80375+ const struct cred *delayed_cred;
80376+#endif
80377+ struct dentry *gr_chroot_dentry;
80378+ struct acl_subject_label *acl;
80379+ struct acl_subject_label *tmpacl;
80380+ struct acl_role_label *role;
80381+ struct file *exec_file;
80382+ unsigned long brute_expires;
80383+ u16 acl_role_id;
80384+ u8 inherited;
80385+ /* is this the task that authenticated to the special role */
80386+ u8 acl_sp_role;
80387+ u8 is_writable;
80388+ u8 brute;
80389+ u8 gr_is_chrooted;
80390+#endif
80391+
80392+} __randomize_layout;
80393+
80394+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
80395+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
80396+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
80397+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
80398+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
80399+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
80400+
80401+#ifdef CONFIG_PAX_SOFTMODE
80402+extern int pax_softmode;
80403+#endif
80404+
80405+extern int pax_check_flags(unsigned long *);
80406+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
80407+
80408+/* if tsk != current then task_lock must be held on it */
80409+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80410+static inline unsigned long pax_get_flags(struct task_struct *tsk)
80411+{
80412+ if (likely(tsk->mm))
80413+ return tsk->mm->pax_flags;
80414+ else
80415+ return 0UL;
80416+}
80417+
80418+/* if tsk != current then task_lock must be held on it */
80419+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
80420+{
80421+ if (likely(tsk->mm)) {
80422+ tsk->mm->pax_flags = flags;
80423+ return 0;
80424+ }
80425+ return -EINVAL;
80426+}
80427+#endif
80428+
80429+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
80430+extern void pax_set_initial_flags(struct linux_binprm *bprm);
80431+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
80432+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
80433+#endif
80434+
80435+struct path;
80436+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
80437+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
80438+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
80439+extern void pax_report_refcount_overflow(struct pt_regs *regs);
80440
80441 /* Future-safe accessor for struct task_struct's cpus_allowed. */
80442 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
80443@@ -1531,7 +1642,7 @@ struct pid_namespace;
80444 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
80445 struct pid_namespace *ns);
80446
80447-static inline pid_t task_pid_nr(struct task_struct *tsk)
80448+static inline pid_t task_pid_nr(const struct task_struct *tsk)
80449 {
80450 return tsk->pid;
80451 }
80452@@ -1981,7 +2092,9 @@ void yield(void);
80453 extern struct exec_domain default_exec_domain;
80454
80455 union thread_union {
80456+#ifndef CONFIG_X86
80457 struct thread_info thread_info;
80458+#endif
80459 unsigned long stack[THREAD_SIZE/sizeof(long)];
80460 };
80461
80462@@ -2014,6 +2127,7 @@ extern struct pid_namespace init_pid_ns;
80463 */
80464
80465 extern struct task_struct *find_task_by_vpid(pid_t nr);
80466+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
80467 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
80468 struct pid_namespace *ns);
80469
80470@@ -2178,7 +2292,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
80471 extern void exit_itimers(struct signal_struct *);
80472 extern void flush_itimer_signals(void);
80473
80474-extern void do_group_exit(int);
80475+extern __noreturn void do_group_exit(int);
80476
80477 extern int allow_signal(int);
80478 extern int disallow_signal(int);
80479@@ -2369,9 +2483,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
80480
80481 #endif
80482
80483-static inline int object_is_on_stack(void *obj)
80484+static inline int object_starts_on_stack(void *obj)
80485 {
80486- void *stack = task_stack_page(current);
80487+ const void *stack = task_stack_page(current);
80488
80489 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
80490 }
80491diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
80492index 41467f8..1e4253d 100644
80493--- a/include/linux/sched/sysctl.h
80494+++ b/include/linux/sched/sysctl.h
80495@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
80496 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
80497
80498 extern int sysctl_max_map_count;
80499+extern unsigned long sysctl_heap_stack_gap;
80500
80501 extern unsigned int sysctl_sched_latency;
80502 extern unsigned int sysctl_sched_min_granularity;
80503diff --git a/include/linux/security.h b/include/linux/security.h
80504index 5623a7f..b352409 100644
80505--- a/include/linux/security.h
80506+++ b/include/linux/security.h
80507@@ -27,6 +27,7 @@
80508 #include <linux/slab.h>
80509 #include <linux/err.h>
80510 #include <linux/string.h>
80511+#include <linux/grsecurity.h>
80512
80513 struct linux_binprm;
80514 struct cred;
80515@@ -116,8 +117,6 @@ struct seq_file;
80516
80517 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
80518
80519-void reset_security_ops(void);
80520-
80521 #ifdef CONFIG_MMU
80522 extern unsigned long mmap_min_addr;
80523 extern unsigned long dac_mmap_min_addr;
80524diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
80525index dc368b8..e895209 100644
80526--- a/include/linux/semaphore.h
80527+++ b/include/linux/semaphore.h
80528@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
80529 }
80530
80531 extern void down(struct semaphore *sem);
80532-extern int __must_check down_interruptible(struct semaphore *sem);
80533+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
80534 extern int __must_check down_killable(struct semaphore *sem);
80535 extern int __must_check down_trylock(struct semaphore *sem);
80536 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
80537diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
80538index 52e0097..09625ef 100644
80539--- a/include/linux/seq_file.h
80540+++ b/include/linux/seq_file.h
80541@@ -27,6 +27,9 @@ struct seq_file {
80542 struct mutex lock;
80543 const struct seq_operations *op;
80544 int poll_event;
80545+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
80546+ u64 exec_id;
80547+#endif
80548 #ifdef CONFIG_USER_NS
80549 struct user_namespace *user_ns;
80550 #endif
80551@@ -39,6 +42,7 @@ struct seq_operations {
80552 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
80553 int (*show) (struct seq_file *m, void *v);
80554 };
80555+typedef struct seq_operations __no_const seq_operations_no_const;
80556
80557 #define SEQ_SKIP 1
80558
80559diff --git a/include/linux/shm.h b/include/linux/shm.h
80560index 429c199..4d42e38 100644
80561--- a/include/linux/shm.h
80562+++ b/include/linux/shm.h
80563@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
80564
80565 /* The task created the shm object. NULL if the task is dead. */
80566 struct task_struct *shm_creator;
80567+#ifdef CONFIG_GRKERNSEC
80568+ time_t shm_createtime;
80569+ pid_t shm_lapid;
80570+#endif
80571 };
80572
80573 /* shm_mode upper byte flags */
80574diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
80575index 6f69b3f..71ac613 100644
80576--- a/include/linux/skbuff.h
80577+++ b/include/linux/skbuff.h
80578@@ -643,7 +643,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
80579 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
80580 int node);
80581 struct sk_buff *build_skb(void *data, unsigned int frag_size);
80582-static inline struct sk_buff *alloc_skb(unsigned int size,
80583+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
80584 gfp_t priority)
80585 {
80586 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
80587@@ -750,7 +750,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
80588 */
80589 static inline int skb_queue_empty(const struct sk_buff_head *list)
80590 {
80591- return list->next == (struct sk_buff *)list;
80592+ return list->next == (const struct sk_buff *)list;
80593 }
80594
80595 /**
80596@@ -763,7 +763,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
80597 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
80598 const struct sk_buff *skb)
80599 {
80600- return skb->next == (struct sk_buff *)list;
80601+ return skb->next == (const struct sk_buff *)list;
80602 }
80603
80604 /**
80605@@ -776,7 +776,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
80606 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
80607 const struct sk_buff *skb)
80608 {
80609- return skb->prev == (struct sk_buff *)list;
80610+ return skb->prev == (const struct sk_buff *)list;
80611 }
80612
80613 /**
80614@@ -1686,7 +1686,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
80615 return skb->inner_transport_header - skb->inner_network_header;
80616 }
80617
80618-static inline int skb_network_offset(const struct sk_buff *skb)
80619+static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
80620 {
80621 return skb_network_header(skb) - skb->data;
80622 }
80623@@ -1746,7 +1746,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
80624 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
80625 */
80626 #ifndef NET_SKB_PAD
80627-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
80628+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
80629 #endif
80630
80631 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
80632@@ -2345,7 +2345,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
80633 int *err);
80634 unsigned int datagram_poll(struct file *file, struct socket *sock,
80635 struct poll_table_struct *wait);
80636-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
80637+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
80638 struct iovec *to, int size);
80639 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
80640 struct iovec *iov);
80641@@ -2617,6 +2617,9 @@ static inline void nf_reset(struct sk_buff *skb)
80642 nf_bridge_put(skb->nf_bridge);
80643 skb->nf_bridge = NULL;
80644 #endif
80645+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
80646+ skb->nf_trace = 0;
80647+#endif
80648 }
80649
80650 static inline void nf_reset_trace(struct sk_buff *skb)
80651diff --git a/include/linux/slab.h b/include/linux/slab.h
80652index 1e2f4fe..df49ca6 100644
80653--- a/include/linux/slab.h
80654+++ b/include/linux/slab.h
80655@@ -14,15 +14,29 @@
80656 #include <linux/gfp.h>
80657 #include <linux/types.h>
80658 #include <linux/workqueue.h>
80659-
80660+#include <linux/err.h>
80661
80662 /*
80663 * Flags to pass to kmem_cache_create().
80664 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
80665 */
80666 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
80667+
80668+#ifdef CONFIG_PAX_USERCOPY_SLABS
80669+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
80670+#else
80671+#define SLAB_USERCOPY 0x00000000UL
80672+#endif
80673+
80674 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
80675 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
80676+
80677+#ifdef CONFIG_PAX_MEMORY_SANITIZE
80678+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
80679+#else
80680+#define SLAB_NO_SANITIZE 0x00000000UL
80681+#endif
80682+
80683 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
80684 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
80685 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
80686@@ -98,10 +112,13 @@
80687 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
80688 * Both make kfree a no-op.
80689 */
80690-#define ZERO_SIZE_PTR ((void *)16)
80691+#define ZERO_SIZE_PTR \
80692+({ \
80693+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
80694+ (void *)(-MAX_ERRNO-1L); \
80695+})
80696
80697-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
80698- (unsigned long)ZERO_SIZE_PTR)
80699+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
80700
80701 #include <linux/kmemleak.h>
80702
80703@@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
80704 void kfree(const void *);
80705 void kzfree(const void *);
80706 size_t ksize(const void *);
80707+const char *check_heap_object(const void *ptr, unsigned long n);
80708+bool is_usercopy_object(const void *ptr);
80709
80710 /*
80711 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
80712@@ -174,7 +193,7 @@ struct kmem_cache {
80713 unsigned int align; /* Alignment as calculated */
80714 unsigned long flags; /* Active flags on the slab */
80715 const char *name; /* Slab name for sysfs */
80716- int refcount; /* Use counter */
80717+ atomic_t refcount; /* Use counter */
80718 void (*ctor)(void *); /* Called on object slot creation */
80719 struct list_head list; /* List of all slab caches on the system */
80720 };
80721@@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
80722 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
80723 #endif
80724
80725+#ifdef CONFIG_PAX_USERCOPY_SLABS
80726+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
80727+#endif
80728+
80729 /*
80730 * Figure out which kmalloc slab an allocation of a certain size
80731 * belongs to.
80732@@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
80733 * 2 = 120 .. 192 bytes
80734 * n = 2^(n-1) .. 2^n -1
80735 */
80736-static __always_inline int kmalloc_index(size_t size)
80737+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
80738 {
80739 if (!size)
80740 return 0;
80741@@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
80742 }
80743 #endif /* !CONFIG_SLOB */
80744
80745-void *__kmalloc(size_t size, gfp_t flags);
80746+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
80747 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
80748
80749 #ifdef CONFIG_NUMA
80750-void *__kmalloc_node(size_t size, gfp_t flags, int node);
80751+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
80752 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
80753 #else
80754 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
80755diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
80756index 09bfffb..4fc80fb 100644
80757--- a/include/linux/slab_def.h
80758+++ b/include/linux/slab_def.h
80759@@ -36,7 +36,7 @@ struct kmem_cache {
80760 /* 4) cache creation/removal */
80761 const char *name;
80762 struct list_head list;
80763- int refcount;
80764+ atomic_t refcount;
80765 int object_size;
80766 int align;
80767
80768@@ -52,10 +52,14 @@ struct kmem_cache {
80769 unsigned long node_allocs;
80770 unsigned long node_frees;
80771 unsigned long node_overflow;
80772- atomic_t allochit;
80773- atomic_t allocmiss;
80774- atomic_t freehit;
80775- atomic_t freemiss;
80776+ atomic_unchecked_t allochit;
80777+ atomic_unchecked_t allocmiss;
80778+ atomic_unchecked_t freehit;
80779+ atomic_unchecked_t freemiss;
80780+#ifdef CONFIG_PAX_MEMORY_SANITIZE
80781+ atomic_unchecked_t sanitized;
80782+ atomic_unchecked_t not_sanitized;
80783+#endif
80784
80785 /*
80786 * If debugging is enabled, then the allocator can add additional
80787diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
80788index f56bfa9..8378a26 100644
80789--- a/include/linux/slub_def.h
80790+++ b/include/linux/slub_def.h
80791@@ -74,7 +74,7 @@ struct kmem_cache {
80792 struct kmem_cache_order_objects max;
80793 struct kmem_cache_order_objects min;
80794 gfp_t allocflags; /* gfp flags to use on each alloc */
80795- int refcount; /* Refcount for slab cache destroy */
80796+ atomic_t refcount; /* Refcount for slab cache destroy */
80797 void (*ctor)(void *);
80798 int inuse; /* Offset to metadata */
80799 int align; /* Alignment */
80800diff --git a/include/linux/smp.h b/include/linux/smp.h
80801index 5da22ee..71d8a28 100644
80802--- a/include/linux/smp.h
80803+++ b/include/linux/smp.h
80804@@ -176,7 +176,9 @@ static inline void kick_all_cpus_sync(void) { }
80805 #endif
80806
80807 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
80808+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
80809 #define put_cpu() preempt_enable()
80810+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
80811
80812 /*
80813 * Callback to arch code if there's nosmp or maxcpus=0 on the
80814diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
80815index 54f91d3..be2c379 100644
80816--- a/include/linux/sock_diag.h
80817+++ b/include/linux/sock_diag.h
80818@@ -11,7 +11,7 @@ struct sock;
80819 struct sock_diag_handler {
80820 __u8 family;
80821 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
80822-};
80823+} __do_const;
80824
80825 int sock_diag_register(const struct sock_diag_handler *h);
80826 void sock_diag_unregister(const struct sock_diag_handler *h);
80827diff --git a/include/linux/sonet.h b/include/linux/sonet.h
80828index 680f9a3..f13aeb0 100644
80829--- a/include/linux/sonet.h
80830+++ b/include/linux/sonet.h
80831@@ -7,7 +7,7 @@
80832 #include <uapi/linux/sonet.h>
80833
80834 struct k_sonet_stats {
80835-#define __HANDLE_ITEM(i) atomic_t i
80836+#define __HANDLE_ITEM(i) atomic_unchecked_t i
80837 __SONET_ITEMS
80838 #undef __HANDLE_ITEM
80839 };
80840diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
80841index 07d8e53..dc934c9 100644
80842--- a/include/linux/sunrpc/addr.h
80843+++ b/include/linux/sunrpc/addr.h
80844@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
80845 {
80846 switch (sap->sa_family) {
80847 case AF_INET:
80848- return ntohs(((struct sockaddr_in *)sap)->sin_port);
80849+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
80850 case AF_INET6:
80851- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
80852+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
80853 }
80854 return 0;
80855 }
80856@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
80857 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
80858 const struct sockaddr *src)
80859 {
80860- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
80861+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
80862 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
80863
80864 dsin->sin_family = ssin->sin_family;
80865@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
80866 if (sa->sa_family != AF_INET6)
80867 return 0;
80868
80869- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
80870+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
80871 }
80872
80873 #endif /* _LINUX_SUNRPC_ADDR_H */
80874diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
80875index 8af2804..c7414ef 100644
80876--- a/include/linux/sunrpc/clnt.h
80877+++ b/include/linux/sunrpc/clnt.h
80878@@ -97,7 +97,7 @@ struct rpc_procinfo {
80879 unsigned int p_timer; /* Which RTT timer to use */
80880 u32 p_statidx; /* Which procedure to account */
80881 const char * p_name; /* name of procedure */
80882-};
80883+} __do_const;
80884
80885 #ifdef __KERNEL__
80886
80887diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
80888index 6eecfc2..7ada79d 100644
80889--- a/include/linux/sunrpc/svc.h
80890+++ b/include/linux/sunrpc/svc.h
80891@@ -410,7 +410,7 @@ struct svc_procedure {
80892 unsigned int pc_count; /* call count */
80893 unsigned int pc_cachetype; /* cache info (NFS) */
80894 unsigned int pc_xdrressize; /* maximum size of XDR reply */
80895-};
80896+} __do_const;
80897
80898 /*
80899 * Function prototypes.
80900diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
80901index 0b8e3e6..33e0a01 100644
80902--- a/include/linux/sunrpc/svc_rdma.h
80903+++ b/include/linux/sunrpc/svc_rdma.h
80904@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
80905 extern unsigned int svcrdma_max_requests;
80906 extern unsigned int svcrdma_max_req_size;
80907
80908-extern atomic_t rdma_stat_recv;
80909-extern atomic_t rdma_stat_read;
80910-extern atomic_t rdma_stat_write;
80911-extern atomic_t rdma_stat_sq_starve;
80912-extern atomic_t rdma_stat_rq_starve;
80913-extern atomic_t rdma_stat_rq_poll;
80914-extern atomic_t rdma_stat_rq_prod;
80915-extern atomic_t rdma_stat_sq_poll;
80916-extern atomic_t rdma_stat_sq_prod;
80917+extern atomic_unchecked_t rdma_stat_recv;
80918+extern atomic_unchecked_t rdma_stat_read;
80919+extern atomic_unchecked_t rdma_stat_write;
80920+extern atomic_unchecked_t rdma_stat_sq_starve;
80921+extern atomic_unchecked_t rdma_stat_rq_starve;
80922+extern atomic_unchecked_t rdma_stat_rq_poll;
80923+extern atomic_unchecked_t rdma_stat_rq_prod;
80924+extern atomic_unchecked_t rdma_stat_sq_poll;
80925+extern atomic_unchecked_t rdma_stat_sq_prod;
80926
80927 #define RPCRDMA_VERSION 1
80928
80929diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
80930index 8d71d65..f79586e 100644
80931--- a/include/linux/sunrpc/svcauth.h
80932+++ b/include/linux/sunrpc/svcauth.h
80933@@ -120,7 +120,7 @@ struct auth_ops {
80934 int (*release)(struct svc_rqst *rq);
80935 void (*domain_release)(struct auth_domain *);
80936 int (*set_client)(struct svc_rqst *rq);
80937-};
80938+} __do_const;
80939
80940 #define SVC_GARBAGE 1
80941 #define SVC_SYSERR 2
80942diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
80943index a5ffd32..0935dea 100644
80944--- a/include/linux/swiotlb.h
80945+++ b/include/linux/swiotlb.h
80946@@ -60,7 +60,8 @@ extern void
80947
80948 extern void
80949 swiotlb_free_coherent(struct device *hwdev, size_t size,
80950- void *vaddr, dma_addr_t dma_handle);
80951+ void *vaddr, dma_addr_t dma_handle,
80952+ struct dma_attrs *attrs);
80953
80954 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
80955 unsigned long offset, size_t size,
80956diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
80957index 94273bb..c2e05fc 100644
80958--- a/include/linux/syscalls.h
80959+++ b/include/linux/syscalls.h
80960@@ -97,8 +97,14 @@ struct sigaltstack;
80961 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
80962
80963 #define __SC_DECL(t, a) t a
80964+#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))
80965 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
80966-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
80967+#define __SC_LONG(t, a) __typeof( \
80968+ __builtin_choose_expr( \
80969+ sizeof(t) > sizeof(int), \
80970+ (t) 0, \
80971+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
80972+ )) a
80973 #define __SC_CAST(t, a) (t) a
80974 #define __SC_ARGS(t, a) a
80975 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
80976@@ -363,11 +369,11 @@ asmlinkage long sys_sync(void);
80977 asmlinkage long sys_fsync(unsigned int fd);
80978 asmlinkage long sys_fdatasync(unsigned int fd);
80979 asmlinkage long sys_bdflush(int func, long data);
80980-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
80981- char __user *type, unsigned long flags,
80982+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
80983+ const char __user *type, unsigned long flags,
80984 void __user *data);
80985-asmlinkage long sys_umount(char __user *name, int flags);
80986-asmlinkage long sys_oldumount(char __user *name);
80987+asmlinkage long sys_umount(const char __user *name, int flags);
80988+asmlinkage long sys_oldumount(const char __user *name);
80989 asmlinkage long sys_truncate(const char __user *path, long length);
80990 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
80991 asmlinkage long sys_stat(const char __user *filename,
80992@@ -579,7 +585,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
80993 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
80994 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
80995 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
80996- struct sockaddr __user *, int);
80997+ struct sockaddr __user *, int) __intentional_overflow(0);
80998 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
80999 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
81000 unsigned int vlen, unsigned flags);
81001diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
81002index 27b3b0b..e093dd9 100644
81003--- a/include/linux/syscore_ops.h
81004+++ b/include/linux/syscore_ops.h
81005@@ -16,7 +16,7 @@ struct syscore_ops {
81006 int (*suspend)(void);
81007 void (*resume)(void);
81008 void (*shutdown)(void);
81009-};
81010+} __do_const;
81011
81012 extern void register_syscore_ops(struct syscore_ops *ops);
81013 extern void unregister_syscore_ops(struct syscore_ops *ops);
81014diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
81015index 14a8ff2..fa95f3a 100644
81016--- a/include/linux/sysctl.h
81017+++ b/include/linux/sysctl.h
81018@@ -34,13 +34,13 @@ struct ctl_table_root;
81019 struct ctl_table_header;
81020 struct ctl_dir;
81021
81022-typedef struct ctl_table ctl_table;
81023-
81024 typedef int proc_handler (struct ctl_table *ctl, int write,
81025 void __user *buffer, size_t *lenp, loff_t *ppos);
81026
81027 extern int proc_dostring(struct ctl_table *, int,
81028 void __user *, size_t *, loff_t *);
81029+extern int proc_dostring_modpriv(struct ctl_table *, int,
81030+ void __user *, size_t *, loff_t *);
81031 extern int proc_dointvec(struct ctl_table *, int,
81032 void __user *, size_t *, loff_t *);
81033 extern int proc_dointvec_minmax(struct ctl_table *, int,
81034@@ -115,7 +115,9 @@ struct ctl_table
81035 struct ctl_table_poll *poll;
81036 void *extra1;
81037 void *extra2;
81038-};
81039+} __do_const __randomize_layout;
81040+typedef struct ctl_table __no_const ctl_table_no_const;
81041+typedef struct ctl_table ctl_table;
81042
81043 struct ctl_node {
81044 struct rb_node node;
81045diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
81046index 6695040..3d4192d 100644
81047--- a/include/linux/sysfs.h
81048+++ b/include/linux/sysfs.h
81049@@ -33,7 +33,8 @@ struct attribute {
81050 struct lock_class_key *key;
81051 struct lock_class_key skey;
81052 #endif
81053-};
81054+} __do_const;
81055+typedef struct attribute __no_const attribute_no_const;
81056
81057 /**
81058 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
81059@@ -62,7 +63,8 @@ struct attribute_group {
81060 struct attribute *, int);
81061 struct attribute **attrs;
81062 struct bin_attribute **bin_attrs;
81063-};
81064+} __do_const;
81065+typedef struct attribute_group __no_const attribute_group_no_const;
81066
81067 /**
81068 * Use these macros to make defining attributes easier. See include/linux/device.h
81069@@ -126,7 +128,8 @@ struct bin_attribute {
81070 char *, loff_t, size_t);
81071 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
81072 struct vm_area_struct *vma);
81073-};
81074+} __do_const;
81075+typedef struct bin_attribute __no_const bin_attribute_no_const;
81076
81077 /**
81078 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
81079diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
81080index 387fa7d..3fcde6b 100644
81081--- a/include/linux/sysrq.h
81082+++ b/include/linux/sysrq.h
81083@@ -16,6 +16,7 @@
81084
81085 #include <linux/errno.h>
81086 #include <linux/types.h>
81087+#include <linux/compiler.h>
81088
81089 /* Possible values of bitmask for enabling sysrq functions */
81090 /* 0x0001 is reserved for enable everything */
81091@@ -33,7 +34,7 @@ struct sysrq_key_op {
81092 char *help_msg;
81093 char *action_msg;
81094 int enable_mask;
81095-};
81096+} __do_const;
81097
81098 #ifdef CONFIG_MAGIC_SYSRQ
81099
81100diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
81101index fddbe20..0312de8 100644
81102--- a/include/linux/thread_info.h
81103+++ b/include/linux/thread_info.h
81104@@ -161,6 +161,15 @@ static inline bool test_and_clear_restore_sigmask(void)
81105 #error "no set_restore_sigmask() provided and default one won't work"
81106 #endif
81107
81108+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
81109+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
81110+{
81111+#ifndef CONFIG_PAX_USERCOPY_DEBUG
81112+ if (!__builtin_constant_p(n))
81113+#endif
81114+ __check_object_size(ptr, n, to_user);
81115+}
81116+
81117 #endif /* __KERNEL__ */
81118
81119 #endif /* _LINUX_THREAD_INFO_H */
81120diff --git a/include/linux/tty.h b/include/linux/tty.h
81121index 97d660e..6356755 100644
81122--- a/include/linux/tty.h
81123+++ b/include/linux/tty.h
81124@@ -196,7 +196,7 @@ struct tty_port {
81125 const struct tty_port_operations *ops; /* Port operations */
81126 spinlock_t lock; /* Lock protecting tty field */
81127 int blocked_open; /* Waiting to open */
81128- int count; /* Usage count */
81129+ atomic_t count; /* Usage count */
81130 wait_queue_head_t open_wait; /* Open waiters */
81131 wait_queue_head_t close_wait; /* Close waiters */
81132 wait_queue_head_t delta_msr_wait; /* Modem status change */
81133@@ -278,7 +278,7 @@ struct tty_struct {
81134 /* If the tty has a pending do_SAK, queue it here - akpm */
81135 struct work_struct SAK_work;
81136 struct tty_port *port;
81137-};
81138+} __randomize_layout;
81139
81140 /* Each of a tty's open files has private_data pointing to tty_file_private */
81141 struct tty_file_private {
81142@@ -545,7 +545,7 @@ extern int tty_port_open(struct tty_port *port,
81143 struct tty_struct *tty, struct file *filp);
81144 static inline int tty_port_users(struct tty_port *port)
81145 {
81146- return port->count + port->blocked_open;
81147+ return atomic_read(&port->count) + port->blocked_open;
81148 }
81149
81150 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
81151diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
81152index 756a609..f61242d 100644
81153--- a/include/linux/tty_driver.h
81154+++ b/include/linux/tty_driver.h
81155@@ -285,7 +285,7 @@ struct tty_operations {
81156 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
81157 #endif
81158 const struct file_operations *proc_fops;
81159-};
81160+} __do_const;
81161
81162 struct tty_driver {
81163 int magic; /* magic number for this structure */
81164@@ -319,7 +319,7 @@ struct tty_driver {
81165
81166 const struct tty_operations *ops;
81167 struct list_head tty_drivers;
81168-};
81169+} __randomize_layout;
81170
81171 extern struct list_head tty_drivers;
81172
81173diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
81174index f15c898..207b7d1 100644
81175--- a/include/linux/tty_ldisc.h
81176+++ b/include/linux/tty_ldisc.h
81177@@ -211,7 +211,7 @@ struct tty_ldisc_ops {
81178
81179 struct module *owner;
81180
81181- int refcount;
81182+ atomic_t refcount;
81183 };
81184
81185 struct tty_ldisc {
81186diff --git a/include/linux/types.h b/include/linux/types.h
81187index 4d118ba..c3ee9bf 100644
81188--- a/include/linux/types.h
81189+++ b/include/linux/types.h
81190@@ -176,10 +176,26 @@ typedef struct {
81191 int counter;
81192 } atomic_t;
81193
81194+#ifdef CONFIG_PAX_REFCOUNT
81195+typedef struct {
81196+ int counter;
81197+} atomic_unchecked_t;
81198+#else
81199+typedef atomic_t atomic_unchecked_t;
81200+#endif
81201+
81202 #ifdef CONFIG_64BIT
81203 typedef struct {
81204 long counter;
81205 } atomic64_t;
81206+
81207+#ifdef CONFIG_PAX_REFCOUNT
81208+typedef struct {
81209+ long counter;
81210+} atomic64_unchecked_t;
81211+#else
81212+typedef atomic64_t atomic64_unchecked_t;
81213+#endif
81214 #endif
81215
81216 struct list_head {
81217diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
81218index 9d8cf05..0ed74dd 100644
81219--- a/include/linux/uaccess.h
81220+++ b/include/linux/uaccess.h
81221@@ -72,11 +72,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
81222 long ret; \
81223 mm_segment_t old_fs = get_fs(); \
81224 \
81225- set_fs(KERNEL_DS); \
81226 pagefault_disable(); \
81227- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
81228- pagefault_enable(); \
81229+ set_fs(KERNEL_DS); \
81230+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
81231 set_fs(old_fs); \
81232+ pagefault_enable(); \
81233 ret; \
81234 })
81235
81236diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
81237index 8e522cbc..aa8572d 100644
81238--- a/include/linux/uidgid.h
81239+++ b/include/linux/uidgid.h
81240@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
81241
81242 #endif /* CONFIG_USER_NS */
81243
81244+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
81245+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
81246+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
81247+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
81248+
81249 #endif /* _LINUX_UIDGID_H */
81250diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
81251index 99c1b4d..562e6f3 100644
81252--- a/include/linux/unaligned/access_ok.h
81253+++ b/include/linux/unaligned/access_ok.h
81254@@ -4,34 +4,34 @@
81255 #include <linux/kernel.h>
81256 #include <asm/byteorder.h>
81257
81258-static inline u16 get_unaligned_le16(const void *p)
81259+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
81260 {
81261- return le16_to_cpup((__le16 *)p);
81262+ return le16_to_cpup((const __le16 *)p);
81263 }
81264
81265-static inline u32 get_unaligned_le32(const void *p)
81266+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
81267 {
81268- return le32_to_cpup((__le32 *)p);
81269+ return le32_to_cpup((const __le32 *)p);
81270 }
81271
81272-static inline u64 get_unaligned_le64(const void *p)
81273+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
81274 {
81275- return le64_to_cpup((__le64 *)p);
81276+ return le64_to_cpup((const __le64 *)p);
81277 }
81278
81279-static inline u16 get_unaligned_be16(const void *p)
81280+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
81281 {
81282- return be16_to_cpup((__be16 *)p);
81283+ return be16_to_cpup((const __be16 *)p);
81284 }
81285
81286-static inline u32 get_unaligned_be32(const void *p)
81287+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
81288 {
81289- return be32_to_cpup((__be32 *)p);
81290+ return be32_to_cpup((const __be32 *)p);
81291 }
81292
81293-static inline u64 get_unaligned_be64(const void *p)
81294+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
81295 {
81296- return be64_to_cpup((__be64 *)p);
81297+ return be64_to_cpup((const __be64 *)p);
81298 }
81299
81300 static inline void put_unaligned_le16(u16 val, void *p)
81301diff --git a/include/linux/usb.h b/include/linux/usb.h
81302index 512ab16..f53e1bf 100644
81303--- a/include/linux/usb.h
81304+++ b/include/linux/usb.h
81305@@ -563,7 +563,7 @@ struct usb_device {
81306 int maxchild;
81307
81308 u32 quirks;
81309- atomic_t urbnum;
81310+ atomic_unchecked_t urbnum;
81311
81312 unsigned long active_duration;
81313
81314@@ -1643,7 +1643,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
81315
81316 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
81317 __u8 request, __u8 requesttype, __u16 value, __u16 index,
81318- void *data, __u16 size, int timeout);
81319+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
81320 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
81321 void *data, int len, int *actual_length, int timeout);
81322 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
81323diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
81324index e452ba6..78f8e80 100644
81325--- a/include/linux/usb/renesas_usbhs.h
81326+++ b/include/linux/usb/renesas_usbhs.h
81327@@ -39,7 +39,7 @@ enum {
81328 */
81329 struct renesas_usbhs_driver_callback {
81330 int (*notify_hotplug)(struct platform_device *pdev);
81331-};
81332+} __no_const;
81333
81334 /*
81335 * callback functions for platform
81336diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
81337index 4836ba3..603f6ee 100644
81338--- a/include/linux/user_namespace.h
81339+++ b/include/linux/user_namespace.h
81340@@ -33,7 +33,7 @@ struct user_namespace {
81341 struct key *persistent_keyring_register;
81342 struct rw_semaphore persistent_keyring_register_sem;
81343 #endif
81344-};
81345+} __randomize_layout;
81346
81347 extern struct user_namespace init_user_ns;
81348
81349diff --git a/include/linux/utsname.h b/include/linux/utsname.h
81350index 239e277..22a5cf5 100644
81351--- a/include/linux/utsname.h
81352+++ b/include/linux/utsname.h
81353@@ -24,7 +24,7 @@ struct uts_namespace {
81354 struct new_utsname name;
81355 struct user_namespace *user_ns;
81356 unsigned int proc_inum;
81357-};
81358+} __randomize_layout;
81359 extern struct uts_namespace init_uts_ns;
81360
81361 #ifdef CONFIG_UTS_NS
81362diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
81363index 6f8fbcf..4efc177 100644
81364--- a/include/linux/vermagic.h
81365+++ b/include/linux/vermagic.h
81366@@ -25,9 +25,42 @@
81367 #define MODULE_ARCH_VERMAGIC ""
81368 #endif
81369
81370+#ifdef CONFIG_PAX_REFCOUNT
81371+#define MODULE_PAX_REFCOUNT "REFCOUNT "
81372+#else
81373+#define MODULE_PAX_REFCOUNT ""
81374+#endif
81375+
81376+#ifdef CONSTIFY_PLUGIN
81377+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
81378+#else
81379+#define MODULE_CONSTIFY_PLUGIN ""
81380+#endif
81381+
81382+#ifdef STACKLEAK_PLUGIN
81383+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
81384+#else
81385+#define MODULE_STACKLEAK_PLUGIN ""
81386+#endif
81387+
81388+#ifdef RANDSTRUCT_PLUGIN
81389+#include <generated/randomize_layout_hash.h>
81390+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
81391+#else
81392+#define MODULE_RANDSTRUCT_PLUGIN
81393+#endif
81394+
81395+#ifdef CONFIG_GRKERNSEC
81396+#define MODULE_GRSEC "GRSEC "
81397+#else
81398+#define MODULE_GRSEC ""
81399+#endif
81400+
81401 #define VERMAGIC_STRING \
81402 UTS_RELEASE " " \
81403 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
81404 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
81405- MODULE_ARCH_VERMAGIC
81406+ MODULE_ARCH_VERMAGIC \
81407+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
81408+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
81409
81410diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
81411index 502073a..a7de024 100644
81412--- a/include/linux/vga_switcheroo.h
81413+++ b/include/linux/vga_switcheroo.h
81414@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
81415
81416 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
81417
81418-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
81419-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
81420+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
81421+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
81422 #else
81423
81424 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
81425@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
81426
81427 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
81428
81429-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
81430-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
81431+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
81432+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
81433
81434 #endif
81435 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
81436diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
81437index 4b8a891..cb8df6e 100644
81438--- a/include/linux/vmalloc.h
81439+++ b/include/linux/vmalloc.h
81440@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
81441 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
81442 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
81443 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
81444+
81445+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
81446+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
81447+#endif
81448+
81449 /* bits [20..32] reserved for arch specific ioremap internals */
81450
81451 /*
81452@@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
81453
81454 /* for /dev/kmem */
81455 extern long vread(char *buf, char *addr, unsigned long count);
81456-extern long vwrite(char *buf, char *addr, unsigned long count);
81457+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
81458
81459 /*
81460 * Internals. Dont't use..
81461diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
81462index e4b9480..5a5f65a 100644
81463--- a/include/linux/vmstat.h
81464+++ b/include/linux/vmstat.h
81465@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
81466 /*
81467 * Zone based page accounting with per cpu differentials.
81468 */
81469-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81470+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81471
81472 static inline void zone_page_state_add(long x, struct zone *zone,
81473 enum zone_stat_item item)
81474 {
81475- atomic_long_add(x, &zone->vm_stat[item]);
81476- atomic_long_add(x, &vm_stat[item]);
81477+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
81478+ atomic_long_add_unchecked(x, &vm_stat[item]);
81479 }
81480
81481-static inline unsigned long global_page_state(enum zone_stat_item item)
81482+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
81483 {
81484- long x = atomic_long_read(&vm_stat[item]);
81485+ long x = atomic_long_read_unchecked(&vm_stat[item]);
81486 #ifdef CONFIG_SMP
81487 if (x < 0)
81488 x = 0;
81489@@ -109,10 +109,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
81490 return x;
81491 }
81492
81493-static inline unsigned long zone_page_state(struct zone *zone,
81494+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
81495 enum zone_stat_item item)
81496 {
81497- long x = atomic_long_read(&zone->vm_stat[item]);
81498+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
81499 #ifdef CONFIG_SMP
81500 if (x < 0)
81501 x = 0;
81502@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
81503 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
81504 enum zone_stat_item item)
81505 {
81506- long x = atomic_long_read(&zone->vm_stat[item]);
81507+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
81508
81509 #ifdef CONFIG_SMP
81510 int cpu;
81511@@ -220,8 +220,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
81512
81513 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
81514 {
81515- atomic_long_inc(&zone->vm_stat[item]);
81516- atomic_long_inc(&vm_stat[item]);
81517+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
81518+ atomic_long_inc_unchecked(&vm_stat[item]);
81519 }
81520
81521 static inline void __inc_zone_page_state(struct page *page,
81522@@ -232,8 +232,8 @@ static inline void __inc_zone_page_state(struct page *page,
81523
81524 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
81525 {
81526- atomic_long_dec(&zone->vm_stat[item]);
81527- atomic_long_dec(&vm_stat[item]);
81528+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
81529+ atomic_long_dec_unchecked(&vm_stat[item]);
81530 }
81531
81532 static inline void __dec_zone_page_state(struct page *page,
81533diff --git a/include/linux/xattr.h b/include/linux/xattr.h
81534index 91b0a68..0e9adf6 100644
81535--- a/include/linux/xattr.h
81536+++ b/include/linux/xattr.h
81537@@ -28,7 +28,7 @@ struct xattr_handler {
81538 size_t size, int handler_flags);
81539 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
81540 size_t size, int flags, int handler_flags);
81541-};
81542+} __do_const;
81543
81544 struct xattr {
81545 const char *name;
81546@@ -37,6 +37,9 @@ struct xattr {
81547 };
81548
81549 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
81550+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
81551+ssize_t pax_getxattr(struct dentry *, void *, size_t);
81552+#endif
81553 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
81554 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
81555 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
81556diff --git a/include/linux/zlib.h b/include/linux/zlib.h
81557index 9c5a6b4..09c9438 100644
81558--- a/include/linux/zlib.h
81559+++ b/include/linux/zlib.h
81560@@ -31,6 +31,7 @@
81561 #define _ZLIB_H
81562
81563 #include <linux/zconf.h>
81564+#include <linux/compiler.h>
81565
81566 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
81567 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
81568@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
81569
81570 /* basic functions */
81571
81572-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
81573+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
81574 /*
81575 Returns the number of bytes that needs to be allocated for a per-
81576 stream workspace with the specified parameters. A pointer to this
81577diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
81578index c768c9f..bdcaa5a 100644
81579--- a/include/media/v4l2-dev.h
81580+++ b/include/media/v4l2-dev.h
81581@@ -76,7 +76,7 @@ struct v4l2_file_operations {
81582 int (*mmap) (struct file *, struct vm_area_struct *);
81583 int (*open) (struct file *);
81584 int (*release) (struct file *);
81585-};
81586+} __do_const;
81587
81588 /*
81589 * Newer version of video_device, handled by videodev2.c
81590diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
81591index c9b1593..a572459 100644
81592--- a/include/media/v4l2-device.h
81593+++ b/include/media/v4l2-device.h
81594@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
81595 this function returns 0. If the name ends with a digit (e.g. cx18),
81596 then the name will be set to cx18-0 since cx180 looks really odd. */
81597 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
81598- atomic_t *instance);
81599+ atomic_unchecked_t *instance);
81600
81601 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
81602 Since the parent disappears this ensures that v4l2_dev doesn't have an
81603diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
81604index 9a36d92..0aafe2a 100644
81605--- a/include/net/9p/transport.h
81606+++ b/include/net/9p/transport.h
81607@@ -60,7 +60,7 @@ struct p9_trans_module {
81608 int (*cancel) (struct p9_client *, struct p9_req_t *req);
81609 int (*zc_request)(struct p9_client *, struct p9_req_t *,
81610 char *, char *, int , int, int, int);
81611-};
81612+} __do_const;
81613
81614 void v9fs_register_trans(struct p9_trans_module *m);
81615 void v9fs_unregister_trans(struct p9_trans_module *m);
81616diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
81617index c853b16d..37fccb7 100644
81618--- a/include/net/bluetooth/l2cap.h
81619+++ b/include/net/bluetooth/l2cap.h
81620@@ -557,7 +557,7 @@ struct l2cap_ops {
81621 long (*get_sndtimeo) (struct l2cap_chan *chan);
81622 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
81623 unsigned long len, int nb);
81624-};
81625+} __do_const;
81626
81627 struct l2cap_conn {
81628 struct hci_conn *hcon;
81629diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
81630index f2ae33d..c457cf0 100644
81631--- a/include/net/caif/cfctrl.h
81632+++ b/include/net/caif/cfctrl.h
81633@@ -52,7 +52,7 @@ struct cfctrl_rsp {
81634 void (*radioset_rsp)(void);
81635 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
81636 struct cflayer *client_layer);
81637-};
81638+} __no_const;
81639
81640 /* Link Setup Parameters for CAIF-Links. */
81641 struct cfctrl_link_param {
81642@@ -101,8 +101,8 @@ struct cfctrl_request_info {
81643 struct cfctrl {
81644 struct cfsrvl serv;
81645 struct cfctrl_rsp res;
81646- atomic_t req_seq_no;
81647- atomic_t rsp_seq_no;
81648+ atomic_unchecked_t req_seq_no;
81649+ atomic_unchecked_t rsp_seq_no;
81650 struct list_head list;
81651 /* Protects from simultaneous access to first_req list */
81652 spinlock_t info_list_lock;
81653diff --git a/include/net/flow.h b/include/net/flow.h
81654index 65ce471..b7bbe9b 100644
81655--- a/include/net/flow.h
81656+++ b/include/net/flow.h
81657@@ -222,6 +222,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
81658
81659 void flow_cache_flush(void);
81660 void flow_cache_flush_deferred(void);
81661-extern atomic_t flow_cache_genid;
81662+extern atomic_unchecked_t flow_cache_genid;
81663
81664 #endif
81665diff --git a/include/net/genetlink.h b/include/net/genetlink.h
81666index 1b177ed..a24a138 100644
81667--- a/include/net/genetlink.h
81668+++ b/include/net/genetlink.h
81669@@ -118,7 +118,7 @@ struct genl_ops {
81670 u8 cmd;
81671 u8 internal_flags;
81672 u8 flags;
81673-};
81674+} __do_const;
81675
81676 int __genl_register_family(struct genl_family *family);
81677
81678diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
81679index 734d9b5..48a9a4b 100644
81680--- a/include/net/gro_cells.h
81681+++ b/include/net/gro_cells.h
81682@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
81683 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
81684
81685 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
81686- atomic_long_inc(&dev->rx_dropped);
81687+ atomic_long_inc_unchecked(&dev->rx_dropped);
81688 kfree_skb(skb);
81689 return;
81690 }
81691diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
81692index c55aeed..b3393f4 100644
81693--- a/include/net/inet_connection_sock.h
81694+++ b/include/net/inet_connection_sock.h
81695@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
81696 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
81697 int (*bind_conflict)(const struct sock *sk,
81698 const struct inet_bind_bucket *tb, bool relax);
81699-};
81700+} __do_const;
81701
81702 /** inet_connection_sock - INET connection oriented sock
81703 *
81704diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
81705index f4e127a..c3d5e9c 100644
81706--- a/include/net/inetpeer.h
81707+++ b/include/net/inetpeer.h
81708@@ -47,8 +47,8 @@ struct inet_peer {
81709 */
81710 union {
81711 struct {
81712- atomic_t rid; /* Frag reception counter */
81713- atomic_t ip_id_count; /* IP ID for the next packet */
81714+ atomic_unchecked_t rid; /* Frag reception counter */
81715+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
81716 };
81717 struct rcu_head rcu;
81718 struct inet_peer *gc_next;
81719@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
81720 /* can be called with or without local BH being disabled */
81721 static inline int inet_getid(struct inet_peer *p, int more)
81722 {
81723- int old, new;
81724+ int id;
81725 more++;
81726 inet_peer_refcheck(p);
81727- do {
81728- old = atomic_read(&p->ip_id_count);
81729- new = old + more;
81730- if (!new)
81731- new = 1;
81732- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
81733- return new;
81734+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
81735+ if (!id)
81736+ id = atomic_inc_return_unchecked(&p->ip_id_count);
81737+ return id;
81738 }
81739
81740 #endif /* _NET_INETPEER_H */
81741diff --git a/include/net/ip.h b/include/net/ip.h
81742index 5a25f36..2e73203 100644
81743--- a/include/net/ip.h
81744+++ b/include/net/ip.h
81745@@ -219,7 +219,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
81746
81747 void inet_get_local_port_range(struct net *net, int *low, int *high);
81748
81749-extern unsigned long *sysctl_local_reserved_ports;
81750+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
81751 static inline int inet_is_reserved_local_port(int port)
81752 {
81753 return test_bit(port, sysctl_local_reserved_ports);
81754diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
81755index 9922093..a1755d6 100644
81756--- a/include/net/ip_fib.h
81757+++ b/include/net/ip_fib.h
81758@@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
81759
81760 #define FIB_RES_SADDR(net, res) \
81761 ((FIB_RES_NH(res).nh_saddr_genid == \
81762- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
81763+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
81764 FIB_RES_NH(res).nh_saddr : \
81765 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
81766 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
81767diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
81768index 5679d92..2e7a690 100644
81769--- a/include/net/ip_vs.h
81770+++ b/include/net/ip_vs.h
81771@@ -558,7 +558,7 @@ struct ip_vs_conn {
81772 struct ip_vs_conn *control; /* Master control connection */
81773 atomic_t n_control; /* Number of controlled ones */
81774 struct ip_vs_dest *dest; /* real server */
81775- atomic_t in_pkts; /* incoming packet counter */
81776+ atomic_unchecked_t in_pkts; /* incoming packet counter */
81777
81778 /* packet transmitter for different forwarding methods. If it
81779 mangles the packet, it must return NF_DROP or better NF_STOLEN,
81780@@ -705,7 +705,7 @@ struct ip_vs_dest {
81781 __be16 port; /* port number of the server */
81782 union nf_inet_addr addr; /* IP address of the server */
81783 volatile unsigned int flags; /* dest status flags */
81784- atomic_t conn_flags; /* flags to copy to conn */
81785+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
81786 atomic_t weight; /* server weight */
81787
81788 atomic_t refcnt; /* reference counter */
81789@@ -960,11 +960,11 @@ struct netns_ipvs {
81790 /* ip_vs_lblc */
81791 int sysctl_lblc_expiration;
81792 struct ctl_table_header *lblc_ctl_header;
81793- struct ctl_table *lblc_ctl_table;
81794+ ctl_table_no_const *lblc_ctl_table;
81795 /* ip_vs_lblcr */
81796 int sysctl_lblcr_expiration;
81797 struct ctl_table_header *lblcr_ctl_header;
81798- struct ctl_table *lblcr_ctl_table;
81799+ ctl_table_no_const *lblcr_ctl_table;
81800 /* ip_vs_est */
81801 struct list_head est_list; /* estimator list */
81802 spinlock_t est_lock;
81803diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
81804index 0224402..dafaf94a 100644
81805--- a/include/net/irda/ircomm_tty.h
81806+++ b/include/net/irda/ircomm_tty.h
81807@@ -35,6 +35,7 @@
81808 #include <linux/termios.h>
81809 #include <linux/timer.h>
81810 #include <linux/tty.h> /* struct tty_struct */
81811+#include <asm/local.h>
81812
81813 #include <net/irda/irias_object.h>
81814 #include <net/irda/ircomm_core.h>
81815diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
81816index 714cc9a..ea05f3e 100644
81817--- a/include/net/iucv/af_iucv.h
81818+++ b/include/net/iucv/af_iucv.h
81819@@ -149,7 +149,7 @@ struct iucv_skb_cb {
81820 struct iucv_sock_list {
81821 struct hlist_head head;
81822 rwlock_t lock;
81823- atomic_t autobind_name;
81824+ atomic_unchecked_t autobind_name;
81825 };
81826
81827 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
81828diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
81829index f3be818..bf46196 100644
81830--- a/include/net/llc_c_ac.h
81831+++ b/include/net/llc_c_ac.h
81832@@ -87,7 +87,7 @@
81833 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
81834 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
81835
81836-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
81837+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
81838
81839 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
81840 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
81841diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
81842index 3948cf1..83b28c4 100644
81843--- a/include/net/llc_c_ev.h
81844+++ b/include/net/llc_c_ev.h
81845@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
81846 return (struct llc_conn_state_ev *)skb->cb;
81847 }
81848
81849-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
81850-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
81851+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
81852+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
81853
81854 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
81855 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
81856diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
81857index 0e79cfb..f46db31 100644
81858--- a/include/net/llc_c_st.h
81859+++ b/include/net/llc_c_st.h
81860@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
81861 u8 next_state;
81862 llc_conn_ev_qfyr_t *ev_qualifiers;
81863 llc_conn_action_t *ev_actions;
81864-};
81865+} __do_const;
81866
81867 struct llc_conn_state {
81868 u8 current_state;
81869diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
81870index a61b98c..aade1eb 100644
81871--- a/include/net/llc_s_ac.h
81872+++ b/include/net/llc_s_ac.h
81873@@ -23,7 +23,7 @@
81874 #define SAP_ACT_TEST_IND 9
81875
81876 /* All action functions must look like this */
81877-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
81878+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
81879
81880 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
81881 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
81882diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
81883index 567c681..cd73ac0 100644
81884--- a/include/net/llc_s_st.h
81885+++ b/include/net/llc_s_st.h
81886@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
81887 llc_sap_ev_t ev;
81888 u8 next_state;
81889 llc_sap_action_t *ev_actions;
81890-};
81891+} __do_const;
81892
81893 struct llc_sap_state {
81894 u8 curr_state;
81895diff --git a/include/net/mac80211.h b/include/net/mac80211.h
81896index 7ceed99..d3ffaa2 100644
81897--- a/include/net/mac80211.h
81898+++ b/include/net/mac80211.h
81899@@ -4407,7 +4407,7 @@ struct rate_control_ops {
81900 void (*add_sta_debugfs)(void *priv, void *priv_sta,
81901 struct dentry *dir);
81902 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
81903-};
81904+} __do_const;
81905
81906 static inline int rate_supported(struct ieee80211_sta *sta,
81907 enum ieee80211_band band,
81908diff --git a/include/net/neighbour.h b/include/net/neighbour.h
81909index 536501a..74ad02bc 100644
81910--- a/include/net/neighbour.h
81911+++ b/include/net/neighbour.h
81912@@ -123,7 +123,7 @@ struct neigh_ops {
81913 void (*error_report)(struct neighbour *, struct sk_buff *);
81914 int (*output)(struct neighbour *, struct sk_buff *);
81915 int (*connected_output)(struct neighbour *, struct sk_buff *);
81916-};
81917+} __do_const;
81918
81919 struct pneigh_entry {
81920 struct pneigh_entry *next;
81921@@ -178,7 +178,7 @@ struct neigh_table {
81922 struct neigh_statistics __percpu *stats;
81923 struct neigh_hash_table __rcu *nht;
81924 struct pneigh_entry **phash_buckets;
81925-};
81926+} __randomize_layout;
81927
81928 #define NEIGH_PRIV_ALIGN sizeof(long long)
81929 #define NEIGH_ENTRY_SIZE(size) ALIGN((size), NEIGH_PRIV_ALIGN)
81930diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
81931index da68c9a..c4a0720 100644
81932--- a/include/net/net_namespace.h
81933+++ b/include/net/net_namespace.h
81934@@ -124,8 +124,8 @@ struct net {
81935 struct netns_ipvs *ipvs;
81936 #endif
81937 struct sock *diag_nlsk;
81938- atomic_t fnhe_genid;
81939-};
81940+ atomic_unchecked_t fnhe_genid;
81941+} __randomize_layout;
81942
81943 /*
81944 * ifindex generation is per-net namespace, and loopback is
81945@@ -281,7 +281,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
81946 #define __net_init __init
81947 #define __net_exit __exit_refok
81948 #define __net_initdata __initdata
81949+#ifdef CONSTIFY_PLUGIN
81950 #define __net_initconst __initconst
81951+#else
81952+#define __net_initconst __initdata
81953+#endif
81954 #endif
81955
81956 struct pernet_operations {
81957@@ -291,7 +295,7 @@ struct pernet_operations {
81958 void (*exit_batch)(struct list_head *net_exit_list);
81959 int *id;
81960 size_t size;
81961-};
81962+} __do_const;
81963
81964 /*
81965 * Use these carefully. If you implement a network device and it
81966@@ -339,23 +343,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
81967
81968 static inline int rt_genid_ipv4(struct net *net)
81969 {
81970- return atomic_read(&net->ipv4.rt_genid);
81971+ return atomic_read_unchecked(&net->ipv4.rt_genid);
81972 }
81973
81974 static inline void rt_genid_bump_ipv4(struct net *net)
81975 {
81976- atomic_inc(&net->ipv4.rt_genid);
81977+ atomic_inc_unchecked(&net->ipv4.rt_genid);
81978 }
81979
81980 #if IS_ENABLED(CONFIG_IPV6)
81981 static inline int rt_genid_ipv6(struct net *net)
81982 {
81983- return atomic_read(&net->ipv6.rt_genid);
81984+ return atomic_read_unchecked(&net->ipv6.rt_genid);
81985 }
81986
81987 static inline void rt_genid_bump_ipv6(struct net *net)
81988 {
81989- atomic_inc(&net->ipv6.rt_genid);
81990+ atomic_inc_unchecked(&net->ipv6.rt_genid);
81991 }
81992 #else
81993 static inline int rt_genid_ipv6(struct net *net)
81994@@ -377,12 +381,12 @@ static inline void rt_genid_bump_all(struct net *net)
81995
81996 static inline int fnhe_genid(struct net *net)
81997 {
81998- return atomic_read(&net->fnhe_genid);
81999+ return atomic_read_unchecked(&net->fnhe_genid);
82000 }
82001
82002 static inline void fnhe_genid_bump(struct net *net)
82003 {
82004- atomic_inc(&net->fnhe_genid);
82005+ atomic_inc_unchecked(&net->fnhe_genid);
82006 }
82007
82008 #endif /* __NET_NET_NAMESPACE_H */
82009diff --git a/include/net/netdma.h b/include/net/netdma.h
82010index 8ba8ce2..99b7fff 100644
82011--- a/include/net/netdma.h
82012+++ b/include/net/netdma.h
82013@@ -24,7 +24,7 @@
82014 #include <linux/dmaengine.h>
82015 #include <linux/skbuff.h>
82016
82017-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
82018+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
82019 struct sk_buff *skb, int offset, struct iovec *to,
82020 size_t len, struct dma_pinned_list *pinned_list);
82021
82022diff --git a/include/net/netlink.h b/include/net/netlink.h
82023index 2b47eaa..6d5bcc2 100644
82024--- a/include/net/netlink.h
82025+++ b/include/net/netlink.h
82026@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
82027 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
82028 {
82029 if (mark)
82030- skb_trim(skb, (unsigned char *) mark - skb->data);
82031+ skb_trim(skb, (const unsigned char *) mark - skb->data);
82032 }
82033
82034 /**
82035diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
82036index c9c0c53..53f24c3 100644
82037--- a/include/net/netns/conntrack.h
82038+++ b/include/net/netns/conntrack.h
82039@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
82040 struct nf_proto_net {
82041 #ifdef CONFIG_SYSCTL
82042 struct ctl_table_header *ctl_table_header;
82043- struct ctl_table *ctl_table;
82044+ ctl_table_no_const *ctl_table;
82045 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
82046 struct ctl_table_header *ctl_compat_header;
82047- struct ctl_table *ctl_compat_table;
82048+ ctl_table_no_const *ctl_compat_table;
82049 #endif
82050 #endif
82051 unsigned int users;
82052@@ -58,7 +58,7 @@ struct nf_ip_net {
82053 struct nf_icmp_net icmpv6;
82054 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
82055 struct ctl_table_header *ctl_table_header;
82056- struct ctl_table *ctl_table;
82057+ ctl_table_no_const *ctl_table;
82058 #endif
82059 };
82060
82061diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
82062index ee520cb..9a0fd88 100644
82063--- a/include/net/netns/ipv4.h
82064+++ b/include/net/netns/ipv4.h
82065@@ -72,7 +72,7 @@ struct netns_ipv4 {
82066
82067 kgid_t sysctl_ping_group_range[2];
82068
82069- atomic_t dev_addr_genid;
82070+ atomic_unchecked_t dev_addr_genid;
82071
82072 #ifdef CONFIG_IP_MROUTE
82073 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
82074@@ -82,6 +82,6 @@ struct netns_ipv4 {
82075 struct fib_rules_ops *mr_rules_ops;
82076 #endif
82077 #endif
82078- atomic_t rt_genid;
82079+ atomic_unchecked_t rt_genid;
82080 };
82081 #endif
82082diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
82083index 0fb2401..477d81c 100644
82084--- a/include/net/netns/ipv6.h
82085+++ b/include/net/netns/ipv6.h
82086@@ -71,8 +71,8 @@ struct netns_ipv6 {
82087 struct fib_rules_ops *mr6_rules_ops;
82088 #endif
82089 #endif
82090- atomic_t dev_addr_genid;
82091- atomic_t rt_genid;
82092+ atomic_unchecked_t dev_addr_genid;
82093+ atomic_unchecked_t rt_genid;
82094 };
82095
82096 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
82097diff --git a/include/net/ping.h b/include/net/ping.h
82098index 90f4841..74446a8 100644
82099--- a/include/net/ping.h
82100+++ b/include/net/ping.h
82101@@ -56,7 +56,7 @@ struct ping_iter_state {
82102 extern struct proto ping_prot;
82103 extern struct ping_table ping_table;
82104 #if IS_ENABLED(CONFIG_IPV6)
82105-extern struct pingv6_ops pingv6_ops;
82106+extern struct pingv6_ops *pingv6_ops;
82107 #endif
82108
82109 struct pingfakehdr {
82110diff --git a/include/net/protocol.h b/include/net/protocol.h
82111index fbf7676..a5e21c3 100644
82112--- a/include/net/protocol.h
82113+++ b/include/net/protocol.h
82114@@ -44,7 +44,7 @@ struct net_protocol {
82115 void (*err_handler)(struct sk_buff *skb, u32 info);
82116 unsigned int no_policy:1,
82117 netns_ok:1;
82118-};
82119+} __do_const;
82120
82121 #if IS_ENABLED(CONFIG_IPV6)
82122 struct inet6_protocol {
82123@@ -57,7 +57,7 @@ struct inet6_protocol {
82124 u8 type, u8 code, int offset,
82125 __be32 info);
82126 unsigned int flags; /* INET6_PROTO_xxx */
82127-};
82128+} __do_const;
82129
82130 #define INET6_PROTO_NOPOLICY 0x1
82131 #define INET6_PROTO_FINAL 0x2
82132diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
82133index bb13a18..e734116 100644
82134--- a/include/net/rtnetlink.h
82135+++ b/include/net/rtnetlink.h
82136@@ -79,7 +79,7 @@ struct rtnl_link_ops {
82137 const struct net_device *dev);
82138 unsigned int (*get_num_tx_queues)(void);
82139 unsigned int (*get_num_rx_queues)(void);
82140-};
82141+} __do_const;
82142
82143 int __rtnl_link_register(struct rtnl_link_ops *ops);
82144 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
82145diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
82146index 6bd44fe..96f364e 100644
82147--- a/include/net/sctp/checksum.h
82148+++ b/include/net/sctp/checksum.h
82149@@ -62,8 +62,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
82150 unsigned int offset)
82151 {
82152 struct sctphdr *sh = sctp_hdr(skb);
82153- __le32 ret, old = sh->checksum;
82154- const struct skb_checksum_ops ops = {
82155+ __le32 ret, old = sh->checksum;
82156+ static const struct skb_checksum_ops ops = {
82157 .update = sctp_csum_update,
82158 .combine = sctp_csum_combine,
82159 };
82160diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
82161index 4ef75af..5aa073a 100644
82162--- a/include/net/sctp/sm.h
82163+++ b/include/net/sctp/sm.h
82164@@ -81,7 +81,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
82165 typedef struct {
82166 sctp_state_fn_t *fn;
82167 const char *name;
82168-} sctp_sm_table_entry_t;
82169+} __do_const sctp_sm_table_entry_t;
82170
82171 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
82172 * currently in use.
82173@@ -293,7 +293,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
82174 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
82175
82176 /* Extern declarations for major data structures. */
82177-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
82178+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
82179
82180
82181 /* Get the size of a DATA chunk payload. */
82182diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
82183index 0a248b3..4dcbe5c 100644
82184--- a/include/net/sctp/structs.h
82185+++ b/include/net/sctp/structs.h
82186@@ -508,7 +508,7 @@ struct sctp_pf {
82187 struct sctp_association *asoc);
82188 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
82189 struct sctp_af *af;
82190-};
82191+} __do_const;
82192
82193
82194 /* Structure to track chunk fragments that have been acked, but peer
82195diff --git a/include/net/sock.h b/include/net/sock.h
82196index 2ef3c3e..e02013e 100644
82197--- a/include/net/sock.h
82198+++ b/include/net/sock.h
82199@@ -348,7 +348,7 @@ struct sock {
82200 unsigned int sk_napi_id;
82201 unsigned int sk_ll_usec;
82202 #endif
82203- atomic_t sk_drops;
82204+ atomic_unchecked_t sk_drops;
82205 int sk_rcvbuf;
82206
82207 struct sk_filter __rcu *sk_filter;
82208@@ -1209,7 +1209,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
82209 return ret >> PAGE_SHIFT;
82210 }
82211
82212-static inline long
82213+static inline long __intentional_overflow(-1)
82214 sk_memory_allocated(const struct sock *sk)
82215 {
82216 struct proto *prot = sk->sk_prot;
82217@@ -1813,7 +1813,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
82218 }
82219
82220 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
82221- char __user *from, char *to,
82222+ char __user *from, unsigned char *to,
82223 int copy, int offset)
82224 {
82225 if (skb->ip_summed == CHECKSUM_NONE) {
82226@@ -2075,7 +2075,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
82227 }
82228 }
82229
82230-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
82231+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
82232
82233 /**
82234 * sk_page_frag - return an appropriate page_frag
82235diff --git a/include/net/tcp.h b/include/net/tcp.h
82236index 70e55d2..c5d8d53 100644
82237--- a/include/net/tcp.h
82238+++ b/include/net/tcp.h
82239@@ -540,7 +540,7 @@ void tcp_retransmit_timer(struct sock *sk);
82240 void tcp_xmit_retransmit_queue(struct sock *);
82241 void tcp_simple_retransmit(struct sock *);
82242 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
82243-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
82244+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
82245
82246 void tcp_send_probe0(struct sock *);
82247 void tcp_send_partial(struct sock *);
82248@@ -711,8 +711,8 @@ struct tcp_skb_cb {
82249 struct inet6_skb_parm h6;
82250 #endif
82251 } header; /* For incoming frames */
82252- __u32 seq; /* Starting sequence number */
82253- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
82254+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
82255+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
82256 __u32 when; /* used to compute rtt's */
82257 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
82258
82259@@ -726,7 +726,7 @@ struct tcp_skb_cb {
82260
82261 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
82262 /* 1 byte hole */
82263- __u32 ack_seq; /* Sequence number ACK'd */
82264+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
82265 };
82266
82267 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
82268diff --git a/include/net/xfrm.h b/include/net/xfrm.h
82269index 6b82fdf..14d74d2 100644
82270--- a/include/net/xfrm.h
82271+++ b/include/net/xfrm.h
82272@@ -287,7 +287,6 @@ struct xfrm_dst;
82273 struct xfrm_policy_afinfo {
82274 unsigned short family;
82275 struct dst_ops *dst_ops;
82276- void (*garbage_collect)(struct net *net);
82277 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
82278 const xfrm_address_t *saddr,
82279 const xfrm_address_t *daddr);
82280@@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
82281 struct net_device *dev,
82282 const struct flowi *fl);
82283 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
82284-};
82285+} __do_const;
82286
82287 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
82288 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
82289@@ -344,7 +343,7 @@ struct xfrm_state_afinfo {
82290 int (*transport_finish)(struct sk_buff *skb,
82291 int async);
82292 void (*local_error)(struct sk_buff *skb, u32 mtu);
82293-};
82294+} __do_const;
82295
82296 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
82297 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
82298@@ -429,7 +428,7 @@ struct xfrm_mode {
82299 struct module *owner;
82300 unsigned int encap;
82301 int flags;
82302-};
82303+} __do_const;
82304
82305 /* Flags for xfrm_mode. */
82306 enum {
82307@@ -526,7 +525,7 @@ struct xfrm_policy {
82308 struct timer_list timer;
82309
82310 struct flow_cache_object flo;
82311- atomic_t genid;
82312+ atomic_unchecked_t genid;
82313 u32 priority;
82314 u32 index;
82315 struct xfrm_mark mark;
82316@@ -1166,6 +1165,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
82317 }
82318
82319 void xfrm_garbage_collect(struct net *net);
82320+void xfrm_garbage_collect_deferred(struct net *net);
82321
82322 #else
82323
82324@@ -1204,6 +1204,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
82325 static inline void xfrm_garbage_collect(struct net *net)
82326 {
82327 }
82328+static inline void xfrm_garbage_collect_deferred(struct net *net)
82329+{
82330+}
82331 #endif
82332
82333 static __inline__
82334diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
82335index 1017e0b..227aa4d 100644
82336--- a/include/rdma/iw_cm.h
82337+++ b/include/rdma/iw_cm.h
82338@@ -122,7 +122,7 @@ struct iw_cm_verbs {
82339 int backlog);
82340
82341 int (*destroy_listen)(struct iw_cm_id *cm_id);
82342-};
82343+} __no_const;
82344
82345 /**
82346 * iw_create_cm_id - Create an IW CM identifier.
82347diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
82348index 52beadf..598734c 100644
82349--- a/include/scsi/libfc.h
82350+++ b/include/scsi/libfc.h
82351@@ -771,6 +771,7 @@ struct libfc_function_template {
82352 */
82353 void (*disc_stop_final) (struct fc_lport *);
82354 };
82355+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
82356
82357 /**
82358 * struct fc_disc - Discovery context
82359@@ -875,7 +876,7 @@ struct fc_lport {
82360 struct fc_vport *vport;
82361
82362 /* Operational Information */
82363- struct libfc_function_template tt;
82364+ libfc_function_template_no_const tt;
82365 u8 link_up;
82366 u8 qfull;
82367 enum fc_lport_state state;
82368diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
82369index d65fbec..f80fef2 100644
82370--- a/include/scsi/scsi_device.h
82371+++ b/include/scsi/scsi_device.h
82372@@ -180,9 +180,9 @@ struct scsi_device {
82373 unsigned int max_device_blocked; /* what device_blocked counts down from */
82374 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
82375
82376- atomic_t iorequest_cnt;
82377- atomic_t iodone_cnt;
82378- atomic_t ioerr_cnt;
82379+ atomic_unchecked_t iorequest_cnt;
82380+ atomic_unchecked_t iodone_cnt;
82381+ atomic_unchecked_t ioerr_cnt;
82382
82383 struct device sdev_gendev,
82384 sdev_dev;
82385diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
82386index b797e8f..8e2c3aa 100644
82387--- a/include/scsi/scsi_transport_fc.h
82388+++ b/include/scsi/scsi_transport_fc.h
82389@@ -751,7 +751,8 @@ struct fc_function_template {
82390 unsigned long show_host_system_hostname:1;
82391
82392 unsigned long disable_target_scan:1;
82393-};
82394+} __do_const;
82395+typedef struct fc_function_template __no_const fc_function_template_no_const;
82396
82397
82398 /**
82399diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
82400index ae6c3b8..fd748ac 100644
82401--- a/include/sound/compress_driver.h
82402+++ b/include/sound/compress_driver.h
82403@@ -128,7 +128,7 @@ struct snd_compr_ops {
82404 struct snd_compr_caps *caps);
82405 int (*get_codec_caps) (struct snd_compr_stream *stream,
82406 struct snd_compr_codec_caps *codec);
82407-};
82408+} __no_const;
82409
82410 /**
82411 * struct snd_compr: Compressed device
82412diff --git a/include/sound/soc.h b/include/sound/soc.h
82413index 1f741cb..8cefc08 100644
82414--- a/include/sound/soc.h
82415+++ b/include/sound/soc.h
82416@@ -763,7 +763,7 @@ struct snd_soc_codec_driver {
82417 /* probe ordering - for components with runtime dependencies */
82418 int probe_order;
82419 int remove_order;
82420-};
82421+} __do_const;
82422
82423 /* SoC platform interface */
82424 struct snd_soc_platform_driver {
82425@@ -809,7 +809,7 @@ struct snd_soc_platform_driver {
82426 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
82427 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
82428 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
82429-};
82430+} __do_const;
82431
82432 struct snd_soc_platform {
82433 const char *name;
82434diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
82435index 321301c..2ae5cb0 100644
82436--- a/include/target/target_core_base.h
82437+++ b/include/target/target_core_base.h
82438@@ -687,7 +687,7 @@ struct se_device {
82439 atomic_long_t write_bytes;
82440 /* Active commands on this virtual SE device */
82441 atomic_t simple_cmds;
82442- atomic_t dev_ordered_id;
82443+ atomic_unchecked_t dev_ordered_id;
82444 atomic_t dev_ordered_sync;
82445 atomic_t dev_qf_count;
82446 int export_count;
82447diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
82448new file mode 100644
82449index 0000000..fb634b7
82450--- /dev/null
82451+++ b/include/trace/events/fs.h
82452@@ -0,0 +1,53 @@
82453+#undef TRACE_SYSTEM
82454+#define TRACE_SYSTEM fs
82455+
82456+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
82457+#define _TRACE_FS_H
82458+
82459+#include <linux/fs.h>
82460+#include <linux/tracepoint.h>
82461+
82462+TRACE_EVENT(do_sys_open,
82463+
82464+ TP_PROTO(const char *filename, int flags, int mode),
82465+
82466+ TP_ARGS(filename, flags, mode),
82467+
82468+ TP_STRUCT__entry(
82469+ __string( filename, filename )
82470+ __field( int, flags )
82471+ __field( int, mode )
82472+ ),
82473+
82474+ TP_fast_assign(
82475+ __assign_str(filename, filename);
82476+ __entry->flags = flags;
82477+ __entry->mode = mode;
82478+ ),
82479+
82480+ TP_printk("\"%s\" %x %o",
82481+ __get_str(filename), __entry->flags, __entry->mode)
82482+);
82483+
82484+TRACE_EVENT(open_exec,
82485+
82486+ TP_PROTO(const char *filename),
82487+
82488+ TP_ARGS(filename),
82489+
82490+ TP_STRUCT__entry(
82491+ __string( filename, filename )
82492+ ),
82493+
82494+ TP_fast_assign(
82495+ __assign_str(filename, filename);
82496+ ),
82497+
82498+ TP_printk("\"%s\"",
82499+ __get_str(filename))
82500+);
82501+
82502+#endif /* _TRACE_FS_H */
82503+
82504+/* This part must be outside protection */
82505+#include <trace/define_trace.h>
82506diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
82507index 1c09820..7f5ec79 100644
82508--- a/include/trace/events/irq.h
82509+++ b/include/trace/events/irq.h
82510@@ -36,7 +36,7 @@ struct softirq_action;
82511 */
82512 TRACE_EVENT(irq_handler_entry,
82513
82514- TP_PROTO(int irq, struct irqaction *action),
82515+ TP_PROTO(int irq, const struct irqaction *action),
82516
82517 TP_ARGS(irq, action),
82518
82519@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
82520 */
82521 TRACE_EVENT(irq_handler_exit,
82522
82523- TP_PROTO(int irq, struct irqaction *action, int ret),
82524+ TP_PROTO(int irq, const struct irqaction *action, int ret),
82525
82526 TP_ARGS(irq, action, ret),
82527
82528diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
82529index 7caf44c..23c6f27 100644
82530--- a/include/uapi/linux/a.out.h
82531+++ b/include/uapi/linux/a.out.h
82532@@ -39,6 +39,14 @@ enum machine_type {
82533 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
82534 };
82535
82536+/* Constants for the N_FLAGS field */
82537+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
82538+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
82539+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
82540+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
82541+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
82542+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
82543+
82544 #if !defined (N_MAGIC)
82545 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
82546 #endif
82547diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
82548index d876736..ccce5c0 100644
82549--- a/include/uapi/linux/byteorder/little_endian.h
82550+++ b/include/uapi/linux/byteorder/little_endian.h
82551@@ -42,51 +42,51 @@
82552
82553 static inline __le64 __cpu_to_le64p(const __u64 *p)
82554 {
82555- return (__force __le64)*p;
82556+ return (__force const __le64)*p;
82557 }
82558-static inline __u64 __le64_to_cpup(const __le64 *p)
82559+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
82560 {
82561- return (__force __u64)*p;
82562+ return (__force const __u64)*p;
82563 }
82564 static inline __le32 __cpu_to_le32p(const __u32 *p)
82565 {
82566- return (__force __le32)*p;
82567+ return (__force const __le32)*p;
82568 }
82569 static inline __u32 __le32_to_cpup(const __le32 *p)
82570 {
82571- return (__force __u32)*p;
82572+ return (__force const __u32)*p;
82573 }
82574 static inline __le16 __cpu_to_le16p(const __u16 *p)
82575 {
82576- return (__force __le16)*p;
82577+ return (__force const __le16)*p;
82578 }
82579 static inline __u16 __le16_to_cpup(const __le16 *p)
82580 {
82581- return (__force __u16)*p;
82582+ return (__force const __u16)*p;
82583 }
82584 static inline __be64 __cpu_to_be64p(const __u64 *p)
82585 {
82586- return (__force __be64)__swab64p(p);
82587+ return (__force const __be64)__swab64p(p);
82588 }
82589 static inline __u64 __be64_to_cpup(const __be64 *p)
82590 {
82591- return __swab64p((__u64 *)p);
82592+ return __swab64p((const __u64 *)p);
82593 }
82594 static inline __be32 __cpu_to_be32p(const __u32 *p)
82595 {
82596- return (__force __be32)__swab32p(p);
82597+ return (__force const __be32)__swab32p(p);
82598 }
82599-static inline __u32 __be32_to_cpup(const __be32 *p)
82600+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
82601 {
82602- return __swab32p((__u32 *)p);
82603+ return __swab32p((const __u32 *)p);
82604 }
82605 static inline __be16 __cpu_to_be16p(const __u16 *p)
82606 {
82607- return (__force __be16)__swab16p(p);
82608+ return (__force const __be16)__swab16p(p);
82609 }
82610 static inline __u16 __be16_to_cpup(const __be16 *p)
82611 {
82612- return __swab16p((__u16 *)p);
82613+ return __swab16p((const __u16 *)p);
82614 }
82615 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
82616 #define __le64_to_cpus(x) do { (void)(x); } while (0)
82617diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
82618index ef6103b..d4e65dd 100644
82619--- a/include/uapi/linux/elf.h
82620+++ b/include/uapi/linux/elf.h
82621@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
82622 #define PT_GNU_EH_FRAME 0x6474e550
82623
82624 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
82625+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
82626+
82627+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
82628+
82629+/* Constants for the e_flags field */
82630+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
82631+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
82632+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
82633+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
82634+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
82635+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
82636
82637 /*
82638 * Extended Numbering
82639@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
82640 #define DT_DEBUG 21
82641 #define DT_TEXTREL 22
82642 #define DT_JMPREL 23
82643+#define DT_FLAGS 30
82644+ #define DF_TEXTREL 0x00000004
82645 #define DT_ENCODING 32
82646 #define OLD_DT_LOOS 0x60000000
82647 #define DT_LOOS 0x6000000d
82648@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
82649 #define PF_W 0x2
82650 #define PF_X 0x1
82651
82652+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
82653+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
82654+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
82655+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
82656+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
82657+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
82658+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
82659+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
82660+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
82661+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
82662+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
82663+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
82664+
82665 typedef struct elf32_phdr{
82666 Elf32_Word p_type;
82667 Elf32_Off p_offset;
82668@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
82669 #define EI_OSABI 7
82670 #define EI_PAD 8
82671
82672+#define EI_PAX 14
82673+
82674 #define ELFMAG0 0x7f /* EI_MAG */
82675 #define ELFMAG1 'E'
82676 #define ELFMAG2 'L'
82677diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
82678index aa169c4..6a2771d 100644
82679--- a/include/uapi/linux/personality.h
82680+++ b/include/uapi/linux/personality.h
82681@@ -30,6 +30,7 @@ enum {
82682 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
82683 ADDR_NO_RANDOMIZE | \
82684 ADDR_COMPAT_LAYOUT | \
82685+ ADDR_LIMIT_3GB | \
82686 MMAP_PAGE_ZERO)
82687
82688 /*
82689diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
82690index 7530e74..e714828 100644
82691--- a/include/uapi/linux/screen_info.h
82692+++ b/include/uapi/linux/screen_info.h
82693@@ -43,7 +43,8 @@ struct screen_info {
82694 __u16 pages; /* 0x32 */
82695 __u16 vesa_attributes; /* 0x34 */
82696 __u32 capabilities; /* 0x36 */
82697- __u8 _reserved[6]; /* 0x3a */
82698+ __u16 vesapm_size; /* 0x3a */
82699+ __u8 _reserved[4]; /* 0x3c */
82700 } __attribute__((packed));
82701
82702 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
82703diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
82704index 0e011eb..82681b1 100644
82705--- a/include/uapi/linux/swab.h
82706+++ b/include/uapi/linux/swab.h
82707@@ -43,7 +43,7 @@
82708 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
82709 */
82710
82711-static inline __attribute_const__ __u16 __fswab16(__u16 val)
82712+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
82713 {
82714 #ifdef __HAVE_BUILTIN_BSWAP16__
82715 return __builtin_bswap16(val);
82716@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
82717 #endif
82718 }
82719
82720-static inline __attribute_const__ __u32 __fswab32(__u32 val)
82721+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
82722 {
82723 #ifdef __HAVE_BUILTIN_BSWAP32__
82724 return __builtin_bswap32(val);
82725@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
82726 #endif
82727 }
82728
82729-static inline __attribute_const__ __u64 __fswab64(__u64 val)
82730+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
82731 {
82732 #ifdef __HAVE_BUILTIN_BSWAP64__
82733 return __builtin_bswap64(val);
82734diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
82735index 6d67213..552fdd9 100644
82736--- a/include/uapi/linux/sysctl.h
82737+++ b/include/uapi/linux/sysctl.h
82738@@ -155,8 +155,6 @@ enum
82739 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
82740 };
82741
82742-
82743-
82744 /* CTL_VM names: */
82745 enum
82746 {
82747diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
82748index 437f1b0..0eeb38d 100644
82749--- a/include/uapi/linux/videodev2.h
82750+++ b/include/uapi/linux/videodev2.h
82751@@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
82752 union {
82753 __s32 value;
82754 __s64 value64;
82755- char *string;
82756+ char __user *string;
82757 };
82758 } __attribute__ ((packed));
82759
82760diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
82761index e4629b9..6958086 100644
82762--- a/include/uapi/linux/xattr.h
82763+++ b/include/uapi/linux/xattr.h
82764@@ -63,5 +63,9 @@
82765 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
82766 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
82767
82768+/* User namespace */
82769+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
82770+#define XATTR_PAX_FLAGS_SUFFIX "flags"
82771+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
82772
82773 #endif /* _UAPI_LINUX_XATTR_H */
82774diff --git a/include/video/udlfb.h b/include/video/udlfb.h
82775index f9466fa..f4e2b81 100644
82776--- a/include/video/udlfb.h
82777+++ b/include/video/udlfb.h
82778@@ -53,10 +53,10 @@ struct dlfb_data {
82779 u32 pseudo_palette[256];
82780 int blank_mode; /*one of FB_BLANK_ */
82781 /* blit-only rendering path metrics, exposed through sysfs */
82782- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
82783- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
82784- atomic_t bytes_sent; /* to usb, after compression including overhead */
82785- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
82786+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
82787+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
82788+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
82789+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
82790 };
82791
82792 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
82793diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
82794index 30f5362..8ed8ac9 100644
82795--- a/include/video/uvesafb.h
82796+++ b/include/video/uvesafb.h
82797@@ -122,6 +122,7 @@ struct uvesafb_par {
82798 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
82799 u8 pmi_setpal; /* PMI for palette changes */
82800 u16 *pmi_base; /* protected mode interface location */
82801+ u8 *pmi_code; /* protected mode code location */
82802 void *pmi_start;
82803 void *pmi_pal;
82804 u8 *vbe_state_orig; /*
82805diff --git a/init/Kconfig b/init/Kconfig
82806index 4e5d96a..93cd8a1 100644
82807--- a/init/Kconfig
82808+++ b/init/Kconfig
82809@@ -1079,6 +1079,7 @@ endif # CGROUPS
82810
82811 config CHECKPOINT_RESTORE
82812 bool "Checkpoint/restore support" if EXPERT
82813+ depends on !GRKERNSEC
82814 default n
82815 help
82816 Enables additional kernel features in a sake of checkpoint/restore.
82817@@ -1550,7 +1551,7 @@ config SLUB_DEBUG
82818
82819 config COMPAT_BRK
82820 bool "Disable heap randomization"
82821- default y
82822+ default n
82823 help
82824 Randomizing heap placement makes heap exploits harder, but it
82825 also breaks ancient binaries (including anything libc5 based).
82826@@ -1838,7 +1839,7 @@ config INIT_ALL_POSSIBLE
82827 config STOP_MACHINE
82828 bool
82829 default y
82830- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
82831+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
82832 help
82833 Need stop_machine() primitive.
82834
82835diff --git a/init/Makefile b/init/Makefile
82836index 7bc47ee..6da2dc7 100644
82837--- a/init/Makefile
82838+++ b/init/Makefile
82839@@ -2,6 +2,9 @@
82840 # Makefile for the linux kernel.
82841 #
82842
82843+ccflags-y := $(GCC_PLUGINS_CFLAGS)
82844+asflags-y := $(GCC_PLUGINS_AFLAGS)
82845+
82846 obj-y := main.o version.o mounts.o
82847 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
82848 obj-y += noinitramfs.o
82849diff --git a/init/do_mounts.c b/init/do_mounts.c
82850index 8e5addc..c96ea61 100644
82851--- a/init/do_mounts.c
82852+++ b/init/do_mounts.c
82853@@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
82854 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
82855 {
82856 struct super_block *s;
82857- int err = sys_mount(name, "/root", fs, flags, data);
82858+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
82859 if (err)
82860 return err;
82861
82862- sys_chdir("/root");
82863+ sys_chdir((const char __force_user *)"/root");
82864 s = current->fs->pwd.dentry->d_sb;
82865 ROOT_DEV = s->s_dev;
82866 printk(KERN_INFO
82867@@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
82868 va_start(args, fmt);
82869 vsprintf(buf, fmt, args);
82870 va_end(args);
82871- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
82872+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
82873 if (fd >= 0) {
82874 sys_ioctl(fd, FDEJECT, 0);
82875 sys_close(fd);
82876 }
82877 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
82878- fd = sys_open("/dev/console", O_RDWR, 0);
82879+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
82880 if (fd >= 0) {
82881 sys_ioctl(fd, TCGETS, (long)&termios);
82882 termios.c_lflag &= ~ICANON;
82883 sys_ioctl(fd, TCSETSF, (long)&termios);
82884- sys_read(fd, &c, 1);
82885+ sys_read(fd, (char __user *)&c, 1);
82886 termios.c_lflag |= ICANON;
82887 sys_ioctl(fd, TCSETSF, (long)&termios);
82888 sys_close(fd);
82889@@ -589,8 +589,8 @@ void __init prepare_namespace(void)
82890 mount_root();
82891 out:
82892 devtmpfs_mount("dev");
82893- sys_mount(".", "/", NULL, MS_MOVE, NULL);
82894- sys_chroot(".");
82895+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
82896+ sys_chroot((const char __force_user *)".");
82897 }
82898
82899 static bool is_tmpfs;
82900diff --git a/init/do_mounts.h b/init/do_mounts.h
82901index f5b978a..69dbfe8 100644
82902--- a/init/do_mounts.h
82903+++ b/init/do_mounts.h
82904@@ -15,15 +15,15 @@ extern int root_mountflags;
82905
82906 static inline int create_dev(char *name, dev_t dev)
82907 {
82908- sys_unlink(name);
82909- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
82910+ sys_unlink((char __force_user *)name);
82911+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
82912 }
82913
82914 #if BITS_PER_LONG == 32
82915 static inline u32 bstat(char *name)
82916 {
82917 struct stat64 stat;
82918- if (sys_stat64(name, &stat) != 0)
82919+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
82920 return 0;
82921 if (!S_ISBLK(stat.st_mode))
82922 return 0;
82923@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
82924 static inline u32 bstat(char *name)
82925 {
82926 struct stat stat;
82927- if (sys_newstat(name, &stat) != 0)
82928+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
82929 return 0;
82930 if (!S_ISBLK(stat.st_mode))
82931 return 0;
82932diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
82933index 3e0878e..8a9d7a0 100644
82934--- a/init/do_mounts_initrd.c
82935+++ b/init/do_mounts_initrd.c
82936@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
82937 {
82938 sys_unshare(CLONE_FS | CLONE_FILES);
82939 /* stdin/stdout/stderr for /linuxrc */
82940- sys_open("/dev/console", O_RDWR, 0);
82941+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
82942 sys_dup(0);
82943 sys_dup(0);
82944 /* move initrd over / and chdir/chroot in initrd root */
82945- sys_chdir("/root");
82946- sys_mount(".", "/", NULL, MS_MOVE, NULL);
82947- sys_chroot(".");
82948+ sys_chdir((const char __force_user *)"/root");
82949+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
82950+ sys_chroot((const char __force_user *)".");
82951 sys_setsid();
82952 return 0;
82953 }
82954@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
82955 create_dev("/dev/root.old", Root_RAM0);
82956 /* mount initrd on rootfs' /root */
82957 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
82958- sys_mkdir("/old", 0700);
82959- sys_chdir("/old");
82960+ sys_mkdir((const char __force_user *)"/old", 0700);
82961+ sys_chdir((const char __force_user *)"/old");
82962
82963 /* try loading default modules from initrd */
82964 load_default_modules();
82965@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
82966 current->flags &= ~PF_FREEZER_SKIP;
82967
82968 /* move initrd to rootfs' /old */
82969- sys_mount("..", ".", NULL, MS_MOVE, NULL);
82970+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
82971 /* switch root and cwd back to / of rootfs */
82972- sys_chroot("..");
82973+ sys_chroot((const char __force_user *)"..");
82974
82975 if (new_decode_dev(real_root_dev) == Root_RAM0) {
82976- sys_chdir("/old");
82977+ sys_chdir((const char __force_user *)"/old");
82978 return;
82979 }
82980
82981- sys_chdir("/");
82982+ sys_chdir((const char __force_user *)"/");
82983 ROOT_DEV = new_decode_dev(real_root_dev);
82984 mount_root();
82985
82986 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
82987- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
82988+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
82989 if (!error)
82990 printk("okay\n");
82991 else {
82992- int fd = sys_open("/dev/root.old", O_RDWR, 0);
82993+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
82994 if (error == -ENOENT)
82995 printk("/initrd does not exist. Ignored.\n");
82996 else
82997 printk("failed\n");
82998 printk(KERN_NOTICE "Unmounting old root\n");
82999- sys_umount("/old", MNT_DETACH);
83000+ sys_umount((char __force_user *)"/old", MNT_DETACH);
83001 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
83002 if (fd < 0) {
83003 error = fd;
83004@@ -127,11 +127,11 @@ int __init initrd_load(void)
83005 * mounted in the normal path.
83006 */
83007 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
83008- sys_unlink("/initrd.image");
83009+ sys_unlink((const char __force_user *)"/initrd.image");
83010 handle_initrd();
83011 return 1;
83012 }
83013 }
83014- sys_unlink("/initrd.image");
83015+ sys_unlink((const char __force_user *)"/initrd.image");
83016 return 0;
83017 }
83018diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
83019index 8cb6db5..d729f50 100644
83020--- a/init/do_mounts_md.c
83021+++ b/init/do_mounts_md.c
83022@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
83023 partitioned ? "_d" : "", minor,
83024 md_setup_args[ent].device_names);
83025
83026- fd = sys_open(name, 0, 0);
83027+ fd = sys_open((char __force_user *)name, 0, 0);
83028 if (fd < 0) {
83029 printk(KERN_ERR "md: open failed - cannot start "
83030 "array %s\n", name);
83031@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
83032 * array without it
83033 */
83034 sys_close(fd);
83035- fd = sys_open(name, 0, 0);
83036+ fd = sys_open((char __force_user *)name, 0, 0);
83037 sys_ioctl(fd, BLKRRPART, 0);
83038 }
83039 sys_close(fd);
83040@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
83041
83042 wait_for_device_probe();
83043
83044- fd = sys_open("/dev/md0", 0, 0);
83045+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
83046 if (fd >= 0) {
83047 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
83048 sys_close(fd);
83049diff --git a/init/init_task.c b/init/init_task.c
83050index ba0a7f36..2bcf1d5 100644
83051--- a/init/init_task.c
83052+++ b/init/init_task.c
83053@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
83054 * Initial thread structure. Alignment of this is handled by a special
83055 * linker map entry.
83056 */
83057+#ifdef CONFIG_X86
83058+union thread_union init_thread_union __init_task_data;
83059+#else
83060 union thread_union init_thread_union __init_task_data =
83061 { INIT_THREAD_INFO(init_task) };
83062+#endif
83063diff --git a/init/initramfs.c b/init/initramfs.c
83064index a67ef9d..2d17ed9 100644
83065--- a/init/initramfs.c
83066+++ b/init/initramfs.c
83067@@ -84,7 +84,7 @@ static void __init free_hash(void)
83068 }
83069 }
83070
83071-static long __init do_utime(char *filename, time_t mtime)
83072+static long __init do_utime(char __force_user *filename, time_t mtime)
83073 {
83074 struct timespec t[2];
83075
83076@@ -119,7 +119,7 @@ static void __init dir_utime(void)
83077 struct dir_entry *de, *tmp;
83078 list_for_each_entry_safe(de, tmp, &dir_list, list) {
83079 list_del(&de->list);
83080- do_utime(de->name, de->mtime);
83081+ do_utime((char __force_user *)de->name, de->mtime);
83082 kfree(de->name);
83083 kfree(de);
83084 }
83085@@ -281,7 +281,7 @@ static int __init maybe_link(void)
83086 if (nlink >= 2) {
83087 char *old = find_link(major, minor, ino, mode, collected);
83088 if (old)
83089- return (sys_link(old, collected) < 0) ? -1 : 1;
83090+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
83091 }
83092 return 0;
83093 }
83094@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
83095 {
83096 struct stat st;
83097
83098- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
83099+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
83100 if (S_ISDIR(st.st_mode))
83101- sys_rmdir(path);
83102+ sys_rmdir((char __force_user *)path);
83103 else
83104- sys_unlink(path);
83105+ sys_unlink((char __force_user *)path);
83106 }
83107 }
83108
83109@@ -315,7 +315,7 @@ static int __init do_name(void)
83110 int openflags = O_WRONLY|O_CREAT;
83111 if (ml != 1)
83112 openflags |= O_TRUNC;
83113- wfd = sys_open(collected, openflags, mode);
83114+ wfd = sys_open((char __force_user *)collected, openflags, mode);
83115
83116 if (wfd >= 0) {
83117 sys_fchown(wfd, uid, gid);
83118@@ -327,17 +327,17 @@ static int __init do_name(void)
83119 }
83120 }
83121 } else if (S_ISDIR(mode)) {
83122- sys_mkdir(collected, mode);
83123- sys_chown(collected, uid, gid);
83124- sys_chmod(collected, mode);
83125+ sys_mkdir((char __force_user *)collected, mode);
83126+ sys_chown((char __force_user *)collected, uid, gid);
83127+ sys_chmod((char __force_user *)collected, mode);
83128 dir_add(collected, mtime);
83129 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
83130 S_ISFIFO(mode) || S_ISSOCK(mode)) {
83131 if (maybe_link() == 0) {
83132- sys_mknod(collected, mode, rdev);
83133- sys_chown(collected, uid, gid);
83134- sys_chmod(collected, mode);
83135- do_utime(collected, mtime);
83136+ sys_mknod((char __force_user *)collected, mode, rdev);
83137+ sys_chown((char __force_user *)collected, uid, gid);
83138+ sys_chmod((char __force_user *)collected, mode);
83139+ do_utime((char __force_user *)collected, mtime);
83140 }
83141 }
83142 return 0;
83143@@ -346,15 +346,15 @@ static int __init do_name(void)
83144 static int __init do_copy(void)
83145 {
83146 if (count >= body_len) {
83147- sys_write(wfd, victim, body_len);
83148+ sys_write(wfd, (char __force_user *)victim, body_len);
83149 sys_close(wfd);
83150- do_utime(vcollected, mtime);
83151+ do_utime((char __force_user *)vcollected, mtime);
83152 kfree(vcollected);
83153 eat(body_len);
83154 state = SkipIt;
83155 return 0;
83156 } else {
83157- sys_write(wfd, victim, count);
83158+ sys_write(wfd, (char __force_user *)victim, count);
83159 body_len -= count;
83160 eat(count);
83161 return 1;
83162@@ -365,9 +365,9 @@ static int __init do_symlink(void)
83163 {
83164 collected[N_ALIGN(name_len) + body_len] = '\0';
83165 clean_path(collected, 0);
83166- sys_symlink(collected + N_ALIGN(name_len), collected);
83167- sys_lchown(collected, uid, gid);
83168- do_utime(collected, mtime);
83169+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
83170+ sys_lchown((char __force_user *)collected, uid, gid);
83171+ do_utime((char __force_user *)collected, mtime);
83172 state = SkipIt;
83173 next_state = Reset;
83174 return 0;
83175@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
83176 {
83177 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
83178 if (err)
83179- panic(err); /* Failed to decompress INTERNAL initramfs */
83180+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
83181 if (initrd_start) {
83182 #ifdef CONFIG_BLK_DEV_RAM
83183 int fd;
83184diff --git a/init/main.c b/init/main.c
83185index febc511..f0851763 100644
83186--- a/init/main.c
83187+++ b/init/main.c
83188@@ -103,6 +103,8 @@ static inline void mark_rodata_ro(void) { }
83189 extern void tc_init(void);
83190 #endif
83191
83192+extern void grsecurity_init(void);
83193+
83194 /*
83195 * Debug helper: via this flag we know that we are in 'early bootup code'
83196 * where only the boot processor is running with IRQ disabled. This means
83197@@ -164,6 +166,75 @@ static int __init set_reset_devices(char *str)
83198
83199 __setup("reset_devices", set_reset_devices);
83200
83201+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
83202+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
83203+static int __init setup_grsec_proc_gid(char *str)
83204+{
83205+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
83206+ return 1;
83207+}
83208+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
83209+#endif
83210+
83211+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
83212+unsigned long pax_user_shadow_base __read_only;
83213+EXPORT_SYMBOL(pax_user_shadow_base);
83214+extern char pax_enter_kernel_user[];
83215+extern char pax_exit_kernel_user[];
83216+#endif
83217+
83218+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
83219+static int __init setup_pax_nouderef(char *str)
83220+{
83221+#ifdef CONFIG_X86_32
83222+ unsigned int cpu;
83223+ struct desc_struct *gdt;
83224+
83225+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
83226+ gdt = get_cpu_gdt_table(cpu);
83227+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
83228+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
83229+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
83230+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
83231+ }
83232+ loadsegment(ds, __KERNEL_DS);
83233+ loadsegment(es, __KERNEL_DS);
83234+ loadsegment(ss, __KERNEL_DS);
83235+#else
83236+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
83237+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
83238+ clone_pgd_mask = ~(pgdval_t)0UL;
83239+ pax_user_shadow_base = 0UL;
83240+ setup_clear_cpu_cap(X86_FEATURE_PCID);
83241+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
83242+#endif
83243+
83244+ return 0;
83245+}
83246+early_param("pax_nouderef", setup_pax_nouderef);
83247+
83248+#ifdef CONFIG_X86_64
83249+static int __init setup_pax_weakuderef(char *str)
83250+{
83251+ if (clone_pgd_mask != ~(pgdval_t)0UL)
83252+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
83253+ return 1;
83254+}
83255+__setup("pax_weakuderef", setup_pax_weakuderef);
83256+#endif
83257+#endif
83258+
83259+#ifdef CONFIG_PAX_SOFTMODE
83260+int pax_softmode;
83261+
83262+static int __init setup_pax_softmode(char *str)
83263+{
83264+ get_option(&str, &pax_softmode);
83265+ return 1;
83266+}
83267+__setup("pax_softmode=", setup_pax_softmode);
83268+#endif
83269+
83270 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
83271 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
83272 static const char *panic_later, *panic_param;
83273@@ -691,25 +762,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
83274 {
83275 int count = preempt_count();
83276 int ret;
83277- char msgbuf[64];
83278+ const char *msg1 = "", *msg2 = "";
83279
83280 if (initcall_debug)
83281 ret = do_one_initcall_debug(fn);
83282 else
83283 ret = fn();
83284
83285- msgbuf[0] = 0;
83286-
83287 if (preempt_count() != count) {
83288- sprintf(msgbuf, "preemption imbalance ");
83289+ msg1 = " preemption imbalance";
83290 preempt_count_set(count);
83291 }
83292 if (irqs_disabled()) {
83293- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
83294+ msg2 = " disabled interrupts";
83295 local_irq_enable();
83296 }
83297- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
83298+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
83299
83300+ add_latent_entropy();
83301 return ret;
83302 }
83303
83304@@ -816,8 +886,8 @@ static int run_init_process(const char *init_filename)
83305 {
83306 argv_init[0] = init_filename;
83307 return do_execve(init_filename,
83308- (const char __user *const __user *)argv_init,
83309- (const char __user *const __user *)envp_init);
83310+ (const char __user *const __force_user *)argv_init,
83311+ (const char __user *const __force_user *)envp_init);
83312 }
83313
83314 static int try_to_run_init_process(const char *init_filename)
83315@@ -834,6 +904,10 @@ static int try_to_run_init_process(const char *init_filename)
83316 return ret;
83317 }
83318
83319+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
83320+extern int gr_init_ran;
83321+#endif
83322+
83323 static noinline void __init kernel_init_freeable(void);
83324
83325 static int __ref kernel_init(void *unused)
83326@@ -858,6 +932,11 @@ static int __ref kernel_init(void *unused)
83327 ramdisk_execute_command, ret);
83328 }
83329
83330+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
83331+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
83332+ gr_init_ran = 1;
83333+#endif
83334+
83335 /*
83336 * We try each of these until one succeeds.
83337 *
83338@@ -913,7 +992,7 @@ static noinline void __init kernel_init_freeable(void)
83339 do_basic_setup();
83340
83341 /* Open the /dev/console on the rootfs, this should never fail */
83342- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
83343+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
83344 pr_err("Warning: unable to open an initial console.\n");
83345
83346 (void) sys_dup(0);
83347@@ -926,11 +1005,13 @@ static noinline void __init kernel_init_freeable(void)
83348 if (!ramdisk_execute_command)
83349 ramdisk_execute_command = "/init";
83350
83351- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
83352+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
83353 ramdisk_execute_command = NULL;
83354 prepare_namespace();
83355 }
83356
83357+ grsecurity_init();
83358+
83359 /*
83360 * Ok, we have completed the initial bootup, and
83361 * we're essentially up and running. Get rid of the
83362diff --git a/ipc/compat.c b/ipc/compat.c
83363index 892f658..e7c6320 100644
83364--- a/ipc/compat.c
83365+++ b/ipc/compat.c
83366@@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
83367 COMPAT_SHMLBA);
83368 if (err < 0)
83369 return err;
83370- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
83371+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
83372 }
83373 case SHMDT:
83374 return sys_shmdt(compat_ptr(ptr));
83375diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
83376index b0e99de..09f385c 100644
83377--- a/ipc/ipc_sysctl.c
83378+++ b/ipc/ipc_sysctl.c
83379@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
83380 static int proc_ipc_dointvec(ctl_table *table, int write,
83381 void __user *buffer, size_t *lenp, loff_t *ppos)
83382 {
83383- struct ctl_table ipc_table;
83384+ ctl_table_no_const ipc_table;
83385
83386 memcpy(&ipc_table, table, sizeof(ipc_table));
83387 ipc_table.data = get_ipc(table);
83388@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
83389 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
83390 void __user *buffer, size_t *lenp, loff_t *ppos)
83391 {
83392- struct ctl_table ipc_table;
83393+ ctl_table_no_const ipc_table;
83394
83395 memcpy(&ipc_table, table, sizeof(ipc_table));
83396 ipc_table.data = get_ipc(table);
83397@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
83398 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
83399 void __user *buffer, size_t *lenp, loff_t *ppos)
83400 {
83401- struct ctl_table ipc_table;
83402+ ctl_table_no_const ipc_table;
83403 size_t lenp_bef = *lenp;
83404 int rc;
83405
83406@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
83407 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
83408 void __user *buffer, size_t *lenp, loff_t *ppos)
83409 {
83410- struct ctl_table ipc_table;
83411+ ctl_table_no_const ipc_table;
83412 memcpy(&ipc_table, table, sizeof(ipc_table));
83413 ipc_table.data = get_ipc(table);
83414
83415@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
83416 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
83417 void __user *buffer, size_t *lenp, loff_t *ppos)
83418 {
83419- struct ctl_table ipc_table;
83420+ ctl_table_no_const ipc_table;
83421 size_t lenp_bef = *lenp;
83422 int oldval;
83423 int rc;
83424diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
83425index 383d638..943fdbb 100644
83426--- a/ipc/mq_sysctl.c
83427+++ b/ipc/mq_sysctl.c
83428@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
83429 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
83430 void __user *buffer, size_t *lenp, loff_t *ppos)
83431 {
83432- struct ctl_table mq_table;
83433+ ctl_table_no_const mq_table;
83434 memcpy(&mq_table, table, sizeof(mq_table));
83435 mq_table.data = get_mq(table);
83436
83437diff --git a/ipc/mqueue.c b/ipc/mqueue.c
83438index 95827ce..09e6d38 100644
83439--- a/ipc/mqueue.c
83440+++ b/ipc/mqueue.c
83441@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
83442 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
83443 info->attr.mq_msgsize);
83444
83445+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
83446 spin_lock(&mq_lock);
83447 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
83448 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
83449diff --git a/ipc/msg.c b/ipc/msg.c
83450index 558aa91..359e718 100644
83451--- a/ipc/msg.c
83452+++ b/ipc/msg.c
83453@@ -297,18 +297,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
83454 return security_msg_queue_associate(msq, msgflg);
83455 }
83456
83457+static struct ipc_ops msg_ops = {
83458+ .getnew = newque,
83459+ .associate = msg_security,
83460+ .more_checks = NULL
83461+};
83462+
83463 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
83464 {
83465 struct ipc_namespace *ns;
83466- struct ipc_ops msg_ops;
83467 struct ipc_params msg_params;
83468
83469 ns = current->nsproxy->ipc_ns;
83470
83471- msg_ops.getnew = newque;
83472- msg_ops.associate = msg_security;
83473- msg_ops.more_checks = NULL;
83474-
83475 msg_params.key = key;
83476 msg_params.flg = msgflg;
83477
83478diff --git a/ipc/sem.c b/ipc/sem.c
83479index db9d241..bc8427c 100644
83480--- a/ipc/sem.c
83481+++ b/ipc/sem.c
83482@@ -562,10 +562,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
83483 return 0;
83484 }
83485
83486+static struct ipc_ops sem_ops = {
83487+ .getnew = newary,
83488+ .associate = sem_security,
83489+ .more_checks = sem_more_checks
83490+};
83491+
83492 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
83493 {
83494 struct ipc_namespace *ns;
83495- struct ipc_ops sem_ops;
83496 struct ipc_params sem_params;
83497
83498 ns = current->nsproxy->ipc_ns;
83499@@ -573,10 +578,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
83500 if (nsems < 0 || nsems > ns->sc_semmsl)
83501 return -EINVAL;
83502
83503- sem_ops.getnew = newary;
83504- sem_ops.associate = sem_security;
83505- sem_ops.more_checks = sem_more_checks;
83506-
83507 sem_params.key = key;
83508 sem_params.flg = semflg;
83509 sem_params.u.nsems = nsems;
83510diff --git a/ipc/shm.c b/ipc/shm.c
83511index 7a51443..3a257d8 100644
83512--- a/ipc/shm.c
83513+++ b/ipc/shm.c
83514@@ -72,6 +72,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
83515 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
83516 #endif
83517
83518+#ifdef CONFIG_GRKERNSEC
83519+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
83520+ const time_t shm_createtime, const kuid_t cuid,
83521+ const int shmid);
83522+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
83523+ const time_t shm_createtime);
83524+#endif
83525+
83526 void shm_init_ns(struct ipc_namespace *ns)
83527 {
83528 ns->shm_ctlmax = SHMMAX;
83529@@ -554,6 +562,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
83530 shp->shm_lprid = 0;
83531 shp->shm_atim = shp->shm_dtim = 0;
83532 shp->shm_ctim = get_seconds();
83533+#ifdef CONFIG_GRKERNSEC
83534+ {
83535+ struct timespec timeval;
83536+ do_posix_clock_monotonic_gettime(&timeval);
83537+
83538+ shp->shm_createtime = timeval.tv_sec;
83539+ }
83540+#endif
83541 shp->shm_segsz = size;
83542 shp->shm_nattch = 0;
83543 shp->shm_file = file;
83544@@ -607,18 +623,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
83545 return 0;
83546 }
83547
83548+static struct ipc_ops shm_ops = {
83549+ .getnew = newseg,
83550+ .associate = shm_security,
83551+ .more_checks = shm_more_checks
83552+};
83553+
83554 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
83555 {
83556 struct ipc_namespace *ns;
83557- struct ipc_ops shm_ops;
83558 struct ipc_params shm_params;
83559
83560 ns = current->nsproxy->ipc_ns;
83561
83562- shm_ops.getnew = newseg;
83563- shm_ops.associate = shm_security;
83564- shm_ops.more_checks = shm_more_checks;
83565-
83566 shm_params.key = key;
83567 shm_params.flg = shmflg;
83568 shm_params.u.size = size;
83569@@ -1089,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
83570 f_mode = FMODE_READ | FMODE_WRITE;
83571 }
83572 if (shmflg & SHM_EXEC) {
83573+
83574+#ifdef CONFIG_PAX_MPROTECT
83575+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
83576+ goto out;
83577+#endif
83578+
83579 prot |= PROT_EXEC;
83580 acc_mode |= S_IXUGO;
83581 }
83582@@ -1113,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
83583 if (err)
83584 goto out_unlock;
83585
83586+#ifdef CONFIG_GRKERNSEC
83587+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
83588+ shp->shm_perm.cuid, shmid) ||
83589+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
83590+ err = -EACCES;
83591+ goto out_unlock;
83592+ }
83593+#endif
83594+
83595 ipc_lock_object(&shp->shm_perm);
83596
83597 /* check if shm_destroy() is tearing down shp */
83598@@ -1125,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
83599 path = shp->shm_file->f_path;
83600 path_get(&path);
83601 shp->shm_nattch++;
83602+#ifdef CONFIG_GRKERNSEC
83603+ shp->shm_lapid = current->pid;
83604+#endif
83605 size = i_size_read(path.dentry->d_inode);
83606 ipc_unlock_object(&shp->shm_perm);
83607 rcu_read_unlock();
83608diff --git a/ipc/util.c b/ipc/util.c
83609index 3ae17a4..d67c32f 100644
83610--- a/ipc/util.c
83611+++ b/ipc/util.c
83612@@ -71,6 +71,8 @@ struct ipc_proc_iface {
83613 int (*show)(struct seq_file *, void *);
83614 };
83615
83616+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
83617+
83618 static void ipc_memory_notifier(struct work_struct *work)
83619 {
83620 ipcns_notify(IPCNS_MEMCHANGED);
83621@@ -558,6 +560,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
83622 granted_mode >>= 6;
83623 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
83624 granted_mode >>= 3;
83625+
83626+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
83627+ return -1;
83628+
83629 /* is there some bit set in requested_mode but not in granted_mode? */
83630 if ((requested_mode & ~granted_mode & 0007) &&
83631 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
83632diff --git a/kernel/acct.c b/kernel/acct.c
83633index 8d6e145..33e0b1e 100644
83634--- a/kernel/acct.c
83635+++ b/kernel/acct.c
83636@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
83637 */
83638 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
83639 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
83640- file->f_op->write(file, (char *)&ac,
83641+ file->f_op->write(file, (char __force_user *)&ac,
83642 sizeof(acct_t), &file->f_pos);
83643 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
83644 set_fs(fs);
83645diff --git a/kernel/audit.c b/kernel/audit.c
83646index 906ae5a0..a7ad0b4 100644
83647--- a/kernel/audit.c
83648+++ b/kernel/audit.c
83649@@ -117,7 +117,7 @@ u32 audit_sig_sid = 0;
83650 3) suppressed due to audit_rate_limit
83651 4) suppressed due to audit_backlog_limit
83652 */
83653-static atomic_t audit_lost = ATOMIC_INIT(0);
83654+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
83655
83656 /* The netlink socket. */
83657 static struct sock *audit_sock;
83658@@ -250,7 +250,7 @@ void audit_log_lost(const char *message)
83659 unsigned long now;
83660 int print;
83661
83662- atomic_inc(&audit_lost);
83663+ atomic_inc_unchecked(&audit_lost);
83664
83665 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
83666
83667@@ -269,7 +269,7 @@ void audit_log_lost(const char *message)
83668 printk(KERN_WARNING
83669 "audit: audit_lost=%d audit_rate_limit=%d "
83670 "audit_backlog_limit=%d\n",
83671- atomic_read(&audit_lost),
83672+ atomic_read_unchecked(&audit_lost),
83673 audit_rate_limit,
83674 audit_backlog_limit);
83675 audit_panic(message);
83676@@ -765,7 +765,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
83677 status_set.pid = audit_pid;
83678 status_set.rate_limit = audit_rate_limit;
83679 status_set.backlog_limit = audit_backlog_limit;
83680- status_set.lost = atomic_read(&audit_lost);
83681+ status_set.lost = atomic_read_unchecked(&audit_lost);
83682 status_set.backlog = skb_queue_len(&audit_skb_queue);
83683 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
83684 &status_set, sizeof(status_set));
83685@@ -1356,7 +1356,7 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,
83686 int i, avail, new_len;
83687 unsigned char *ptr;
83688 struct sk_buff *skb;
83689- static const unsigned char *hex = "0123456789ABCDEF";
83690+ static const unsigned char hex[] = "0123456789ABCDEF";
83691
83692 if (!ab)
83693 return;
83694diff --git a/kernel/auditsc.c b/kernel/auditsc.c
83695index 90594c9..abbeed7 100644
83696--- a/kernel/auditsc.c
83697+++ b/kernel/auditsc.c
83698@@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
83699 }
83700
83701 /* global counter which is incremented every time something logs in */
83702-static atomic_t session_id = ATOMIC_INIT(0);
83703+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
83704
83705 static int audit_set_loginuid_perm(kuid_t loginuid)
83706 {
83707@@ -2008,7 +2008,7 @@ int audit_set_loginuid(kuid_t loginuid)
83708
83709 /* are we setting or clearing? */
83710 if (uid_valid(loginuid))
83711- sessionid = atomic_inc_return(&session_id);
83712+ sessionid = atomic_inc_return_unchecked(&session_id);
83713
83714 task->sessionid = sessionid;
83715 task->loginuid = loginuid;
83716diff --git a/kernel/capability.c b/kernel/capability.c
83717index 4e66bf9..cdccecf 100644
83718--- a/kernel/capability.c
83719+++ b/kernel/capability.c
83720@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
83721 * before modification is attempted and the application
83722 * fails.
83723 */
83724+ if (tocopy > ARRAY_SIZE(kdata))
83725+ return -EFAULT;
83726+
83727 if (copy_to_user(dataptr, kdata, tocopy
83728 * sizeof(struct __user_cap_data_struct))) {
83729 return -EFAULT;
83730@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
83731 int ret;
83732
83733 rcu_read_lock();
83734- ret = security_capable(__task_cred(t), ns, cap);
83735+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
83736+ gr_task_is_capable(t, __task_cred(t), cap);
83737 rcu_read_unlock();
83738
83739- return (ret == 0);
83740+ return ret;
83741 }
83742
83743 /**
83744@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
83745 int ret;
83746
83747 rcu_read_lock();
83748- ret = security_capable_noaudit(__task_cred(t), ns, cap);
83749+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
83750 rcu_read_unlock();
83751
83752- return (ret == 0);
83753+ return ret;
83754 }
83755
83756 /**
83757@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
83758 BUG();
83759 }
83760
83761- if (security_capable(current_cred(), ns, cap) == 0) {
83762+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
83763 current->flags |= PF_SUPERPRIV;
83764 return true;
83765 }
83766@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
83767 }
83768 EXPORT_SYMBOL(ns_capable);
83769
83770+bool ns_capable_nolog(struct user_namespace *ns, int cap)
83771+{
83772+ if (unlikely(!cap_valid(cap))) {
83773+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
83774+ BUG();
83775+ }
83776+
83777+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
83778+ current->flags |= PF_SUPERPRIV;
83779+ return true;
83780+ }
83781+ return false;
83782+}
83783+EXPORT_SYMBOL(ns_capable_nolog);
83784+
83785 /**
83786 * file_ns_capable - Determine if the file's opener had a capability in effect
83787 * @file: The file we want to check
83788@@ -432,6 +451,12 @@ bool capable(int cap)
83789 }
83790 EXPORT_SYMBOL(capable);
83791
83792+bool capable_nolog(int cap)
83793+{
83794+ return ns_capable_nolog(&init_user_ns, cap);
83795+}
83796+EXPORT_SYMBOL(capable_nolog);
83797+
83798 /**
83799 * inode_capable - Check superior capability over inode
83800 * @inode: The inode in question
83801@@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
83802 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
83803 }
83804 EXPORT_SYMBOL(inode_capable);
83805+
83806+bool inode_capable_nolog(const struct inode *inode, int cap)
83807+{
83808+ struct user_namespace *ns = current_user_ns();
83809+
83810+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
83811+}
83812+EXPORT_SYMBOL(inode_capable_nolog);
83813diff --git a/kernel/cgroup.c b/kernel/cgroup.c
83814index bc1dcab..f3a6b42 100644
83815--- a/kernel/cgroup.c
83816+++ b/kernel/cgroup.c
83817@@ -5607,7 +5607,7 @@ static int cgroup_css_links_read(struct cgroup_subsys_state *css,
83818 struct css_set *cset = link->cset;
83819 struct task_struct *task;
83820 int count = 0;
83821- seq_printf(seq, "css_set %p\n", cset);
83822+ seq_printf(seq, "css_set %pK\n", cset);
83823 list_for_each_entry(task, &cset->tasks, cg_list) {
83824 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
83825 seq_puts(seq, " ...\n");
83826diff --git a/kernel/compat.c b/kernel/compat.c
83827index 0a09e48..b46b3d78 100644
83828--- a/kernel/compat.c
83829+++ b/kernel/compat.c
83830@@ -13,6 +13,7 @@
83831
83832 #include <linux/linkage.h>
83833 #include <linux/compat.h>
83834+#include <linux/module.h>
83835 #include <linux/errno.h>
83836 #include <linux/time.h>
83837 #include <linux/signal.h>
83838@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
83839 mm_segment_t oldfs;
83840 long ret;
83841
83842- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
83843+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
83844 oldfs = get_fs();
83845 set_fs(KERNEL_DS);
83846 ret = hrtimer_nanosleep_restart(restart);
83847@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
83848 oldfs = get_fs();
83849 set_fs(KERNEL_DS);
83850 ret = hrtimer_nanosleep(&tu,
83851- rmtp ? (struct timespec __user *)&rmt : NULL,
83852+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
83853 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
83854 set_fs(oldfs);
83855
83856@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
83857 mm_segment_t old_fs = get_fs();
83858
83859 set_fs(KERNEL_DS);
83860- ret = sys_sigpending((old_sigset_t __user *) &s);
83861+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
83862 set_fs(old_fs);
83863 if (ret == 0)
83864 ret = put_user(s, set);
83865@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
83866 mm_segment_t old_fs = get_fs();
83867
83868 set_fs(KERNEL_DS);
83869- ret = sys_old_getrlimit(resource, &r);
83870+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
83871 set_fs(old_fs);
83872
83873 if (!ret) {
83874@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
83875 set_fs (KERNEL_DS);
83876 ret = sys_wait4(pid,
83877 (stat_addr ?
83878- (unsigned int __user *) &status : NULL),
83879- options, (struct rusage __user *) &r);
83880+ (unsigned int __force_user *) &status : NULL),
83881+ options, (struct rusage __force_user *) &r);
83882 set_fs (old_fs);
83883
83884 if (ret > 0) {
83885@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
83886 memset(&info, 0, sizeof(info));
83887
83888 set_fs(KERNEL_DS);
83889- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
83890- uru ? (struct rusage __user *)&ru : NULL);
83891+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
83892+ uru ? (struct rusage __force_user *)&ru : NULL);
83893 set_fs(old_fs);
83894
83895 if ((ret < 0) || (info.si_signo == 0))
83896@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
83897 oldfs = get_fs();
83898 set_fs(KERNEL_DS);
83899 err = sys_timer_settime(timer_id, flags,
83900- (struct itimerspec __user *) &newts,
83901- (struct itimerspec __user *) &oldts);
83902+ (struct itimerspec __force_user *) &newts,
83903+ (struct itimerspec __force_user *) &oldts);
83904 set_fs(oldfs);
83905 if (!err && old && put_compat_itimerspec(old, &oldts))
83906 return -EFAULT;
83907@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
83908 oldfs = get_fs();
83909 set_fs(KERNEL_DS);
83910 err = sys_timer_gettime(timer_id,
83911- (struct itimerspec __user *) &ts);
83912+ (struct itimerspec __force_user *) &ts);
83913 set_fs(oldfs);
83914 if (!err && put_compat_itimerspec(setting, &ts))
83915 return -EFAULT;
83916@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
83917 oldfs = get_fs();
83918 set_fs(KERNEL_DS);
83919 err = sys_clock_settime(which_clock,
83920- (struct timespec __user *) &ts);
83921+ (struct timespec __force_user *) &ts);
83922 set_fs(oldfs);
83923 return err;
83924 }
83925@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
83926 oldfs = get_fs();
83927 set_fs(KERNEL_DS);
83928 err = sys_clock_gettime(which_clock,
83929- (struct timespec __user *) &ts);
83930+ (struct timespec __force_user *) &ts);
83931 set_fs(oldfs);
83932 if (!err && put_compat_timespec(&ts, tp))
83933 return -EFAULT;
83934@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
83935
83936 oldfs = get_fs();
83937 set_fs(KERNEL_DS);
83938- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
83939+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
83940 set_fs(oldfs);
83941
83942 err = compat_put_timex(utp, &txc);
83943@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
83944 oldfs = get_fs();
83945 set_fs(KERNEL_DS);
83946 err = sys_clock_getres(which_clock,
83947- (struct timespec __user *) &ts);
83948+ (struct timespec __force_user *) &ts);
83949 set_fs(oldfs);
83950 if (!err && tp && put_compat_timespec(&ts, tp))
83951 return -EFAULT;
83952@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
83953 long err;
83954 mm_segment_t oldfs;
83955 struct timespec tu;
83956- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
83957+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
83958
83959- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
83960+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
83961 oldfs = get_fs();
83962 set_fs(KERNEL_DS);
83963 err = clock_nanosleep_restart(restart);
83964@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
83965 oldfs = get_fs();
83966 set_fs(KERNEL_DS);
83967 err = sys_clock_nanosleep(which_clock, flags,
83968- (struct timespec __user *) &in,
83969- (struct timespec __user *) &out);
83970+ (struct timespec __force_user *) &in,
83971+ (struct timespec __force_user *) &out);
83972 set_fs(oldfs);
83973
83974 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
83975@@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
83976 mm_segment_t old_fs = get_fs();
83977
83978 set_fs(KERNEL_DS);
83979- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
83980+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
83981 set_fs(old_fs);
83982 if (put_compat_timespec(&t, interval))
83983 return -EFAULT;
83984diff --git a/kernel/configs.c b/kernel/configs.c
83985index c18b1f1..b9a0132 100644
83986--- a/kernel/configs.c
83987+++ b/kernel/configs.c
83988@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
83989 struct proc_dir_entry *entry;
83990
83991 /* create the current config file */
83992+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
83993+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
83994+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
83995+ &ikconfig_file_ops);
83996+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83997+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
83998+ &ikconfig_file_ops);
83999+#endif
84000+#else
84001 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
84002 &ikconfig_file_ops);
84003+#endif
84004+
84005 if (!entry)
84006 return -ENOMEM;
84007
84008diff --git a/kernel/cred.c b/kernel/cred.c
84009index e0573a4..3874e41 100644
84010--- a/kernel/cred.c
84011+++ b/kernel/cred.c
84012@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
84013 validate_creds(cred);
84014 alter_cred_subscribers(cred, -1);
84015 put_cred(cred);
84016+
84017+#ifdef CONFIG_GRKERNSEC_SETXID
84018+ cred = (struct cred *) tsk->delayed_cred;
84019+ if (cred != NULL) {
84020+ tsk->delayed_cred = NULL;
84021+ validate_creds(cred);
84022+ alter_cred_subscribers(cred, -1);
84023+ put_cred(cred);
84024+ }
84025+#endif
84026 }
84027
84028 /**
84029@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
84030 * Always returns 0 thus allowing this function to be tail-called at the end
84031 * of, say, sys_setgid().
84032 */
84033-int commit_creds(struct cred *new)
84034+static int __commit_creds(struct cred *new)
84035 {
84036 struct task_struct *task = current;
84037 const struct cred *old = task->real_cred;
84038@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
84039
84040 get_cred(new); /* we will require a ref for the subj creds too */
84041
84042+ gr_set_role_label(task, new->uid, new->gid);
84043+
84044 /* dumpability changes */
84045 if (!uid_eq(old->euid, new->euid) ||
84046 !gid_eq(old->egid, new->egid) ||
84047@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
84048 put_cred(old);
84049 return 0;
84050 }
84051+#ifdef CONFIG_GRKERNSEC_SETXID
84052+extern int set_user(struct cred *new);
84053+
84054+void gr_delayed_cred_worker(void)
84055+{
84056+ const struct cred *new = current->delayed_cred;
84057+ struct cred *ncred;
84058+
84059+ current->delayed_cred = NULL;
84060+
84061+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
84062+ // from doing get_cred on it when queueing this
84063+ put_cred(new);
84064+ return;
84065+ } else if (new == NULL)
84066+ return;
84067+
84068+ ncred = prepare_creds();
84069+ if (!ncred)
84070+ goto die;
84071+ // uids
84072+ ncred->uid = new->uid;
84073+ ncred->euid = new->euid;
84074+ ncred->suid = new->suid;
84075+ ncred->fsuid = new->fsuid;
84076+ // gids
84077+ ncred->gid = new->gid;
84078+ ncred->egid = new->egid;
84079+ ncred->sgid = new->sgid;
84080+ ncred->fsgid = new->fsgid;
84081+ // groups
84082+ if (set_groups(ncred, new->group_info) < 0) {
84083+ abort_creds(ncred);
84084+ goto die;
84085+ }
84086+ // caps
84087+ ncred->securebits = new->securebits;
84088+ ncred->cap_inheritable = new->cap_inheritable;
84089+ ncred->cap_permitted = new->cap_permitted;
84090+ ncred->cap_effective = new->cap_effective;
84091+ ncred->cap_bset = new->cap_bset;
84092+
84093+ if (set_user(ncred)) {
84094+ abort_creds(ncred);
84095+ goto die;
84096+ }
84097+
84098+ // from doing get_cred on it when queueing this
84099+ put_cred(new);
84100+
84101+ __commit_creds(ncred);
84102+ return;
84103+die:
84104+ // from doing get_cred on it when queueing this
84105+ put_cred(new);
84106+ do_group_exit(SIGKILL);
84107+}
84108+#endif
84109+
84110+int commit_creds(struct cred *new)
84111+{
84112+#ifdef CONFIG_GRKERNSEC_SETXID
84113+ int ret;
84114+ int schedule_it = 0;
84115+ struct task_struct *t;
84116+
84117+ /* we won't get called with tasklist_lock held for writing
84118+ and interrupts disabled as the cred struct in that case is
84119+ init_cred
84120+ */
84121+ if (grsec_enable_setxid && !current_is_single_threaded() &&
84122+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
84123+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
84124+ schedule_it = 1;
84125+ }
84126+ ret = __commit_creds(new);
84127+ if (schedule_it) {
84128+ rcu_read_lock();
84129+ read_lock(&tasklist_lock);
84130+ for (t = next_thread(current); t != current;
84131+ t = next_thread(t)) {
84132+ if (t->delayed_cred == NULL) {
84133+ t->delayed_cred = get_cred(new);
84134+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
84135+ set_tsk_need_resched(t);
84136+ }
84137+ }
84138+ read_unlock(&tasklist_lock);
84139+ rcu_read_unlock();
84140+ }
84141+ return ret;
84142+#else
84143+ return __commit_creds(new);
84144+#endif
84145+}
84146+
84147 EXPORT_SYMBOL(commit_creds);
84148
84149 /**
84150diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
84151index 7d2f35e..1bafcd0 100644
84152--- a/kernel/debug/debug_core.c
84153+++ b/kernel/debug/debug_core.c
84154@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
84155 */
84156 static atomic_t masters_in_kgdb;
84157 static atomic_t slaves_in_kgdb;
84158-static atomic_t kgdb_break_tasklet_var;
84159+static atomic_unchecked_t kgdb_break_tasklet_var;
84160 atomic_t kgdb_setting_breakpoint;
84161
84162 struct task_struct *kgdb_usethread;
84163@@ -133,7 +133,7 @@ int kgdb_single_step;
84164 static pid_t kgdb_sstep_pid;
84165
84166 /* to keep track of the CPU which is doing the single stepping*/
84167-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
84168+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
84169
84170 /*
84171 * If you are debugging a problem where roundup (the collection of
84172@@ -541,7 +541,7 @@ return_normal:
84173 * kernel will only try for the value of sstep_tries before
84174 * giving up and continuing on.
84175 */
84176- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
84177+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
84178 (kgdb_info[cpu].task &&
84179 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
84180 atomic_set(&kgdb_active, -1);
84181@@ -639,8 +639,8 @@ cpu_master_loop:
84182 }
84183
84184 kgdb_restore:
84185- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
84186- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
84187+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
84188+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
84189 if (kgdb_info[sstep_cpu].task)
84190 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
84191 else
84192@@ -916,18 +916,18 @@ static void kgdb_unregister_callbacks(void)
84193 static void kgdb_tasklet_bpt(unsigned long ing)
84194 {
84195 kgdb_breakpoint();
84196- atomic_set(&kgdb_break_tasklet_var, 0);
84197+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
84198 }
84199
84200 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
84201
84202 void kgdb_schedule_breakpoint(void)
84203 {
84204- if (atomic_read(&kgdb_break_tasklet_var) ||
84205+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
84206 atomic_read(&kgdb_active) != -1 ||
84207 atomic_read(&kgdb_setting_breakpoint))
84208 return;
84209- atomic_inc(&kgdb_break_tasklet_var);
84210+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
84211 tasklet_schedule(&kgdb_tasklet_breakpoint);
84212 }
84213 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
84214diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
84215index 0b097c8..11dd5c5 100644
84216--- a/kernel/debug/kdb/kdb_main.c
84217+++ b/kernel/debug/kdb/kdb_main.c
84218@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
84219 continue;
84220
84221 kdb_printf("%-20s%8u 0x%p ", mod->name,
84222- mod->core_size, (void *)mod);
84223+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
84224 #ifdef CONFIG_MODULE_UNLOAD
84225 kdb_printf("%4ld ", module_refcount(mod));
84226 #endif
84227@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
84228 kdb_printf(" (Loading)");
84229 else
84230 kdb_printf(" (Live)");
84231- kdb_printf(" 0x%p", mod->module_core);
84232+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
84233
84234 #ifdef CONFIG_MODULE_UNLOAD
84235 {
84236diff --git a/kernel/events/core.c b/kernel/events/core.c
84237index f574401..11b21f0 100644
84238--- a/kernel/events/core.c
84239+++ b/kernel/events/core.c
84240@@ -157,8 +157,15 @@ static struct srcu_struct pmus_srcu;
84241 * 0 - disallow raw tracepoint access for unpriv
84242 * 1 - disallow cpu events for unpriv
84243 * 2 - disallow kernel profiling for unpriv
84244+ * 3 - disallow all unpriv perf event use
84245 */
84246-int sysctl_perf_event_paranoid __read_mostly = 1;
84247+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
84248+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
84249+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
84250+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
84251+#else
84252+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
84253+#endif
84254
84255 /* Minimum for 512 kiB + 1 user control page */
84256 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
84257@@ -184,7 +191,7 @@ void update_perf_cpu_limits(void)
84258
84259 tmp *= sysctl_perf_cpu_time_max_percent;
84260 do_div(tmp, 100);
84261- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
84262+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
84263 }
84264
84265 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
84266@@ -271,7 +278,7 @@ void perf_sample_event_took(u64 sample_len_ns)
84267 update_perf_cpu_limits();
84268 }
84269
84270-static atomic64_t perf_event_id;
84271+static atomic64_unchecked_t perf_event_id;
84272
84273 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
84274 enum event_type_t event_type);
84275@@ -2985,7 +2992,7 @@ static void __perf_event_read(void *info)
84276
84277 static inline u64 perf_event_count(struct perf_event *event)
84278 {
84279- return local64_read(&event->count) + atomic64_read(&event->child_count);
84280+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
84281 }
84282
84283 static u64 perf_event_read(struct perf_event *event)
84284@@ -3353,9 +3360,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
84285 mutex_lock(&event->child_mutex);
84286 total += perf_event_read(event);
84287 *enabled += event->total_time_enabled +
84288- atomic64_read(&event->child_total_time_enabled);
84289+ atomic64_read_unchecked(&event->child_total_time_enabled);
84290 *running += event->total_time_running +
84291- atomic64_read(&event->child_total_time_running);
84292+ atomic64_read_unchecked(&event->child_total_time_running);
84293
84294 list_for_each_entry(child, &event->child_list, child_list) {
84295 total += perf_event_read(child);
84296@@ -3770,10 +3777,10 @@ void perf_event_update_userpage(struct perf_event *event)
84297 userpg->offset -= local64_read(&event->hw.prev_count);
84298
84299 userpg->time_enabled = enabled +
84300- atomic64_read(&event->child_total_time_enabled);
84301+ atomic64_read_unchecked(&event->child_total_time_enabled);
84302
84303 userpg->time_running = running +
84304- atomic64_read(&event->child_total_time_running);
84305+ atomic64_read_unchecked(&event->child_total_time_running);
84306
84307 arch_perf_update_userpage(userpg, now);
84308
84309@@ -4324,7 +4331,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
84310
84311 /* Data. */
84312 sp = perf_user_stack_pointer(regs);
84313- rem = __output_copy_user(handle, (void *) sp, dump_size);
84314+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
84315 dyn_size = dump_size - rem;
84316
84317 perf_output_skip(handle, rem);
84318@@ -4415,11 +4422,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
84319 values[n++] = perf_event_count(event);
84320 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
84321 values[n++] = enabled +
84322- atomic64_read(&event->child_total_time_enabled);
84323+ atomic64_read_unchecked(&event->child_total_time_enabled);
84324 }
84325 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
84326 values[n++] = running +
84327- atomic64_read(&event->child_total_time_running);
84328+ atomic64_read_unchecked(&event->child_total_time_running);
84329 }
84330 if (read_format & PERF_FORMAT_ID)
84331 values[n++] = primary_event_id(event);
84332@@ -6686,7 +6693,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
84333 event->parent = parent_event;
84334
84335 event->ns = get_pid_ns(task_active_pid_ns(current));
84336- event->id = atomic64_inc_return(&perf_event_id);
84337+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
84338
84339 event->state = PERF_EVENT_STATE_INACTIVE;
84340
84341@@ -6985,6 +6992,11 @@ SYSCALL_DEFINE5(perf_event_open,
84342 if (flags & ~PERF_FLAG_ALL)
84343 return -EINVAL;
84344
84345+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
84346+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
84347+ return -EACCES;
84348+#endif
84349+
84350 err = perf_copy_attr(attr_uptr, &attr);
84351 if (err)
84352 return err;
84353@@ -7316,10 +7328,10 @@ static void sync_child_event(struct perf_event *child_event,
84354 /*
84355 * Add back the child's count to the parent's count:
84356 */
84357- atomic64_add(child_val, &parent_event->child_count);
84358- atomic64_add(child_event->total_time_enabled,
84359+ atomic64_add_unchecked(child_val, &parent_event->child_count);
84360+ atomic64_add_unchecked(child_event->total_time_enabled,
84361 &parent_event->child_total_time_enabled);
84362- atomic64_add(child_event->total_time_running,
84363+ atomic64_add_unchecked(child_event->total_time_running,
84364 &parent_event->child_total_time_running);
84365
84366 /*
84367diff --git a/kernel/events/internal.h b/kernel/events/internal.h
84368index 569b2187..19940d9 100644
84369--- a/kernel/events/internal.h
84370+++ b/kernel/events/internal.h
84371@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
84372 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
84373 }
84374
84375-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
84376+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
84377 static inline unsigned long \
84378 func_name(struct perf_output_handle *handle, \
84379- const void *buf, unsigned long len) \
84380+ const void user *buf, unsigned long len) \
84381 { \
84382 unsigned long size, written; \
84383 \
84384@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
84385 return 0;
84386 }
84387
84388-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
84389+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
84390
84391 static inline unsigned long
84392 memcpy_skip(void *dst, const void *src, unsigned long n)
84393@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
84394 return 0;
84395 }
84396
84397-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
84398+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
84399
84400 #ifndef arch_perf_out_copy_user
84401 #define arch_perf_out_copy_user arch_perf_out_copy_user
84402@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
84403 }
84404 #endif
84405
84406-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
84407+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
84408
84409 /* Callchain handling */
84410 extern struct perf_callchain_entry *
84411diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
84412index 24b7d6c..40cf797 100644
84413--- a/kernel/events/uprobes.c
84414+++ b/kernel/events/uprobes.c
84415@@ -1640,7 +1640,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
84416 {
84417 struct page *page;
84418 uprobe_opcode_t opcode;
84419- int result;
84420+ long result;
84421
84422 pagefault_disable();
84423 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
84424diff --git a/kernel/exit.c b/kernel/exit.c
84425index a949819..a5f127d 100644
84426--- a/kernel/exit.c
84427+++ b/kernel/exit.c
84428@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
84429 struct task_struct *leader;
84430 int zap_leader;
84431 repeat:
84432+#ifdef CONFIG_NET
84433+ gr_del_task_from_ip_table(p);
84434+#endif
84435+
84436 /* don't need to get the RCU readlock here - the process is dead and
84437 * can't be modifying its own credentials. But shut RCU-lockdep up */
84438 rcu_read_lock();
84439@@ -329,7 +333,7 @@ int allow_signal(int sig)
84440 * know it'll be handled, so that they don't get converted to
84441 * SIGKILL or just silently dropped.
84442 */
84443- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
84444+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
84445 recalc_sigpending();
84446 spin_unlock_irq(&current->sighand->siglock);
84447 return 0;
84448@@ -698,6 +702,8 @@ void do_exit(long code)
84449 struct task_struct *tsk = current;
84450 int group_dead;
84451
84452+ set_fs(USER_DS);
84453+
84454 profile_task_exit(tsk);
84455
84456 WARN_ON(blk_needs_flush_plug(tsk));
84457@@ -714,7 +720,6 @@ void do_exit(long code)
84458 * mm_release()->clear_child_tid() from writing to a user-controlled
84459 * kernel address.
84460 */
84461- set_fs(USER_DS);
84462
84463 ptrace_event(PTRACE_EVENT_EXIT, code);
84464
84465@@ -773,6 +778,9 @@ void do_exit(long code)
84466 tsk->exit_code = code;
84467 taskstats_exit(tsk, group_dead);
84468
84469+ gr_acl_handle_psacct(tsk, code);
84470+ gr_acl_handle_exit();
84471+
84472 exit_mm(tsk);
84473
84474 if (group_dead)
84475@@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
84476 * Take down every thread in the group. This is called by fatal signals
84477 * as well as by sys_exit_group (below).
84478 */
84479-void
84480+__noreturn void
84481 do_group_exit(int exit_code)
84482 {
84483 struct signal_struct *sig = current->signal;
84484diff --git a/kernel/fork.c b/kernel/fork.c
84485index dfa736c..d170f9b 100644
84486--- a/kernel/fork.c
84487+++ b/kernel/fork.c
84488@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
84489 *stackend = STACK_END_MAGIC; /* for overflow detection */
84490
84491 #ifdef CONFIG_CC_STACKPROTECTOR
84492- tsk->stack_canary = get_random_int();
84493+ tsk->stack_canary = pax_get_random_long();
84494 #endif
84495
84496 /*
84497@@ -345,12 +345,80 @@ free_tsk:
84498 }
84499
84500 #ifdef CONFIG_MMU
84501-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84502+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
84503+{
84504+ struct vm_area_struct *tmp;
84505+ unsigned long charge;
84506+ struct file *file;
84507+ int retval;
84508+
84509+ charge = 0;
84510+ if (mpnt->vm_flags & VM_ACCOUNT) {
84511+ unsigned long len = vma_pages(mpnt);
84512+
84513+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
84514+ goto fail_nomem;
84515+ charge = len;
84516+ }
84517+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
84518+ if (!tmp)
84519+ goto fail_nomem;
84520+ *tmp = *mpnt;
84521+ tmp->vm_mm = mm;
84522+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
84523+ retval = vma_dup_policy(mpnt, tmp);
84524+ if (retval)
84525+ goto fail_nomem_policy;
84526+ if (anon_vma_fork(tmp, mpnt))
84527+ goto fail_nomem_anon_vma_fork;
84528+ tmp->vm_flags &= ~VM_LOCKED;
84529+ tmp->vm_next = tmp->vm_prev = NULL;
84530+ tmp->vm_mirror = NULL;
84531+ file = tmp->vm_file;
84532+ if (file) {
84533+ struct inode *inode = file_inode(file);
84534+ struct address_space *mapping = file->f_mapping;
84535+
84536+ get_file(file);
84537+ if (tmp->vm_flags & VM_DENYWRITE)
84538+ atomic_dec(&inode->i_writecount);
84539+ mutex_lock(&mapping->i_mmap_mutex);
84540+ if (tmp->vm_flags & VM_SHARED)
84541+ mapping->i_mmap_writable++;
84542+ flush_dcache_mmap_lock(mapping);
84543+ /* insert tmp into the share list, just after mpnt */
84544+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
84545+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
84546+ else
84547+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
84548+ flush_dcache_mmap_unlock(mapping);
84549+ mutex_unlock(&mapping->i_mmap_mutex);
84550+ }
84551+
84552+ /*
84553+ * Clear hugetlb-related page reserves for children. This only
84554+ * affects MAP_PRIVATE mappings. Faults generated by the child
84555+ * are not guaranteed to succeed, even if read-only
84556+ */
84557+ if (is_vm_hugetlb_page(tmp))
84558+ reset_vma_resv_huge_pages(tmp);
84559+
84560+ return tmp;
84561+
84562+fail_nomem_anon_vma_fork:
84563+ mpol_put(vma_policy(tmp));
84564+fail_nomem_policy:
84565+ kmem_cache_free(vm_area_cachep, tmp);
84566+fail_nomem:
84567+ vm_unacct_memory(charge);
84568+ return NULL;
84569+}
84570+
84571+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84572 {
84573 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
84574 struct rb_node **rb_link, *rb_parent;
84575 int retval;
84576- unsigned long charge;
84577
84578 uprobe_start_dup_mmap();
84579 down_write(&oldmm->mmap_sem);
84580@@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84581
84582 prev = NULL;
84583 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
84584- struct file *file;
84585-
84586 if (mpnt->vm_flags & VM_DONTCOPY) {
84587 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
84588 -vma_pages(mpnt));
84589 continue;
84590 }
84591- charge = 0;
84592- if (mpnt->vm_flags & VM_ACCOUNT) {
84593- unsigned long len = vma_pages(mpnt);
84594-
84595- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
84596- goto fail_nomem;
84597- charge = len;
84598- }
84599- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
84600- if (!tmp)
84601- goto fail_nomem;
84602- *tmp = *mpnt;
84603- INIT_LIST_HEAD(&tmp->anon_vma_chain);
84604- retval = vma_dup_policy(mpnt, tmp);
84605- if (retval)
84606- goto fail_nomem_policy;
84607- tmp->vm_mm = mm;
84608- if (anon_vma_fork(tmp, mpnt))
84609- goto fail_nomem_anon_vma_fork;
84610- tmp->vm_flags &= ~VM_LOCKED;
84611- tmp->vm_next = tmp->vm_prev = NULL;
84612- file = tmp->vm_file;
84613- if (file) {
84614- struct inode *inode = file_inode(file);
84615- struct address_space *mapping = file->f_mapping;
84616-
84617- get_file(file);
84618- if (tmp->vm_flags & VM_DENYWRITE)
84619- atomic_dec(&inode->i_writecount);
84620- mutex_lock(&mapping->i_mmap_mutex);
84621- if (tmp->vm_flags & VM_SHARED)
84622- mapping->i_mmap_writable++;
84623- flush_dcache_mmap_lock(mapping);
84624- /* insert tmp into the share list, just after mpnt */
84625- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
84626- vma_nonlinear_insert(tmp,
84627- &mapping->i_mmap_nonlinear);
84628- else
84629- vma_interval_tree_insert_after(tmp, mpnt,
84630- &mapping->i_mmap);
84631- flush_dcache_mmap_unlock(mapping);
84632- mutex_unlock(&mapping->i_mmap_mutex);
84633+ tmp = dup_vma(mm, oldmm, mpnt);
84634+ if (!tmp) {
84635+ retval = -ENOMEM;
84636+ goto out;
84637 }
84638
84639 /*
84640@@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84641 if (retval)
84642 goto out;
84643 }
84644+
84645+#ifdef CONFIG_PAX_SEGMEXEC
84646+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
84647+ struct vm_area_struct *mpnt_m;
84648+
84649+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
84650+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
84651+
84652+ if (!mpnt->vm_mirror)
84653+ continue;
84654+
84655+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
84656+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
84657+ mpnt->vm_mirror = mpnt_m;
84658+ } else {
84659+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
84660+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
84661+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
84662+ mpnt->vm_mirror->vm_mirror = mpnt;
84663+ }
84664+ }
84665+ BUG_ON(mpnt_m);
84666+ }
84667+#endif
84668+
84669 /* a new mm has just been created */
84670 arch_dup_mmap(oldmm, mm);
84671 retval = 0;
84672@@ -468,14 +521,6 @@ out:
84673 up_write(&oldmm->mmap_sem);
84674 uprobe_end_dup_mmap();
84675 return retval;
84676-fail_nomem_anon_vma_fork:
84677- mpol_put(vma_policy(tmp));
84678-fail_nomem_policy:
84679- kmem_cache_free(vm_area_cachep, tmp);
84680-fail_nomem:
84681- retval = -ENOMEM;
84682- vm_unacct_memory(charge);
84683- goto out;
84684 }
84685
84686 static inline int mm_alloc_pgd(struct mm_struct *mm)
84687@@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
84688 return ERR_PTR(err);
84689
84690 mm = get_task_mm(task);
84691- if (mm && mm != current->mm &&
84692- !ptrace_may_access(task, mode)) {
84693+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
84694+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
84695 mmput(mm);
84696 mm = ERR_PTR(-EACCES);
84697 }
84698@@ -909,13 +954,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
84699 spin_unlock(&fs->lock);
84700 return -EAGAIN;
84701 }
84702- fs->users++;
84703+ atomic_inc(&fs->users);
84704 spin_unlock(&fs->lock);
84705 return 0;
84706 }
84707 tsk->fs = copy_fs_struct(fs);
84708 if (!tsk->fs)
84709 return -ENOMEM;
84710+ /* Carry through gr_chroot_dentry and is_chrooted instead
84711+ of recomputing it here. Already copied when the task struct
84712+ is duplicated. This allows pivot_root to not be treated as
84713+ a chroot
84714+ */
84715+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
84716+
84717 return 0;
84718 }
84719
84720@@ -1126,7 +1178,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
84721 * parts of the process environment (as per the clone
84722 * flags). The actual kick-off is left to the caller.
84723 */
84724-static struct task_struct *copy_process(unsigned long clone_flags,
84725+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
84726 unsigned long stack_start,
84727 unsigned long stack_size,
84728 int __user *child_tidptr,
84729@@ -1198,6 +1250,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
84730 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
84731 #endif
84732 retval = -EAGAIN;
84733+
84734+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
84735+
84736 if (atomic_read(&p->real_cred->user->processes) >=
84737 task_rlimit(p, RLIMIT_NPROC)) {
84738 if (p->real_cred->user != INIT_USER &&
84739@@ -1446,6 +1501,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
84740 goto bad_fork_free_pid;
84741 }
84742
84743+ /* synchronizes with gr_set_acls()
84744+ we need to call this past the point of no return for fork()
84745+ */
84746+ gr_copy_label(p);
84747+
84748 if (likely(p->pid)) {
84749 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
84750
84751@@ -1532,6 +1592,8 @@ bad_fork_cleanup_count:
84752 bad_fork_free:
84753 free_task(p);
84754 fork_out:
84755+ gr_log_forkfail(retval);
84756+
84757 return ERR_PTR(retval);
84758 }
84759
84760@@ -1593,6 +1655,7 @@ long do_fork(unsigned long clone_flags,
84761
84762 p = copy_process(clone_flags, stack_start, stack_size,
84763 child_tidptr, NULL, trace);
84764+ add_latent_entropy();
84765 /*
84766 * Do this prior waking up the new thread - the thread pointer
84767 * might get invalid after that point, if the thread exits quickly.
84768@@ -1607,6 +1670,8 @@ long do_fork(unsigned long clone_flags,
84769 if (clone_flags & CLONE_PARENT_SETTID)
84770 put_user(nr, parent_tidptr);
84771
84772+ gr_handle_brute_check();
84773+
84774 if (clone_flags & CLONE_VFORK) {
84775 p->vfork_done = &vfork;
84776 init_completion(&vfork);
84777@@ -1723,7 +1788,7 @@ void __init proc_caches_init(void)
84778 mm_cachep = kmem_cache_create("mm_struct",
84779 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
84780 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
84781- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
84782+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
84783 mmap_init();
84784 nsproxy_cache_init();
84785 }
84786@@ -1763,7 +1828,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
84787 return 0;
84788
84789 /* don't need lock here; in the worst case we'll do useless copy */
84790- if (fs->users == 1)
84791+ if (atomic_read(&fs->users) == 1)
84792 return 0;
84793
84794 *new_fsp = copy_fs_struct(fs);
84795@@ -1870,7 +1935,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
84796 fs = current->fs;
84797 spin_lock(&fs->lock);
84798 current->fs = new_fs;
84799- if (--fs->users)
84800+ gr_set_chroot_entries(current, &current->fs->root);
84801+ if (atomic_dec_return(&fs->users))
84802 new_fs = NULL;
84803 else
84804 new_fs = fs;
84805diff --git a/kernel/futex.c b/kernel/futex.c
84806index f6ff019..ac53307 100644
84807--- a/kernel/futex.c
84808+++ b/kernel/futex.c
84809@@ -54,6 +54,7 @@
84810 #include <linux/mount.h>
84811 #include <linux/pagemap.h>
84812 #include <linux/syscalls.h>
84813+#include <linux/ptrace.h>
84814 #include <linux/signal.h>
84815 #include <linux/export.h>
84816 #include <linux/magic.h>
84817@@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
84818 struct page *page, *page_head;
84819 int err, ro = 0;
84820
84821+#ifdef CONFIG_PAX_SEGMEXEC
84822+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
84823+ return -EFAULT;
84824+#endif
84825+
84826 /*
84827 * The futex address must be "naturally" aligned.
84828 */
84829@@ -442,7 +448,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
84830
84831 static int get_futex_value_locked(u32 *dest, u32 __user *from)
84832 {
84833- int ret;
84834+ unsigned long ret;
84835
84836 pagefault_disable();
84837 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
84838@@ -2735,6 +2741,7 @@ static int __init futex_init(void)
84839 {
84840 u32 curval;
84841 int i;
84842+ mm_segment_t oldfs;
84843
84844 /*
84845 * This will fail and we want it. Some arch implementations do
84846@@ -2746,8 +2753,11 @@ static int __init futex_init(void)
84847 * implementation, the non-functional ones will return
84848 * -ENOSYS.
84849 */
84850+ oldfs = get_fs();
84851+ set_fs(USER_DS);
84852 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
84853 futex_cmpxchg_enabled = 1;
84854+ set_fs(oldfs);
84855
84856 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
84857 plist_head_init(&futex_queues[i].chain);
84858diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
84859index f9f44fd..29885e4 100644
84860--- a/kernel/futex_compat.c
84861+++ b/kernel/futex_compat.c
84862@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
84863 return 0;
84864 }
84865
84866-static void __user *futex_uaddr(struct robust_list __user *entry,
84867+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
84868 compat_long_t futex_offset)
84869 {
84870 compat_uptr_t base = ptr_to_compat(entry);
84871diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
84872index f45b75b..bfac6d5 100644
84873--- a/kernel/gcov/base.c
84874+++ b/kernel/gcov/base.c
84875@@ -108,11 +108,6 @@ void gcov_enable_events(void)
84876 }
84877
84878 #ifdef CONFIG_MODULES
84879-static inline int within(void *addr, void *start, unsigned long size)
84880-{
84881- return ((addr >= start) && (addr < start + size));
84882-}
84883-
84884 /* Update list and generate events when modules are unloaded. */
84885 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
84886 void *data)
84887@@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
84888
84889 /* Remove entries located in module from linked list. */
84890 while ((info = gcov_info_next(info))) {
84891- if (within(info, mod->module_core, mod->core_size)) {
84892+ if (within_module_core_rw((unsigned long)info, mod)) {
84893 gcov_info_unlink(prev, info);
84894 if (gcov_events_enabled)
84895 gcov_event(GCOV_REMOVE, info);
84896diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
84897index 383319b..56ebb13 100644
84898--- a/kernel/hrtimer.c
84899+++ b/kernel/hrtimer.c
84900@@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
84901 local_irq_restore(flags);
84902 }
84903
84904-static void run_hrtimer_softirq(struct softirq_action *h)
84905+static __latent_entropy void run_hrtimer_softirq(void)
84906 {
84907 hrtimer_peek_ahead_timers();
84908 }
84909diff --git a/kernel/irq_work.c b/kernel/irq_work.c
84910index 55fcce6..0e4cf34 100644
84911--- a/kernel/irq_work.c
84912+++ b/kernel/irq_work.c
84913@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
84914 return NOTIFY_OK;
84915 }
84916
84917-static struct notifier_block cpu_notify;
84918+static struct notifier_block cpu_notify = {
84919+ .notifier_call = irq_work_cpu_notify,
84920+ .priority = 0,
84921+};
84922
84923 static __init int irq_work_init_cpu_notifier(void)
84924 {
84925- cpu_notify.notifier_call = irq_work_cpu_notify;
84926- cpu_notify.priority = 0;
84927 register_cpu_notifier(&cpu_notify);
84928 return 0;
84929 }
84930diff --git a/kernel/jump_label.c b/kernel/jump_label.c
84931index 9019f15..9a3c42e 100644
84932--- a/kernel/jump_label.c
84933+++ b/kernel/jump_label.c
84934@@ -14,6 +14,7 @@
84935 #include <linux/err.h>
84936 #include <linux/static_key.h>
84937 #include <linux/jump_label_ratelimit.h>
84938+#include <linux/mm.h>
84939
84940 #ifdef HAVE_JUMP_LABEL
84941
84942@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
84943
84944 size = (((unsigned long)stop - (unsigned long)start)
84945 / sizeof(struct jump_entry));
84946+ pax_open_kernel();
84947 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
84948+ pax_close_kernel();
84949 }
84950
84951 static void jump_label_update(struct static_key *key, int enable);
84952@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
84953 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
84954 struct jump_entry *iter;
84955
84956+ pax_open_kernel();
84957 for (iter = iter_start; iter < iter_stop; iter++) {
84958 if (within_module_init(iter->code, mod))
84959 iter->code = 0;
84960 }
84961+ pax_close_kernel();
84962 }
84963
84964 static int
84965diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
84966index 3127ad5..159d880 100644
84967--- a/kernel/kallsyms.c
84968+++ b/kernel/kallsyms.c
84969@@ -11,6 +11,9 @@
84970 * Changed the compression method from stem compression to "table lookup"
84971 * compression (see scripts/kallsyms.c for a more complete description)
84972 */
84973+#ifdef CONFIG_GRKERNSEC_HIDESYM
84974+#define __INCLUDED_BY_HIDESYM 1
84975+#endif
84976 #include <linux/kallsyms.h>
84977 #include <linux/module.h>
84978 #include <linux/init.h>
84979@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
84980
84981 static inline int is_kernel_inittext(unsigned long addr)
84982 {
84983+ if (system_state != SYSTEM_BOOTING)
84984+ return 0;
84985+
84986 if (addr >= (unsigned long)_sinittext
84987 && addr <= (unsigned long)_einittext)
84988 return 1;
84989 return 0;
84990 }
84991
84992+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84993+#ifdef CONFIG_MODULES
84994+static inline int is_module_text(unsigned long addr)
84995+{
84996+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
84997+ return 1;
84998+
84999+ addr = ktla_ktva(addr);
85000+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
85001+}
85002+#else
85003+static inline int is_module_text(unsigned long addr)
85004+{
85005+ return 0;
85006+}
85007+#endif
85008+#endif
85009+
85010 static inline int is_kernel_text(unsigned long addr)
85011 {
85012 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
85013@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
85014
85015 static inline int is_kernel(unsigned long addr)
85016 {
85017+
85018+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85019+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
85020+ return 1;
85021+
85022+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
85023+#else
85024 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
85025+#endif
85026+
85027 return 1;
85028 return in_gate_area_no_mm(addr);
85029 }
85030
85031 static int is_ksym_addr(unsigned long addr)
85032 {
85033+
85034+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85035+ if (is_module_text(addr))
85036+ return 0;
85037+#endif
85038+
85039 if (all_var)
85040 return is_kernel(addr);
85041
85042@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
85043
85044 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
85045 {
85046- iter->name[0] = '\0';
85047 iter->nameoff = get_symbol_offset(new_pos);
85048 iter->pos = new_pos;
85049 }
85050@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
85051 {
85052 struct kallsym_iter *iter = m->private;
85053
85054+#ifdef CONFIG_GRKERNSEC_HIDESYM
85055+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
85056+ return 0;
85057+#endif
85058+
85059 /* Some debugging symbols have no name. Ignore them. */
85060 if (!iter->name[0])
85061 return 0;
85062@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
85063 */
85064 type = iter->exported ? toupper(iter->type) :
85065 tolower(iter->type);
85066+
85067 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
85068 type, iter->name, iter->module_name);
85069 } else
85070@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
85071 struct kallsym_iter *iter;
85072 int ret;
85073
85074- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
85075+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
85076 if (!iter)
85077 return -ENOMEM;
85078 reset_iter(iter, 0);
85079diff --git a/kernel/kcmp.c b/kernel/kcmp.c
85080index e30ac0f..3528cac 100644
85081--- a/kernel/kcmp.c
85082+++ b/kernel/kcmp.c
85083@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
85084 struct task_struct *task1, *task2;
85085 int ret;
85086
85087+#ifdef CONFIG_GRKERNSEC
85088+ return -ENOSYS;
85089+#endif
85090+
85091 rcu_read_lock();
85092
85093 /*
85094diff --git a/kernel/kexec.c b/kernel/kexec.c
85095index 9c97016..df438f8 100644
85096--- a/kernel/kexec.c
85097+++ b/kernel/kexec.c
85098@@ -1044,7 +1044,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
85099 unsigned long flags)
85100 {
85101 struct compat_kexec_segment in;
85102- struct kexec_segment out, __user *ksegments;
85103+ struct kexec_segment out;
85104+ struct kexec_segment __user *ksegments;
85105 unsigned long i, result;
85106
85107 /* Don't allow clients that don't understand the native
85108diff --git a/kernel/kmod.c b/kernel/kmod.c
85109index b086006..655e2aa 100644
85110--- a/kernel/kmod.c
85111+++ b/kernel/kmod.c
85112@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
85113 kfree(info->argv);
85114 }
85115
85116-static int call_modprobe(char *module_name, int wait)
85117+static int call_modprobe(char *module_name, char *module_param, int wait)
85118 {
85119 struct subprocess_info *info;
85120 static char *envp[] = {
85121@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
85122 NULL
85123 };
85124
85125- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
85126+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
85127 if (!argv)
85128 goto out;
85129
85130@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
85131 argv[1] = "-q";
85132 argv[2] = "--";
85133 argv[3] = module_name; /* check free_modprobe_argv() */
85134- argv[4] = NULL;
85135+ argv[4] = module_param;
85136+ argv[5] = NULL;
85137
85138 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
85139 NULL, free_modprobe_argv, NULL);
85140@@ -129,9 +130,8 @@ out:
85141 * If module auto-loading support is disabled then this function
85142 * becomes a no-operation.
85143 */
85144-int __request_module(bool wait, const char *fmt, ...)
85145+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
85146 {
85147- va_list args;
85148 char module_name[MODULE_NAME_LEN];
85149 unsigned int max_modprobes;
85150 int ret;
85151@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
85152 if (!modprobe_path[0])
85153 return 0;
85154
85155- va_start(args, fmt);
85156- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
85157- va_end(args);
85158+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
85159 if (ret >= MODULE_NAME_LEN)
85160 return -ENAMETOOLONG;
85161
85162@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
85163 if (ret)
85164 return ret;
85165
85166+#ifdef CONFIG_GRKERNSEC_MODHARDEN
85167+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
85168+ /* hack to workaround consolekit/udisks stupidity */
85169+ read_lock(&tasklist_lock);
85170+ if (!strcmp(current->comm, "mount") &&
85171+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
85172+ read_unlock(&tasklist_lock);
85173+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
85174+ return -EPERM;
85175+ }
85176+ read_unlock(&tasklist_lock);
85177+ }
85178+#endif
85179+
85180 /* If modprobe needs a service that is in a module, we get a recursive
85181 * loop. Limit the number of running kmod threads to max_threads/2 or
85182 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
85183@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
85184
85185 trace_module_request(module_name, wait, _RET_IP_);
85186
85187- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
85188+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
85189
85190 atomic_dec(&kmod_concurrent);
85191 return ret;
85192 }
85193+
85194+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
85195+{
85196+ va_list args;
85197+ int ret;
85198+
85199+ va_start(args, fmt);
85200+ ret = ____request_module(wait, module_param, fmt, args);
85201+ va_end(args);
85202+
85203+ return ret;
85204+}
85205+
85206+int __request_module(bool wait, const char *fmt, ...)
85207+{
85208+ va_list args;
85209+ int ret;
85210+
85211+#ifdef CONFIG_GRKERNSEC_MODHARDEN
85212+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
85213+ char module_param[MODULE_NAME_LEN];
85214+
85215+ memset(module_param, 0, sizeof(module_param));
85216+
85217+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
85218+
85219+ va_start(args, fmt);
85220+ ret = ____request_module(wait, module_param, fmt, args);
85221+ va_end(args);
85222+
85223+ return ret;
85224+ }
85225+#endif
85226+
85227+ va_start(args, fmt);
85228+ ret = ____request_module(wait, NULL, fmt, args);
85229+ va_end(args);
85230+
85231+ return ret;
85232+}
85233+
85234 EXPORT_SYMBOL(__request_module);
85235 #endif /* CONFIG_MODULES */
85236
85237@@ -218,6 +271,19 @@ static int ____call_usermodehelper(void *data)
85238 */
85239 set_user_nice(current, 0);
85240
85241+#ifdef CONFIG_GRKERNSEC
85242+ /* this is race-free as far as userland is concerned as we copied
85243+ out the path to be used prior to this point and are now operating
85244+ on that copy
85245+ */
85246+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
85247+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7)) || strstr(sub_info->path, "..")) {
85248+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
85249+ retval = -EPERM;
85250+ goto fail;
85251+ }
85252+#endif
85253+
85254 retval = -ENOMEM;
85255 new = prepare_kernel_cred(current);
85256 if (!new)
85257@@ -240,8 +306,8 @@ static int ____call_usermodehelper(void *data)
85258 commit_creds(new);
85259
85260 retval = do_execve(sub_info->path,
85261- (const char __user *const __user *)sub_info->argv,
85262- (const char __user *const __user *)sub_info->envp);
85263+ (const char __user *const __force_user *)sub_info->argv,
85264+ (const char __user *const __force_user *)sub_info->envp);
85265 if (!retval)
85266 return 0;
85267
85268@@ -260,6 +326,10 @@ static int call_helper(void *data)
85269
85270 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
85271 {
85272+#ifdef CONFIG_GRKERNSEC
85273+ kfree(info->path);
85274+ info->path = info->origpath;
85275+#endif
85276 if (info->cleanup)
85277 (*info->cleanup)(info);
85278 kfree(info);
85279@@ -303,7 +373,7 @@ static int wait_for_helper(void *data)
85280 *
85281 * Thus the __user pointer cast is valid here.
85282 */
85283- sys_wait4(pid, (int __user *)&ret, 0, NULL);
85284+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
85285
85286 /*
85287 * If ret is 0, either ____call_usermodehelper failed and the
85288@@ -542,7 +612,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
85289 goto out;
85290
85291 INIT_WORK(&sub_info->work, __call_usermodehelper);
85292+#ifdef CONFIG_GRKERNSEC
85293+ sub_info->origpath = path;
85294+ sub_info->path = kstrdup(path, gfp_mask);
85295+#else
85296 sub_info->path = path;
85297+#endif
85298 sub_info->argv = argv;
85299 sub_info->envp = envp;
85300
85301@@ -650,7 +725,7 @@ EXPORT_SYMBOL(call_usermodehelper);
85302 static int proc_cap_handler(struct ctl_table *table, int write,
85303 void __user *buffer, size_t *lenp, loff_t *ppos)
85304 {
85305- struct ctl_table t;
85306+ ctl_table_no_const t;
85307 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
85308 kernel_cap_t new_cap;
85309 int err, i;
85310diff --git a/kernel/kprobes.c b/kernel/kprobes.c
85311index ceeadfc..11c18b6 100644
85312--- a/kernel/kprobes.c
85313+++ b/kernel/kprobes.c
85314@@ -31,6 +31,9 @@
85315 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
85316 * <prasanna@in.ibm.com> added function-return probes.
85317 */
85318+#ifdef CONFIG_GRKERNSEC_HIDESYM
85319+#define __INCLUDED_BY_HIDESYM 1
85320+#endif
85321 #include <linux/kprobes.h>
85322 #include <linux/hash.h>
85323 #include <linux/init.h>
85324@@ -135,12 +138,12 @@ enum kprobe_slot_state {
85325
85326 static void *alloc_insn_page(void)
85327 {
85328- return module_alloc(PAGE_SIZE);
85329+ return module_alloc_exec(PAGE_SIZE);
85330 }
85331
85332 static void free_insn_page(void *page)
85333 {
85334- module_free(NULL, page);
85335+ module_free_exec(NULL, page);
85336 }
85337
85338 struct kprobe_insn_cache kprobe_insn_slots = {
85339@@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
85340 kprobe_type = "k";
85341
85342 if (sym)
85343- seq_printf(pi, "%p %s %s+0x%x %s ",
85344+ seq_printf(pi, "%pK %s %s+0x%x %s ",
85345 p->addr, kprobe_type, sym, offset,
85346 (modname ? modname : " "));
85347 else
85348- seq_printf(pi, "%p %s %p ",
85349+ seq_printf(pi, "%pK %s %pK ",
85350 p->addr, kprobe_type, p->addr);
85351
85352 if (!pp)
85353diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
85354index 9659d38..bffd520 100644
85355--- a/kernel/ksysfs.c
85356+++ b/kernel/ksysfs.c
85357@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
85358 {
85359 if (count+1 > UEVENT_HELPER_PATH_LEN)
85360 return -ENOENT;
85361+ if (!capable(CAP_SYS_ADMIN))
85362+ return -EPERM;
85363 memcpy(uevent_helper, buf, count);
85364 uevent_helper[count] = '\0';
85365 if (count && uevent_helper[count-1] == '\n')
85366@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
85367 return count;
85368 }
85369
85370-static struct bin_attribute notes_attr = {
85371+static bin_attribute_no_const notes_attr __read_only = {
85372 .attr = {
85373 .name = "notes",
85374 .mode = S_IRUGO,
85375diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
85376index 576ba75..7c256e4 100644
85377--- a/kernel/locking/lockdep.c
85378+++ b/kernel/locking/lockdep.c
85379@@ -596,6 +596,10 @@ static int static_obj(void *obj)
85380 end = (unsigned long) &_end,
85381 addr = (unsigned long) obj;
85382
85383+#ifdef CONFIG_PAX_KERNEXEC
85384+ start = ktla_ktva(start);
85385+#endif
85386+
85387 /*
85388 * static variable?
85389 */
85390@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
85391 if (!static_obj(lock->key)) {
85392 debug_locks_off();
85393 printk("INFO: trying to register non-static key.\n");
85394+ printk("lock:%pS key:%pS.\n", lock, lock->key);
85395 printk("the code is fine but needs lockdep annotation.\n");
85396 printk("turning off the locking correctness validator.\n");
85397 dump_stack();
85398@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
85399 if (!class)
85400 return 0;
85401 }
85402- atomic_inc((atomic_t *)&class->ops);
85403+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
85404 if (very_verbose(class)) {
85405 printk("\nacquire class [%p] %s", class->key, class->name);
85406 if (class->name_version > 1)
85407diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
85408index ef43ac4..2720dfa 100644
85409--- a/kernel/locking/lockdep_proc.c
85410+++ b/kernel/locking/lockdep_proc.c
85411@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
85412 return 0;
85413 }
85414
85415- seq_printf(m, "%p", class->key);
85416+ seq_printf(m, "%pK", class->key);
85417 #ifdef CONFIG_DEBUG_LOCKDEP
85418 seq_printf(m, " OPS:%8ld", class->ops);
85419 #endif
85420@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
85421
85422 list_for_each_entry(entry, &class->locks_after, entry) {
85423 if (entry->distance == 1) {
85424- seq_printf(m, " -> [%p] ", entry->class->key);
85425+ seq_printf(m, " -> [%pK] ", entry->class->key);
85426 print_name(m, entry->class);
85427 seq_puts(m, "\n");
85428 }
85429@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
85430 if (!class->key)
85431 continue;
85432
85433- seq_printf(m, "[%p] ", class->key);
85434+ seq_printf(m, "[%pK] ", class->key);
85435 print_name(m, class);
85436 seq_puts(m, "\n");
85437 }
85438@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
85439 if (!i)
85440 seq_line(m, '-', 40-namelen, namelen);
85441
85442- snprintf(ip, sizeof(ip), "[<%p>]",
85443+ snprintf(ip, sizeof(ip), "[<%pK>]",
85444 (void *)class->contention_point[i]);
85445 seq_printf(m, "%40s %14lu %29s %pS\n",
85446 name, stats->contention_point[i],
85447@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
85448 if (!i)
85449 seq_line(m, '-', 40-namelen, namelen);
85450
85451- snprintf(ip, sizeof(ip), "[<%p>]",
85452+ snprintf(ip, sizeof(ip), "[<%pK>]",
85453 (void *)class->contending_point[i]);
85454 seq_printf(m, "%40s %14lu %29s %pS\n",
85455 name, stats->contending_point[i],
85456diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
85457index 7e3443f..b2a1e6b 100644
85458--- a/kernel/locking/mutex-debug.c
85459+++ b/kernel/locking/mutex-debug.c
85460@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
85461 }
85462
85463 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
85464- struct thread_info *ti)
85465+ struct task_struct *task)
85466 {
85467 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
85468
85469 /* Mark the current thread as blocked on the lock: */
85470- ti->task->blocked_on = waiter;
85471+ task->blocked_on = waiter;
85472 }
85473
85474 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
85475- struct thread_info *ti)
85476+ struct task_struct *task)
85477 {
85478 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
85479- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
85480- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
85481- ti->task->blocked_on = NULL;
85482+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
85483+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
85484+ task->blocked_on = NULL;
85485
85486 list_del_init(&waiter->list);
85487 waiter->task = NULL;
85488diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
85489index 0799fd3..d06ae3b 100644
85490--- a/kernel/locking/mutex-debug.h
85491+++ b/kernel/locking/mutex-debug.h
85492@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
85493 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
85494 extern void debug_mutex_add_waiter(struct mutex *lock,
85495 struct mutex_waiter *waiter,
85496- struct thread_info *ti);
85497+ struct task_struct *task);
85498 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
85499- struct thread_info *ti);
85500+ struct task_struct *task);
85501 extern void debug_mutex_unlock(struct mutex *lock);
85502 extern void debug_mutex_init(struct mutex *lock, const char *name,
85503 struct lock_class_key *key);
85504diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
85505index 4dd6e4c..df52693 100644
85506--- a/kernel/locking/mutex.c
85507+++ b/kernel/locking/mutex.c
85508@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
85509 node->locked = 1;
85510 return;
85511 }
85512- ACCESS_ONCE(prev->next) = node;
85513+ ACCESS_ONCE_RW(prev->next) = node;
85514 smp_wmb();
85515 /* Wait until the lock holder passes the lock down */
85516 while (!ACCESS_ONCE(node->locked))
85517@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
85518 while (!(next = ACCESS_ONCE(node->next)))
85519 arch_mutex_cpu_relax();
85520 }
85521- ACCESS_ONCE(next->locked) = 1;
85522+ ACCESS_ONCE_RW(next->locked) = 1;
85523 smp_wmb();
85524 }
85525
85526@@ -520,7 +520,7 @@ slowpath:
85527 goto skip_wait;
85528
85529 debug_mutex_lock_common(lock, &waiter);
85530- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
85531+ debug_mutex_add_waiter(lock, &waiter, task);
85532
85533 /* add waiting tasks to the end of the waitqueue (FIFO): */
85534 list_add_tail(&waiter.list, &lock->wait_list);
85535@@ -564,7 +564,7 @@ slowpath:
85536 schedule_preempt_disabled();
85537 spin_lock_mutex(&lock->wait_lock, flags);
85538 }
85539- mutex_remove_waiter(lock, &waiter, current_thread_info());
85540+ mutex_remove_waiter(lock, &waiter, task);
85541 /* set it to 0 if there are no waiters left: */
85542 if (likely(list_empty(&lock->wait_list)))
85543 atomic_set(&lock->count, 0);
85544@@ -601,7 +601,7 @@ skip_wait:
85545 return 0;
85546
85547 err:
85548- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
85549+ mutex_remove_waiter(lock, &waiter, task);
85550 spin_unlock_mutex(&lock->wait_lock, flags);
85551 debug_mutex_free_waiter(&waiter);
85552 mutex_release(&lock->dep_map, 1, ip);
85553diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
85554index 1d96dd0..994ff19 100644
85555--- a/kernel/locking/rtmutex-tester.c
85556+++ b/kernel/locking/rtmutex-tester.c
85557@@ -22,7 +22,7 @@
85558 #define MAX_RT_TEST_MUTEXES 8
85559
85560 static spinlock_t rttest_lock;
85561-static atomic_t rttest_event;
85562+static atomic_unchecked_t rttest_event;
85563
85564 struct test_thread_data {
85565 int opcode;
85566@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85567
85568 case RTTEST_LOCKCONT:
85569 td->mutexes[td->opdata] = 1;
85570- td->event = atomic_add_return(1, &rttest_event);
85571+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85572 return 0;
85573
85574 case RTTEST_RESET:
85575@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85576 return 0;
85577
85578 case RTTEST_RESETEVENT:
85579- atomic_set(&rttest_event, 0);
85580+ atomic_set_unchecked(&rttest_event, 0);
85581 return 0;
85582
85583 default:
85584@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85585 return ret;
85586
85587 td->mutexes[id] = 1;
85588- td->event = atomic_add_return(1, &rttest_event);
85589+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85590 rt_mutex_lock(&mutexes[id]);
85591- td->event = atomic_add_return(1, &rttest_event);
85592+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85593 td->mutexes[id] = 4;
85594 return 0;
85595
85596@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85597 return ret;
85598
85599 td->mutexes[id] = 1;
85600- td->event = atomic_add_return(1, &rttest_event);
85601+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85602 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
85603- td->event = atomic_add_return(1, &rttest_event);
85604+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85605 td->mutexes[id] = ret ? 0 : 4;
85606 return ret ? -EINTR : 0;
85607
85608@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85609 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
85610 return ret;
85611
85612- td->event = atomic_add_return(1, &rttest_event);
85613+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85614 rt_mutex_unlock(&mutexes[id]);
85615- td->event = atomic_add_return(1, &rttest_event);
85616+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85617 td->mutexes[id] = 0;
85618 return 0;
85619
85620@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85621 break;
85622
85623 td->mutexes[dat] = 2;
85624- td->event = atomic_add_return(1, &rttest_event);
85625+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85626 break;
85627
85628 default:
85629@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85630 return;
85631
85632 td->mutexes[dat] = 3;
85633- td->event = atomic_add_return(1, &rttest_event);
85634+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85635 break;
85636
85637 case RTTEST_LOCKNOWAIT:
85638@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85639 return;
85640
85641 td->mutexes[dat] = 1;
85642- td->event = atomic_add_return(1, &rttest_event);
85643+ td->event = atomic_add_return_unchecked(1, &rttest_event);
85644 return;
85645
85646 default:
85647diff --git a/kernel/module.c b/kernel/module.c
85648index f5a3b1e..97ebb15 100644
85649--- a/kernel/module.c
85650+++ b/kernel/module.c
85651@@ -61,6 +61,7 @@
85652 #include <linux/pfn.h>
85653 #include <linux/bsearch.h>
85654 #include <linux/fips.h>
85655+#include <linux/grsecurity.h>
85656 #include <uapi/linux/module.h>
85657 #include "module-internal.h"
85658
85659@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
85660
85661 /* Bounds of module allocation, for speeding __module_address.
85662 * Protected by module_mutex. */
85663-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
85664+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
85665+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
85666
85667 int register_module_notifier(struct notifier_block * nb)
85668 {
85669@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
85670 return true;
85671
85672 list_for_each_entry_rcu(mod, &modules, list) {
85673- struct symsearch arr[] = {
85674+ struct symsearch modarr[] = {
85675 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
85676 NOT_GPL_ONLY, false },
85677 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
85678@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
85679 if (mod->state == MODULE_STATE_UNFORMED)
85680 continue;
85681
85682- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
85683+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
85684 return true;
85685 }
85686 return false;
85687@@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
85688 if (!pcpusec->sh_size)
85689 return 0;
85690
85691- if (align > PAGE_SIZE) {
85692+ if (align-1 >= PAGE_SIZE) {
85693 pr_warn("%s: per-cpu alignment %li > %li\n",
85694 mod->name, align, PAGE_SIZE);
85695 align = PAGE_SIZE;
85696@@ -1064,7 +1066,7 @@ struct module_attribute module_uevent =
85697 static ssize_t show_coresize(struct module_attribute *mattr,
85698 struct module_kobject *mk, char *buffer)
85699 {
85700- return sprintf(buffer, "%u\n", mk->mod->core_size);
85701+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
85702 }
85703
85704 static struct module_attribute modinfo_coresize =
85705@@ -1073,7 +1075,7 @@ static struct module_attribute modinfo_coresize =
85706 static ssize_t show_initsize(struct module_attribute *mattr,
85707 struct module_kobject *mk, char *buffer)
85708 {
85709- return sprintf(buffer, "%u\n", mk->mod->init_size);
85710+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
85711 }
85712
85713 static struct module_attribute modinfo_initsize =
85714@@ -1165,12 +1167,29 @@ static int check_version(Elf_Shdr *sechdrs,
85715 goto bad_version;
85716 }
85717
85718+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
85719+ /*
85720+ * avoid potentially printing jibberish on attempted load
85721+ * of a module randomized with a different seed
85722+ */
85723+ pr_warn("no symbol version for %s\n", symname);
85724+#else
85725 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
85726+#endif
85727 return 0;
85728
85729 bad_version:
85730+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
85731+ /*
85732+ * avoid potentially printing jibberish on attempted load
85733+ * of a module randomized with a different seed
85734+ */
85735+ printk("attempted module disagrees about version of symbol %s\n",
85736+ symname);
85737+#else
85738 printk("%s: disagrees about version of symbol %s\n",
85739 mod->name, symname);
85740+#endif
85741 return 0;
85742 }
85743
85744@@ -1286,7 +1305,7 @@ resolve_symbol_wait(struct module *mod,
85745 */
85746 #ifdef CONFIG_SYSFS
85747
85748-#ifdef CONFIG_KALLSYMS
85749+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
85750 static inline bool sect_empty(const Elf_Shdr *sect)
85751 {
85752 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
85753@@ -1426,7 +1445,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
85754 {
85755 unsigned int notes, loaded, i;
85756 struct module_notes_attrs *notes_attrs;
85757- struct bin_attribute *nattr;
85758+ bin_attribute_no_const *nattr;
85759
85760 /* failed to create section attributes, so can't create notes */
85761 if (!mod->sect_attrs)
85762@@ -1538,7 +1557,7 @@ static void del_usage_links(struct module *mod)
85763 static int module_add_modinfo_attrs(struct module *mod)
85764 {
85765 struct module_attribute *attr;
85766- struct module_attribute *temp_attr;
85767+ module_attribute_no_const *temp_attr;
85768 int error = 0;
85769 int i;
85770
85771@@ -1759,21 +1778,21 @@ static void set_section_ro_nx(void *base,
85772
85773 static void unset_module_core_ro_nx(struct module *mod)
85774 {
85775- set_page_attributes(mod->module_core + mod->core_text_size,
85776- mod->module_core + mod->core_size,
85777+ set_page_attributes(mod->module_core_rw,
85778+ mod->module_core_rw + mod->core_size_rw,
85779 set_memory_x);
85780- set_page_attributes(mod->module_core,
85781- mod->module_core + mod->core_ro_size,
85782+ set_page_attributes(mod->module_core_rx,
85783+ mod->module_core_rx + mod->core_size_rx,
85784 set_memory_rw);
85785 }
85786
85787 static void unset_module_init_ro_nx(struct module *mod)
85788 {
85789- set_page_attributes(mod->module_init + mod->init_text_size,
85790- mod->module_init + mod->init_size,
85791+ set_page_attributes(mod->module_init_rw,
85792+ mod->module_init_rw + mod->init_size_rw,
85793 set_memory_x);
85794- set_page_attributes(mod->module_init,
85795- mod->module_init + mod->init_ro_size,
85796+ set_page_attributes(mod->module_init_rx,
85797+ mod->module_init_rx + mod->init_size_rx,
85798 set_memory_rw);
85799 }
85800
85801@@ -1786,14 +1805,14 @@ void set_all_modules_text_rw(void)
85802 list_for_each_entry_rcu(mod, &modules, list) {
85803 if (mod->state == MODULE_STATE_UNFORMED)
85804 continue;
85805- if ((mod->module_core) && (mod->core_text_size)) {
85806- set_page_attributes(mod->module_core,
85807- mod->module_core + mod->core_text_size,
85808+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
85809+ set_page_attributes(mod->module_core_rx,
85810+ mod->module_core_rx + mod->core_size_rx,
85811 set_memory_rw);
85812 }
85813- if ((mod->module_init) && (mod->init_text_size)) {
85814- set_page_attributes(mod->module_init,
85815- mod->module_init + mod->init_text_size,
85816+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
85817+ set_page_attributes(mod->module_init_rx,
85818+ mod->module_init_rx + mod->init_size_rx,
85819 set_memory_rw);
85820 }
85821 }
85822@@ -1809,14 +1828,14 @@ void set_all_modules_text_ro(void)
85823 list_for_each_entry_rcu(mod, &modules, list) {
85824 if (mod->state == MODULE_STATE_UNFORMED)
85825 continue;
85826- if ((mod->module_core) && (mod->core_text_size)) {
85827- set_page_attributes(mod->module_core,
85828- mod->module_core + mod->core_text_size,
85829+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
85830+ set_page_attributes(mod->module_core_rx,
85831+ mod->module_core_rx + mod->core_size_rx,
85832 set_memory_ro);
85833 }
85834- if ((mod->module_init) && (mod->init_text_size)) {
85835- set_page_attributes(mod->module_init,
85836- mod->module_init + mod->init_text_size,
85837+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
85838+ set_page_attributes(mod->module_init_rx,
85839+ mod->module_init_rx + mod->init_size_rx,
85840 set_memory_ro);
85841 }
85842 }
85843@@ -1867,16 +1886,19 @@ static void free_module(struct module *mod)
85844
85845 /* This may be NULL, but that's OK */
85846 unset_module_init_ro_nx(mod);
85847- module_free(mod, mod->module_init);
85848+ module_free(mod, mod->module_init_rw);
85849+ module_free_exec(mod, mod->module_init_rx);
85850 kfree(mod->args);
85851 percpu_modfree(mod);
85852
85853 /* Free lock-classes: */
85854- lockdep_free_key_range(mod->module_core, mod->core_size);
85855+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
85856+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
85857
85858 /* Finally, free the core (containing the module structure) */
85859 unset_module_core_ro_nx(mod);
85860- module_free(mod, mod->module_core);
85861+ module_free_exec(mod, mod->module_core_rx);
85862+ module_free(mod, mod->module_core_rw);
85863
85864 #ifdef CONFIG_MPU
85865 update_protections(current->mm);
85866@@ -1945,9 +1967,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
85867 int ret = 0;
85868 const struct kernel_symbol *ksym;
85869
85870+#ifdef CONFIG_GRKERNSEC_MODHARDEN
85871+ int is_fs_load = 0;
85872+ int register_filesystem_found = 0;
85873+ char *p;
85874+
85875+ p = strstr(mod->args, "grsec_modharden_fs");
85876+ if (p) {
85877+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
85878+ /* copy \0 as well */
85879+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
85880+ is_fs_load = 1;
85881+ }
85882+#endif
85883+
85884 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
85885 const char *name = info->strtab + sym[i].st_name;
85886
85887+#ifdef CONFIG_GRKERNSEC_MODHARDEN
85888+ /* it's a real shame this will never get ripped and copied
85889+ upstream! ;(
85890+ */
85891+ if (is_fs_load && !strcmp(name, "register_filesystem"))
85892+ register_filesystem_found = 1;
85893+#endif
85894+
85895 switch (sym[i].st_shndx) {
85896 case SHN_COMMON:
85897 /* We compiled with -fno-common. These are not
85898@@ -1968,7 +2012,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
85899 ksym = resolve_symbol_wait(mod, info, name);
85900 /* Ok if resolved. */
85901 if (ksym && !IS_ERR(ksym)) {
85902+ pax_open_kernel();
85903 sym[i].st_value = ksym->value;
85904+ pax_close_kernel();
85905 break;
85906 }
85907
85908@@ -1987,11 +2033,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
85909 secbase = (unsigned long)mod_percpu(mod);
85910 else
85911 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
85912+ pax_open_kernel();
85913 sym[i].st_value += secbase;
85914+ pax_close_kernel();
85915 break;
85916 }
85917 }
85918
85919+#ifdef CONFIG_GRKERNSEC_MODHARDEN
85920+ if (is_fs_load && !register_filesystem_found) {
85921+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
85922+ ret = -EPERM;
85923+ }
85924+#endif
85925+
85926 return ret;
85927 }
85928
85929@@ -2075,22 +2130,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
85930 || s->sh_entsize != ~0UL
85931 || strstarts(sname, ".init"))
85932 continue;
85933- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
85934+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
85935+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
85936+ else
85937+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
85938 pr_debug("\t%s\n", sname);
85939 }
85940- switch (m) {
85941- case 0: /* executable */
85942- mod->core_size = debug_align(mod->core_size);
85943- mod->core_text_size = mod->core_size;
85944- break;
85945- case 1: /* RO: text and ro-data */
85946- mod->core_size = debug_align(mod->core_size);
85947- mod->core_ro_size = mod->core_size;
85948- break;
85949- case 3: /* whole core */
85950- mod->core_size = debug_align(mod->core_size);
85951- break;
85952- }
85953 }
85954
85955 pr_debug("Init section allocation order:\n");
85956@@ -2104,23 +2149,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
85957 || s->sh_entsize != ~0UL
85958 || !strstarts(sname, ".init"))
85959 continue;
85960- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
85961- | INIT_OFFSET_MASK);
85962+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
85963+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
85964+ else
85965+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
85966+ s->sh_entsize |= INIT_OFFSET_MASK;
85967 pr_debug("\t%s\n", sname);
85968 }
85969- switch (m) {
85970- case 0: /* executable */
85971- mod->init_size = debug_align(mod->init_size);
85972- mod->init_text_size = mod->init_size;
85973- break;
85974- case 1: /* RO: text and ro-data */
85975- mod->init_size = debug_align(mod->init_size);
85976- mod->init_ro_size = mod->init_size;
85977- break;
85978- case 3: /* whole init */
85979- mod->init_size = debug_align(mod->init_size);
85980- break;
85981- }
85982 }
85983 }
85984
85985@@ -2293,7 +2328,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
85986
85987 /* Put symbol section at end of init part of module. */
85988 symsect->sh_flags |= SHF_ALLOC;
85989- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
85990+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
85991 info->index.sym) | INIT_OFFSET_MASK;
85992 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
85993
85994@@ -2310,13 +2345,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
85995 }
85996
85997 /* Append room for core symbols at end of core part. */
85998- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
85999- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
86000- mod->core_size += strtab_size;
86001+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
86002+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
86003+ mod->core_size_rx += strtab_size;
86004
86005 /* Put string table section at end of init part of module. */
86006 strsect->sh_flags |= SHF_ALLOC;
86007- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
86008+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
86009 info->index.str) | INIT_OFFSET_MASK;
86010 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
86011 }
86012@@ -2334,12 +2369,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
86013 /* Make sure we get permanent strtab: don't use info->strtab. */
86014 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
86015
86016+ pax_open_kernel();
86017+
86018 /* Set types up while we still have access to sections. */
86019 for (i = 0; i < mod->num_symtab; i++)
86020 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
86021
86022- mod->core_symtab = dst = mod->module_core + info->symoffs;
86023- mod->core_strtab = s = mod->module_core + info->stroffs;
86024+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
86025+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
86026 src = mod->symtab;
86027 for (ndst = i = 0; i < mod->num_symtab; i++) {
86028 if (i == 0 ||
86029@@ -2351,6 +2388,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
86030 }
86031 }
86032 mod->core_num_syms = ndst;
86033+
86034+ pax_close_kernel();
86035 }
86036 #else
86037 static inline void layout_symtab(struct module *mod, struct load_info *info)
86038@@ -2384,17 +2423,33 @@ void * __weak module_alloc(unsigned long size)
86039 return vmalloc_exec(size);
86040 }
86041
86042-static void *module_alloc_update_bounds(unsigned long size)
86043+static void *module_alloc_update_bounds_rw(unsigned long size)
86044 {
86045 void *ret = module_alloc(size);
86046
86047 if (ret) {
86048 mutex_lock(&module_mutex);
86049 /* Update module bounds. */
86050- if ((unsigned long)ret < module_addr_min)
86051- module_addr_min = (unsigned long)ret;
86052- if ((unsigned long)ret + size > module_addr_max)
86053- module_addr_max = (unsigned long)ret + size;
86054+ if ((unsigned long)ret < module_addr_min_rw)
86055+ module_addr_min_rw = (unsigned long)ret;
86056+ if ((unsigned long)ret + size > module_addr_max_rw)
86057+ module_addr_max_rw = (unsigned long)ret + size;
86058+ mutex_unlock(&module_mutex);
86059+ }
86060+ return ret;
86061+}
86062+
86063+static void *module_alloc_update_bounds_rx(unsigned long size)
86064+{
86065+ void *ret = module_alloc_exec(size);
86066+
86067+ if (ret) {
86068+ mutex_lock(&module_mutex);
86069+ /* Update module bounds. */
86070+ if ((unsigned long)ret < module_addr_min_rx)
86071+ module_addr_min_rx = (unsigned long)ret;
86072+ if ((unsigned long)ret + size > module_addr_max_rx)
86073+ module_addr_max_rx = (unsigned long)ret + size;
86074 mutex_unlock(&module_mutex);
86075 }
86076 return ret;
86077@@ -2651,7 +2706,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
86078 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
86079
86080 if (info->index.sym == 0) {
86081+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
86082+ /*
86083+ * avoid potentially printing jibberish on attempted load
86084+ * of a module randomized with a different seed
86085+ */
86086+ pr_warn("module has no symbols (stripped?)\n");
86087+#else
86088 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
86089+#endif
86090 return ERR_PTR(-ENOEXEC);
86091 }
86092
86093@@ -2667,8 +2730,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
86094 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
86095 {
86096 const char *modmagic = get_modinfo(info, "vermagic");
86097+ const char *license = get_modinfo(info, "license");
86098 int err;
86099
86100+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
86101+ if (!license || !license_is_gpl_compatible(license))
86102+ return -ENOEXEC;
86103+#endif
86104+
86105 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
86106 modmagic = NULL;
86107
86108@@ -2693,7 +2762,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
86109 }
86110
86111 /* Set up license info based on the info section */
86112- set_license(mod, get_modinfo(info, "license"));
86113+ set_license(mod, license);
86114
86115 return 0;
86116 }
86117@@ -2787,7 +2856,7 @@ static int move_module(struct module *mod, struct load_info *info)
86118 void *ptr;
86119
86120 /* Do the allocs. */
86121- ptr = module_alloc_update_bounds(mod->core_size);
86122+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
86123 /*
86124 * The pointer to this block is stored in the module structure
86125 * which is inside the block. Just mark it as not being a
86126@@ -2797,11 +2866,11 @@ static int move_module(struct module *mod, struct load_info *info)
86127 if (!ptr)
86128 return -ENOMEM;
86129
86130- memset(ptr, 0, mod->core_size);
86131- mod->module_core = ptr;
86132+ memset(ptr, 0, mod->core_size_rw);
86133+ mod->module_core_rw = ptr;
86134
86135- if (mod->init_size) {
86136- ptr = module_alloc_update_bounds(mod->init_size);
86137+ if (mod->init_size_rw) {
86138+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
86139 /*
86140 * The pointer to this block is stored in the module structure
86141 * which is inside the block. This block doesn't need to be
86142@@ -2810,13 +2879,45 @@ static int move_module(struct module *mod, struct load_info *info)
86143 */
86144 kmemleak_ignore(ptr);
86145 if (!ptr) {
86146- module_free(mod, mod->module_core);
86147+ module_free(mod, mod->module_core_rw);
86148 return -ENOMEM;
86149 }
86150- memset(ptr, 0, mod->init_size);
86151- mod->module_init = ptr;
86152+ memset(ptr, 0, mod->init_size_rw);
86153+ mod->module_init_rw = ptr;
86154 } else
86155- mod->module_init = NULL;
86156+ mod->module_init_rw = NULL;
86157+
86158+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
86159+ kmemleak_not_leak(ptr);
86160+ if (!ptr) {
86161+ if (mod->module_init_rw)
86162+ module_free(mod, mod->module_init_rw);
86163+ module_free(mod, mod->module_core_rw);
86164+ return -ENOMEM;
86165+ }
86166+
86167+ pax_open_kernel();
86168+ memset(ptr, 0, mod->core_size_rx);
86169+ pax_close_kernel();
86170+ mod->module_core_rx = ptr;
86171+
86172+ if (mod->init_size_rx) {
86173+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
86174+ kmemleak_ignore(ptr);
86175+ if (!ptr && mod->init_size_rx) {
86176+ module_free_exec(mod, mod->module_core_rx);
86177+ if (mod->module_init_rw)
86178+ module_free(mod, mod->module_init_rw);
86179+ module_free(mod, mod->module_core_rw);
86180+ return -ENOMEM;
86181+ }
86182+
86183+ pax_open_kernel();
86184+ memset(ptr, 0, mod->init_size_rx);
86185+ pax_close_kernel();
86186+ mod->module_init_rx = ptr;
86187+ } else
86188+ mod->module_init_rx = NULL;
86189
86190 /* Transfer each section which specifies SHF_ALLOC */
86191 pr_debug("final section addresses:\n");
86192@@ -2827,16 +2928,45 @@ static int move_module(struct module *mod, struct load_info *info)
86193 if (!(shdr->sh_flags & SHF_ALLOC))
86194 continue;
86195
86196- if (shdr->sh_entsize & INIT_OFFSET_MASK)
86197- dest = mod->module_init
86198- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
86199- else
86200- dest = mod->module_core + shdr->sh_entsize;
86201+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
86202+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
86203+ dest = mod->module_init_rw
86204+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
86205+ else
86206+ dest = mod->module_init_rx
86207+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
86208+ } else {
86209+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
86210+ dest = mod->module_core_rw + shdr->sh_entsize;
86211+ else
86212+ dest = mod->module_core_rx + shdr->sh_entsize;
86213+ }
86214+
86215+ if (shdr->sh_type != SHT_NOBITS) {
86216+
86217+#ifdef CONFIG_PAX_KERNEXEC
86218+#ifdef CONFIG_X86_64
86219+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
86220+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
86221+#endif
86222+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
86223+ pax_open_kernel();
86224+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
86225+ pax_close_kernel();
86226+ } else
86227+#endif
86228
86229- if (shdr->sh_type != SHT_NOBITS)
86230 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
86231+ }
86232 /* Update sh_addr to point to copy in image. */
86233- shdr->sh_addr = (unsigned long)dest;
86234+
86235+#ifdef CONFIG_PAX_KERNEXEC
86236+ if (shdr->sh_flags & SHF_EXECINSTR)
86237+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
86238+ else
86239+#endif
86240+
86241+ shdr->sh_addr = (unsigned long)dest;
86242 pr_debug("\t0x%lx %s\n",
86243 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
86244 }
86245@@ -2893,12 +3023,12 @@ static void flush_module_icache(const struct module *mod)
86246 * Do it before processing of module parameters, so the module
86247 * can provide parameter accessor functions of its own.
86248 */
86249- if (mod->module_init)
86250- flush_icache_range((unsigned long)mod->module_init,
86251- (unsigned long)mod->module_init
86252- + mod->init_size);
86253- flush_icache_range((unsigned long)mod->module_core,
86254- (unsigned long)mod->module_core + mod->core_size);
86255+ if (mod->module_init_rx)
86256+ flush_icache_range((unsigned long)mod->module_init_rx,
86257+ (unsigned long)mod->module_init_rx
86258+ + mod->init_size_rx);
86259+ flush_icache_range((unsigned long)mod->module_core_rx,
86260+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
86261
86262 set_fs(old_fs);
86263 }
86264@@ -2955,8 +3085,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
86265 static void module_deallocate(struct module *mod, struct load_info *info)
86266 {
86267 percpu_modfree(mod);
86268- module_free(mod, mod->module_init);
86269- module_free(mod, mod->module_core);
86270+ module_free_exec(mod, mod->module_init_rx);
86271+ module_free_exec(mod, mod->module_core_rx);
86272+ module_free(mod, mod->module_init_rw);
86273+ module_free(mod, mod->module_core_rw);
86274 }
86275
86276 int __weak module_finalize(const Elf_Ehdr *hdr,
86277@@ -2969,7 +3101,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
86278 static int post_relocation(struct module *mod, const struct load_info *info)
86279 {
86280 /* Sort exception table now relocations are done. */
86281+ pax_open_kernel();
86282 sort_extable(mod->extable, mod->extable + mod->num_exentries);
86283+ pax_close_kernel();
86284
86285 /* Copy relocated percpu area over. */
86286 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
86287@@ -3023,16 +3157,16 @@ static int do_init_module(struct module *mod)
86288 MODULE_STATE_COMING, mod);
86289
86290 /* Set RO and NX regions for core */
86291- set_section_ro_nx(mod->module_core,
86292- mod->core_text_size,
86293- mod->core_ro_size,
86294- mod->core_size);
86295+ set_section_ro_nx(mod->module_core_rx,
86296+ mod->core_size_rx,
86297+ mod->core_size_rx,
86298+ mod->core_size_rx);
86299
86300 /* Set RO and NX regions for init */
86301- set_section_ro_nx(mod->module_init,
86302- mod->init_text_size,
86303- mod->init_ro_size,
86304- mod->init_size);
86305+ set_section_ro_nx(mod->module_init_rx,
86306+ mod->init_size_rx,
86307+ mod->init_size_rx,
86308+ mod->init_size_rx);
86309
86310 do_mod_ctors(mod);
86311 /* Start the module */
86312@@ -3093,11 +3227,12 @@ static int do_init_module(struct module *mod)
86313 mod->strtab = mod->core_strtab;
86314 #endif
86315 unset_module_init_ro_nx(mod);
86316- module_free(mod, mod->module_init);
86317- mod->module_init = NULL;
86318- mod->init_size = 0;
86319- mod->init_ro_size = 0;
86320- mod->init_text_size = 0;
86321+ module_free(mod, mod->module_init_rw);
86322+ module_free_exec(mod, mod->module_init_rx);
86323+ mod->module_init_rw = NULL;
86324+ mod->module_init_rx = NULL;
86325+ mod->init_size_rw = 0;
86326+ mod->init_size_rx = 0;
86327 mutex_unlock(&module_mutex);
86328 wake_up_all(&module_wq);
86329
86330@@ -3240,9 +3375,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
86331 if (err)
86332 goto free_unload;
86333
86334+ /* Now copy in args */
86335+ mod->args = strndup_user(uargs, ~0UL >> 1);
86336+ if (IS_ERR(mod->args)) {
86337+ err = PTR_ERR(mod->args);
86338+ goto free_unload;
86339+ }
86340+
86341 /* Set up MODINFO_ATTR fields */
86342 setup_modinfo(mod, info);
86343
86344+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86345+ {
86346+ char *p, *p2;
86347+
86348+ if (strstr(mod->args, "grsec_modharden_netdev")) {
86349+ 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);
86350+ err = -EPERM;
86351+ goto free_modinfo;
86352+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
86353+ p += sizeof("grsec_modharden_normal") - 1;
86354+ p2 = strstr(p, "_");
86355+ if (p2) {
86356+ *p2 = '\0';
86357+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
86358+ *p2 = '_';
86359+ }
86360+ err = -EPERM;
86361+ goto free_modinfo;
86362+ }
86363+ }
86364+#endif
86365+
86366 /* Fix up syms, so that st_value is a pointer to location. */
86367 err = simplify_symbols(mod, info);
86368 if (err < 0)
86369@@ -3258,13 +3422,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
86370
86371 flush_module_icache(mod);
86372
86373- /* Now copy in args */
86374- mod->args = strndup_user(uargs, ~0UL >> 1);
86375- if (IS_ERR(mod->args)) {
86376- err = PTR_ERR(mod->args);
86377- goto free_arch_cleanup;
86378- }
86379-
86380 dynamic_debug_setup(info->debug, info->num_debug);
86381
86382 /* Finally it's fully formed, ready to start executing. */
86383@@ -3299,11 +3456,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
86384 ddebug_cleanup:
86385 dynamic_debug_remove(info->debug);
86386 synchronize_sched();
86387- kfree(mod->args);
86388- free_arch_cleanup:
86389 module_arch_cleanup(mod);
86390 free_modinfo:
86391 free_modinfo(mod);
86392+ kfree(mod->args);
86393 free_unload:
86394 module_unload_free(mod);
86395 unlink_mod:
86396@@ -3386,10 +3542,16 @@ static const char *get_ksymbol(struct module *mod,
86397 unsigned long nextval;
86398
86399 /* At worse, next value is at end of module */
86400- if (within_module_init(addr, mod))
86401- nextval = (unsigned long)mod->module_init+mod->init_text_size;
86402+ if (within_module_init_rx(addr, mod))
86403+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
86404+ else if (within_module_init_rw(addr, mod))
86405+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
86406+ else if (within_module_core_rx(addr, mod))
86407+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
86408+ else if (within_module_core_rw(addr, mod))
86409+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
86410 else
86411- nextval = (unsigned long)mod->module_core+mod->core_text_size;
86412+ return NULL;
86413
86414 /* Scan for closest preceding symbol, and next symbol. (ELF
86415 starts real symbols at 1). */
86416@@ -3640,7 +3802,7 @@ static int m_show(struct seq_file *m, void *p)
86417 return 0;
86418
86419 seq_printf(m, "%s %u",
86420- mod->name, mod->init_size + mod->core_size);
86421+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
86422 print_unload_info(m, mod);
86423
86424 /* Informative for users. */
86425@@ -3649,7 +3811,7 @@ static int m_show(struct seq_file *m, void *p)
86426 mod->state == MODULE_STATE_COMING ? "Loading":
86427 "Live");
86428 /* Used by oprofile and other similar tools. */
86429- seq_printf(m, " 0x%pK", mod->module_core);
86430+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
86431
86432 /* Taints info */
86433 if (mod->taints)
86434@@ -3685,7 +3847,17 @@ static const struct file_operations proc_modules_operations = {
86435
86436 static int __init proc_modules_init(void)
86437 {
86438+#ifndef CONFIG_GRKERNSEC_HIDESYM
86439+#ifdef CONFIG_GRKERNSEC_PROC_USER
86440+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
86441+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
86442+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
86443+#else
86444 proc_create("modules", 0, NULL, &proc_modules_operations);
86445+#endif
86446+#else
86447+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
86448+#endif
86449 return 0;
86450 }
86451 module_init(proc_modules_init);
86452@@ -3746,14 +3918,14 @@ struct module *__module_address(unsigned long addr)
86453 {
86454 struct module *mod;
86455
86456- if (addr < module_addr_min || addr > module_addr_max)
86457+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
86458+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
86459 return NULL;
86460
86461 list_for_each_entry_rcu(mod, &modules, list) {
86462 if (mod->state == MODULE_STATE_UNFORMED)
86463 continue;
86464- if (within_module_core(addr, mod)
86465- || within_module_init(addr, mod))
86466+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
86467 return mod;
86468 }
86469 return NULL;
86470@@ -3788,11 +3960,20 @@ bool is_module_text_address(unsigned long addr)
86471 */
86472 struct module *__module_text_address(unsigned long addr)
86473 {
86474- struct module *mod = __module_address(addr);
86475+ struct module *mod;
86476+
86477+#ifdef CONFIG_X86_32
86478+ addr = ktla_ktva(addr);
86479+#endif
86480+
86481+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
86482+ return NULL;
86483+
86484+ mod = __module_address(addr);
86485+
86486 if (mod) {
86487 /* Make sure it's within the text section. */
86488- if (!within(addr, mod->module_init, mod->init_text_size)
86489- && !within(addr, mod->module_core, mod->core_text_size))
86490+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
86491 mod = NULL;
86492 }
86493 return mod;
86494diff --git a/kernel/notifier.c b/kernel/notifier.c
86495index 2d5cc4c..d9ea600 100644
86496--- a/kernel/notifier.c
86497+++ b/kernel/notifier.c
86498@@ -5,6 +5,7 @@
86499 #include <linux/rcupdate.h>
86500 #include <linux/vmalloc.h>
86501 #include <linux/reboot.h>
86502+#include <linux/mm.h>
86503
86504 /*
86505 * Notifier list for kernel code which wants to be called
86506@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
86507 while ((*nl) != NULL) {
86508 if (n->priority > (*nl)->priority)
86509 break;
86510- nl = &((*nl)->next);
86511+ nl = (struct notifier_block **)&((*nl)->next);
86512 }
86513- n->next = *nl;
86514+ pax_open_kernel();
86515+ *(const void **)&n->next = *nl;
86516 rcu_assign_pointer(*nl, n);
86517+ pax_close_kernel();
86518 return 0;
86519 }
86520
86521@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
86522 return 0;
86523 if (n->priority > (*nl)->priority)
86524 break;
86525- nl = &((*nl)->next);
86526+ nl = (struct notifier_block **)&((*nl)->next);
86527 }
86528- n->next = *nl;
86529+ pax_open_kernel();
86530+ *(const void **)&n->next = *nl;
86531 rcu_assign_pointer(*nl, n);
86532+ pax_close_kernel();
86533 return 0;
86534 }
86535
86536@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
86537 {
86538 while ((*nl) != NULL) {
86539 if ((*nl) == n) {
86540+ pax_open_kernel();
86541 rcu_assign_pointer(*nl, n->next);
86542+ pax_close_kernel();
86543 return 0;
86544 }
86545- nl = &((*nl)->next);
86546+ nl = (struct notifier_block **)&((*nl)->next);
86547 }
86548 return -ENOENT;
86549 }
86550diff --git a/kernel/padata.c b/kernel/padata.c
86551index 2abd25d..02c4faa 100644
86552--- a/kernel/padata.c
86553+++ b/kernel/padata.c
86554@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
86555 * seq_nr mod. number of cpus in use.
86556 */
86557
86558- seq_nr = atomic_inc_return(&pd->seq_nr);
86559+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
86560 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
86561
86562 return padata_index_to_cpu(pd, cpu_index);
86563@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
86564 padata_init_pqueues(pd);
86565 padata_init_squeues(pd);
86566 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
86567- atomic_set(&pd->seq_nr, -1);
86568+ atomic_set_unchecked(&pd->seq_nr, -1);
86569 atomic_set(&pd->reorder_objects, 0);
86570 atomic_set(&pd->refcnt, 0);
86571 pd->pinst = pinst;
86572diff --git a/kernel/panic.c b/kernel/panic.c
86573index c00b4ce..a846117 100644
86574--- a/kernel/panic.c
86575+++ b/kernel/panic.c
86576@@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
86577 disable_trace_on_warning();
86578
86579 pr_warn("------------[ cut here ]------------\n");
86580- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
86581+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
86582 raw_smp_processor_id(), current->pid, file, line, caller);
86583
86584 if (args)
86585@@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
86586 */
86587 void __stack_chk_fail(void)
86588 {
86589- panic("stack-protector: Kernel stack is corrupted in: %p\n",
86590+ dump_stack();
86591+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
86592 __builtin_return_address(0));
86593 }
86594 EXPORT_SYMBOL(__stack_chk_fail);
86595diff --git a/kernel/pid.c b/kernel/pid.c
86596index 9b9a266..c20ef80 100644
86597--- a/kernel/pid.c
86598+++ b/kernel/pid.c
86599@@ -33,6 +33,7 @@
86600 #include <linux/rculist.h>
86601 #include <linux/bootmem.h>
86602 #include <linux/hash.h>
86603+#include <linux/security.h>
86604 #include <linux/pid_namespace.h>
86605 #include <linux/init_task.h>
86606 #include <linux/syscalls.h>
86607@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
86608
86609 int pid_max = PID_MAX_DEFAULT;
86610
86611-#define RESERVED_PIDS 300
86612+#define RESERVED_PIDS 500
86613
86614 int pid_max_min = RESERVED_PIDS + 1;
86615 int pid_max_max = PID_MAX_LIMIT;
86616@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
86617 */
86618 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
86619 {
86620+ struct task_struct *task;
86621+
86622 rcu_lockdep_assert(rcu_read_lock_held(),
86623 "find_task_by_pid_ns() needs rcu_read_lock()"
86624 " protection");
86625- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
86626+
86627+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
86628+
86629+ if (gr_pid_is_chrooted(task))
86630+ return NULL;
86631+
86632+ return task;
86633 }
86634
86635 struct task_struct *find_task_by_vpid(pid_t vnr)
86636@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
86637 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
86638 }
86639
86640+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
86641+{
86642+ rcu_lockdep_assert(rcu_read_lock_held(),
86643+ "find_task_by_pid_ns() needs rcu_read_lock()"
86644+ " protection");
86645+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
86646+}
86647+
86648 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
86649 {
86650 struct pid *pid;
86651diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
86652index 06c62de..b08cc6c 100644
86653--- a/kernel/pid_namespace.c
86654+++ b/kernel/pid_namespace.c
86655@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
86656 void __user *buffer, size_t *lenp, loff_t *ppos)
86657 {
86658 struct pid_namespace *pid_ns = task_active_pid_ns(current);
86659- struct ctl_table tmp = *table;
86660+ ctl_table_no_const tmp = *table;
86661
86662 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
86663 return -EPERM;
86664diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
86665index c7f31aa..2b44977 100644
86666--- a/kernel/posix-cpu-timers.c
86667+++ b/kernel/posix-cpu-timers.c
86668@@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
86669
86670 static __init int init_posix_cpu_timers(void)
86671 {
86672- struct k_clock process = {
86673+ static struct k_clock process = {
86674 .clock_getres = process_cpu_clock_getres,
86675 .clock_get = process_cpu_clock_get,
86676 .timer_create = process_cpu_timer_create,
86677 .nsleep = process_cpu_nsleep,
86678 .nsleep_restart = process_cpu_nsleep_restart,
86679 };
86680- struct k_clock thread = {
86681+ static struct k_clock thread = {
86682 .clock_getres = thread_cpu_clock_getres,
86683 .clock_get = thread_cpu_clock_get,
86684 .timer_create = thread_cpu_timer_create,
86685diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
86686index 424c2d4..679242f 100644
86687--- a/kernel/posix-timers.c
86688+++ b/kernel/posix-timers.c
86689@@ -43,6 +43,7 @@
86690 #include <linux/hash.h>
86691 #include <linux/posix-clock.h>
86692 #include <linux/posix-timers.h>
86693+#include <linux/grsecurity.h>
86694 #include <linux/syscalls.h>
86695 #include <linux/wait.h>
86696 #include <linux/workqueue.h>
86697@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
86698 * which we beg off on and pass to do_sys_settimeofday().
86699 */
86700
86701-static struct k_clock posix_clocks[MAX_CLOCKS];
86702+static struct k_clock *posix_clocks[MAX_CLOCKS];
86703
86704 /*
86705 * These ones are defined below.
86706@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
86707 */
86708 static __init int init_posix_timers(void)
86709 {
86710- struct k_clock clock_realtime = {
86711+ static struct k_clock clock_realtime = {
86712 .clock_getres = hrtimer_get_res,
86713 .clock_get = posix_clock_realtime_get,
86714 .clock_set = posix_clock_realtime_set,
86715@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
86716 .timer_get = common_timer_get,
86717 .timer_del = common_timer_del,
86718 };
86719- struct k_clock clock_monotonic = {
86720+ static struct k_clock clock_monotonic = {
86721 .clock_getres = hrtimer_get_res,
86722 .clock_get = posix_ktime_get_ts,
86723 .nsleep = common_nsleep,
86724@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
86725 .timer_get = common_timer_get,
86726 .timer_del = common_timer_del,
86727 };
86728- struct k_clock clock_monotonic_raw = {
86729+ static struct k_clock clock_monotonic_raw = {
86730 .clock_getres = hrtimer_get_res,
86731 .clock_get = posix_get_monotonic_raw,
86732 };
86733- struct k_clock clock_realtime_coarse = {
86734+ static struct k_clock clock_realtime_coarse = {
86735 .clock_getres = posix_get_coarse_res,
86736 .clock_get = posix_get_realtime_coarse,
86737 };
86738- struct k_clock clock_monotonic_coarse = {
86739+ static struct k_clock clock_monotonic_coarse = {
86740 .clock_getres = posix_get_coarse_res,
86741 .clock_get = posix_get_monotonic_coarse,
86742 };
86743- struct k_clock clock_tai = {
86744+ static struct k_clock clock_tai = {
86745 .clock_getres = hrtimer_get_res,
86746 .clock_get = posix_get_tai,
86747 .nsleep = common_nsleep,
86748@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
86749 .timer_get = common_timer_get,
86750 .timer_del = common_timer_del,
86751 };
86752- struct k_clock clock_boottime = {
86753+ static struct k_clock clock_boottime = {
86754 .clock_getres = hrtimer_get_res,
86755 .clock_get = posix_get_boottime,
86756 .nsleep = common_nsleep,
86757@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
86758 return;
86759 }
86760
86761- posix_clocks[clock_id] = *new_clock;
86762+ posix_clocks[clock_id] = new_clock;
86763 }
86764 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
86765
86766@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
86767 return (id & CLOCKFD_MASK) == CLOCKFD ?
86768 &clock_posix_dynamic : &clock_posix_cpu;
86769
86770- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
86771+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
86772 return NULL;
86773- return &posix_clocks[id];
86774+ return posix_clocks[id];
86775 }
86776
86777 static int common_timer_create(struct k_itimer *new_timer)
86778@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
86779 struct k_clock *kc = clockid_to_kclock(which_clock);
86780 struct k_itimer *new_timer;
86781 int error, new_timer_id;
86782- sigevent_t event;
86783+ sigevent_t event = { };
86784 int it_id_set = IT_ID_NOT_SET;
86785
86786 if (!kc)
86787@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
86788 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
86789 return -EFAULT;
86790
86791+ /* only the CLOCK_REALTIME clock can be set, all other clocks
86792+ have their clock_set fptr set to a nosettime dummy function
86793+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
86794+ call common_clock_set, which calls do_sys_settimeofday, which
86795+ we hook
86796+ */
86797+
86798 return kc->clock_set(which_clock, &new_tp);
86799 }
86800
86801diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
86802index 2fac9cc..56fef29 100644
86803--- a/kernel/power/Kconfig
86804+++ b/kernel/power/Kconfig
86805@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
86806 config HIBERNATION
86807 bool "Hibernation (aka 'suspend to disk')"
86808 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
86809+ depends on !GRKERNSEC_KMEM
86810+ depends on !PAX_MEMORY_SANITIZE
86811 select HIBERNATE_CALLBACKS
86812 select LZO_COMPRESS
86813 select LZO_DECOMPRESS
86814diff --git a/kernel/power/process.c b/kernel/power/process.c
86815index 06ec886..9dba35e 100644
86816--- a/kernel/power/process.c
86817+++ b/kernel/power/process.c
86818@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
86819 unsigned int elapsed_msecs;
86820 bool wakeup = false;
86821 int sleep_usecs = USEC_PER_MSEC;
86822+ bool timedout = false;
86823
86824 do_gettimeofday(&start);
86825
86826@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
86827
86828 while (true) {
86829 todo = 0;
86830+ if (time_after(jiffies, end_time))
86831+ timedout = true;
86832 read_lock(&tasklist_lock);
86833 do_each_thread(g, p) {
86834 if (p == current || !freeze_task(p))
86835 continue;
86836
86837- if (!freezer_should_skip(p))
86838+ if (!freezer_should_skip(p)) {
86839 todo++;
86840+ if (timedout) {
86841+ printk(KERN_ERR "Task refusing to freeze:\n");
86842+ sched_show_task(p);
86843+ }
86844+ }
86845 } while_each_thread(g, p);
86846 read_unlock(&tasklist_lock);
86847
86848@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
86849 todo += wq_busy;
86850 }
86851
86852- if (!todo || time_after(jiffies, end_time))
86853+ if (!todo || timedout)
86854 break;
86855
86856 if (pm_wakeup_pending()) {
86857diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
86858index be7c86b..c741464 100644
86859--- a/kernel/printk/printk.c
86860+++ b/kernel/printk/printk.c
86861@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
86862 if (from_file && type != SYSLOG_ACTION_OPEN)
86863 return 0;
86864
86865+#ifdef CONFIG_GRKERNSEC_DMESG
86866+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
86867+ return -EPERM;
86868+#endif
86869+
86870 if (syslog_action_restricted(type)) {
86871 if (capable(CAP_SYSLOG))
86872 return 0;
86873diff --git a/kernel/profile.c b/kernel/profile.c
86874index 6631e1e..310c266 100644
86875--- a/kernel/profile.c
86876+++ b/kernel/profile.c
86877@@ -37,7 +37,7 @@ struct profile_hit {
86878 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
86879 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
86880
86881-static atomic_t *prof_buffer;
86882+static atomic_unchecked_t *prof_buffer;
86883 static unsigned long prof_len, prof_shift;
86884
86885 int prof_on __read_mostly;
86886@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
86887 hits[i].pc = 0;
86888 continue;
86889 }
86890- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
86891+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
86892 hits[i].hits = hits[i].pc = 0;
86893 }
86894 }
86895@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
86896 * Add the current hit(s) and flush the write-queue out
86897 * to the global buffer:
86898 */
86899- atomic_add(nr_hits, &prof_buffer[pc]);
86900+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
86901 for (i = 0; i < NR_PROFILE_HIT; ++i) {
86902- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
86903+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
86904 hits[i].pc = hits[i].hits = 0;
86905 }
86906 out:
86907@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
86908 {
86909 unsigned long pc;
86910 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
86911- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
86912+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
86913 }
86914 #endif /* !CONFIG_SMP */
86915
86916@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
86917 return -EFAULT;
86918 buf++; p++; count--; read++;
86919 }
86920- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
86921+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
86922 if (copy_to_user(buf, (void *)pnt, count))
86923 return -EFAULT;
86924 read += count;
86925@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
86926 }
86927 #endif
86928 profile_discard_flip_buffers();
86929- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
86930+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
86931 return count;
86932 }
86933
86934diff --git a/kernel/ptrace.c b/kernel/ptrace.c
86935index 1f4bcb3..99cf7ab 100644
86936--- a/kernel/ptrace.c
86937+++ b/kernel/ptrace.c
86938@@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
86939 if (seize)
86940 flags |= PT_SEIZED;
86941 rcu_read_lock();
86942- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
86943+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
86944 flags |= PT_PTRACE_CAP;
86945 rcu_read_unlock();
86946 task->ptrace = flags;
86947@@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
86948 break;
86949 return -EIO;
86950 }
86951- if (copy_to_user(dst, buf, retval))
86952+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
86953 return -EFAULT;
86954 copied += retval;
86955 src += retval;
86956@@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
86957 bool seized = child->ptrace & PT_SEIZED;
86958 int ret = -EIO;
86959 siginfo_t siginfo, *si;
86960- void __user *datavp = (void __user *) data;
86961+ void __user *datavp = (__force void __user *) data;
86962 unsigned long __user *datalp = datavp;
86963 unsigned long flags;
86964
86965@@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
86966 goto out;
86967 }
86968
86969+ if (gr_handle_ptrace(child, request)) {
86970+ ret = -EPERM;
86971+ goto out_put_task_struct;
86972+ }
86973+
86974 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
86975 ret = ptrace_attach(child, request, addr, data);
86976 /*
86977 * Some architectures need to do book-keeping after
86978 * a ptrace attach.
86979 */
86980- if (!ret)
86981+ if (!ret) {
86982 arch_ptrace_attach(child);
86983+ gr_audit_ptrace(child);
86984+ }
86985 goto out_put_task_struct;
86986 }
86987
86988@@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
86989 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
86990 if (copied != sizeof(tmp))
86991 return -EIO;
86992- return put_user(tmp, (unsigned long __user *)data);
86993+ return put_user(tmp, (__force unsigned long __user *)data);
86994 }
86995
86996 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
86997@@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
86998 }
86999
87000 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
87001- compat_long_t addr, compat_long_t data)
87002+ compat_ulong_t addr, compat_ulong_t data)
87003 {
87004 struct task_struct *child;
87005 long ret;
87006@@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
87007 goto out;
87008 }
87009
87010+ if (gr_handle_ptrace(child, request)) {
87011+ ret = -EPERM;
87012+ goto out_put_task_struct;
87013+ }
87014+
87015 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
87016 ret = ptrace_attach(child, request, addr, data);
87017 /*
87018 * Some architectures need to do book-keeping after
87019 * a ptrace attach.
87020 */
87021- if (!ret)
87022+ if (!ret) {
87023 arch_ptrace_attach(child);
87024+ gr_audit_ptrace(child);
87025+ }
87026 goto out_put_task_struct;
87027 }
87028
87029diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
87030index 01d5ccb..cdcbee6 100644
87031--- a/kernel/rcu/srcu.c
87032+++ b/kernel/rcu/srcu.c
87033@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
87034
87035 idx = ACCESS_ONCE(sp->completed) & 0x1;
87036 preempt_disable();
87037- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
87038+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
87039 smp_mb(); /* B */ /* Avoid leaking the critical section. */
87040- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
87041+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
87042 preempt_enable();
87043 return idx;
87044 }
87045diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
87046index 1254f31..16258dc 100644
87047--- a/kernel/rcu/tiny.c
87048+++ b/kernel/rcu/tiny.c
87049@@ -46,7 +46,7 @@
87050 /* Forward declarations for tiny_plugin.h. */
87051 struct rcu_ctrlblk;
87052 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
87053-static void rcu_process_callbacks(struct softirq_action *unused);
87054+static void rcu_process_callbacks(void);
87055 static void __call_rcu(struct rcu_head *head,
87056 void (*func)(struct rcu_head *rcu),
87057 struct rcu_ctrlblk *rcp);
87058@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
87059 false));
87060 }
87061
87062-static void rcu_process_callbacks(struct softirq_action *unused)
87063+static __latent_entropy void rcu_process_callbacks(void)
87064 {
87065 __rcu_process_callbacks(&rcu_sched_ctrlblk);
87066 __rcu_process_callbacks(&rcu_bh_ctrlblk);
87067diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
87068index 3929cd4..421624d 100644
87069--- a/kernel/rcu/torture.c
87070+++ b/kernel/rcu/torture.c
87071@@ -176,12 +176,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
87072 { 0 };
87073 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
87074 { 0 };
87075-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
87076-static atomic_t n_rcu_torture_alloc;
87077-static atomic_t n_rcu_torture_alloc_fail;
87078-static atomic_t n_rcu_torture_free;
87079-static atomic_t n_rcu_torture_mberror;
87080-static atomic_t n_rcu_torture_error;
87081+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
87082+static atomic_unchecked_t n_rcu_torture_alloc;
87083+static atomic_unchecked_t n_rcu_torture_alloc_fail;
87084+static atomic_unchecked_t n_rcu_torture_free;
87085+static atomic_unchecked_t n_rcu_torture_mberror;
87086+static atomic_unchecked_t n_rcu_torture_error;
87087 static long n_rcu_torture_barrier_error;
87088 static long n_rcu_torture_boost_ktrerror;
87089 static long n_rcu_torture_boost_rterror;
87090@@ -299,11 +299,11 @@ rcu_torture_alloc(void)
87091
87092 spin_lock_bh(&rcu_torture_lock);
87093 if (list_empty(&rcu_torture_freelist)) {
87094- atomic_inc(&n_rcu_torture_alloc_fail);
87095+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
87096 spin_unlock_bh(&rcu_torture_lock);
87097 return NULL;
87098 }
87099- atomic_inc(&n_rcu_torture_alloc);
87100+ atomic_inc_unchecked(&n_rcu_torture_alloc);
87101 p = rcu_torture_freelist.next;
87102 list_del_init(p);
87103 spin_unlock_bh(&rcu_torture_lock);
87104@@ -316,7 +316,7 @@ rcu_torture_alloc(void)
87105 static void
87106 rcu_torture_free(struct rcu_torture *p)
87107 {
87108- atomic_inc(&n_rcu_torture_free);
87109+ atomic_inc_unchecked(&n_rcu_torture_free);
87110 spin_lock_bh(&rcu_torture_lock);
87111 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
87112 spin_unlock_bh(&rcu_torture_lock);
87113@@ -437,7 +437,7 @@ rcu_torture_cb(struct rcu_head *p)
87114 i = rp->rtort_pipe_count;
87115 if (i > RCU_TORTURE_PIPE_LEN)
87116 i = RCU_TORTURE_PIPE_LEN;
87117- atomic_inc(&rcu_torture_wcount[i]);
87118+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
87119 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
87120 rp->rtort_mbtest = 0;
87121 rcu_torture_free(rp);
87122@@ -827,7 +827,7 @@ rcu_torture_writer(void *arg)
87123 i = old_rp->rtort_pipe_count;
87124 if (i > RCU_TORTURE_PIPE_LEN)
87125 i = RCU_TORTURE_PIPE_LEN;
87126- atomic_inc(&rcu_torture_wcount[i]);
87127+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
87128 old_rp->rtort_pipe_count++;
87129 if (gp_normal == gp_exp)
87130 exp = !!(rcu_random(&rand) & 0x80);
87131@@ -845,7 +845,7 @@ rcu_torture_writer(void *arg)
87132 i = rp->rtort_pipe_count;
87133 if (i > RCU_TORTURE_PIPE_LEN)
87134 i = RCU_TORTURE_PIPE_LEN;
87135- atomic_inc(&rcu_torture_wcount[i]);
87136+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
87137 if (++rp->rtort_pipe_count >=
87138 RCU_TORTURE_PIPE_LEN) {
87139 rp->rtort_mbtest = 0;
87140@@ -944,7 +944,7 @@ static void rcu_torture_timer(unsigned long unused)
87141 return;
87142 }
87143 if (p->rtort_mbtest == 0)
87144- atomic_inc(&n_rcu_torture_mberror);
87145+ atomic_inc_unchecked(&n_rcu_torture_mberror);
87146 spin_lock(&rand_lock);
87147 cur_ops->read_delay(&rand);
87148 n_rcu_torture_timers++;
87149@@ -1014,7 +1014,7 @@ rcu_torture_reader(void *arg)
87150 continue;
87151 }
87152 if (p->rtort_mbtest == 0)
87153- atomic_inc(&n_rcu_torture_mberror);
87154+ atomic_inc_unchecked(&n_rcu_torture_mberror);
87155 cur_ops->read_delay(&rand);
87156 preempt_disable();
87157 pipe_count = p->rtort_pipe_count;
87158@@ -1077,11 +1077,11 @@ rcu_torture_printk(char *page)
87159 rcu_torture_current,
87160 rcu_torture_current_version,
87161 list_empty(&rcu_torture_freelist),
87162- atomic_read(&n_rcu_torture_alloc),
87163- atomic_read(&n_rcu_torture_alloc_fail),
87164- atomic_read(&n_rcu_torture_free));
87165+ atomic_read_unchecked(&n_rcu_torture_alloc),
87166+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
87167+ atomic_read_unchecked(&n_rcu_torture_free));
87168 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
87169- atomic_read(&n_rcu_torture_mberror),
87170+ atomic_read_unchecked(&n_rcu_torture_mberror),
87171 n_rcu_torture_boost_ktrerror,
87172 n_rcu_torture_boost_rterror);
87173 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
87174@@ -1100,14 +1100,14 @@ rcu_torture_printk(char *page)
87175 n_barrier_attempts,
87176 n_rcu_torture_barrier_error);
87177 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
87178- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
87179+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
87180 n_rcu_torture_barrier_error != 0 ||
87181 n_rcu_torture_boost_ktrerror != 0 ||
87182 n_rcu_torture_boost_rterror != 0 ||
87183 n_rcu_torture_boost_failure != 0 ||
87184 i > 1) {
87185 cnt += sprintf(&page[cnt], "!!! ");
87186- atomic_inc(&n_rcu_torture_error);
87187+ atomic_inc_unchecked(&n_rcu_torture_error);
87188 WARN_ON_ONCE(1);
87189 }
87190 cnt += sprintf(&page[cnt], "Reader Pipe: ");
87191@@ -1121,7 +1121,7 @@ rcu_torture_printk(char *page)
87192 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
87193 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
87194 cnt += sprintf(&page[cnt], " %d",
87195- atomic_read(&rcu_torture_wcount[i]));
87196+ atomic_read_unchecked(&rcu_torture_wcount[i]));
87197 }
87198 cnt += sprintf(&page[cnt], "\n");
87199 if (cur_ops->stats)
87200@@ -1836,7 +1836,7 @@ rcu_torture_cleanup(void)
87201
87202 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
87203
87204- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
87205+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
87206 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
87207 else if (n_online_successes != n_online_attempts ||
87208 n_offline_successes != n_offline_attempts)
87209@@ -1958,18 +1958,18 @@ rcu_torture_init(void)
87210
87211 rcu_torture_current = NULL;
87212 rcu_torture_current_version = 0;
87213- atomic_set(&n_rcu_torture_alloc, 0);
87214- atomic_set(&n_rcu_torture_alloc_fail, 0);
87215- atomic_set(&n_rcu_torture_free, 0);
87216- atomic_set(&n_rcu_torture_mberror, 0);
87217- atomic_set(&n_rcu_torture_error, 0);
87218+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
87219+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
87220+ atomic_set_unchecked(&n_rcu_torture_free, 0);
87221+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
87222+ atomic_set_unchecked(&n_rcu_torture_error, 0);
87223 n_rcu_torture_barrier_error = 0;
87224 n_rcu_torture_boost_ktrerror = 0;
87225 n_rcu_torture_boost_rterror = 0;
87226 n_rcu_torture_boost_failure = 0;
87227 n_rcu_torture_boosts = 0;
87228 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
87229- atomic_set(&rcu_torture_wcount[i], 0);
87230+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
87231 for_each_possible_cpu(cpu) {
87232 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
87233 per_cpu(rcu_torture_count, cpu)[i] = 0;
87234diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
87235index dd08198..5ccccbe 100644
87236--- a/kernel/rcu/tree.c
87237+++ b/kernel/rcu/tree.c
87238@@ -383,9 +383,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
87239 rcu_prepare_for_idle(smp_processor_id());
87240 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
87241 smp_mb__before_atomic_inc(); /* See above. */
87242- atomic_inc(&rdtp->dynticks);
87243+ atomic_inc_unchecked(&rdtp->dynticks);
87244 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
87245- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
87246+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
87247
87248 /*
87249 * It is illegal to enter an extended quiescent state while
87250@@ -502,10 +502,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
87251 int user)
87252 {
87253 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
87254- atomic_inc(&rdtp->dynticks);
87255+ atomic_inc_unchecked(&rdtp->dynticks);
87256 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
87257 smp_mb__after_atomic_inc(); /* See above. */
87258- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
87259+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
87260 rcu_cleanup_after_idle(smp_processor_id());
87261 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
87262 if (!user && !is_idle_task(current)) {
87263@@ -625,14 +625,14 @@ void rcu_nmi_enter(void)
87264 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
87265
87266 if (rdtp->dynticks_nmi_nesting == 0 &&
87267- (atomic_read(&rdtp->dynticks) & 0x1))
87268+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
87269 return;
87270 rdtp->dynticks_nmi_nesting++;
87271 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
87272- atomic_inc(&rdtp->dynticks);
87273+ atomic_inc_unchecked(&rdtp->dynticks);
87274 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
87275 smp_mb__after_atomic_inc(); /* See above. */
87276- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
87277+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
87278 }
87279
87280 /**
87281@@ -651,9 +651,9 @@ void rcu_nmi_exit(void)
87282 return;
87283 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
87284 smp_mb__before_atomic_inc(); /* See above. */
87285- atomic_inc(&rdtp->dynticks);
87286+ atomic_inc_unchecked(&rdtp->dynticks);
87287 smp_mb__after_atomic_inc(); /* Force delay to next write. */
87288- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
87289+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
87290 }
87291
87292 /**
87293@@ -666,7 +666,7 @@ void rcu_nmi_exit(void)
87294 */
87295 bool notrace __rcu_is_watching(void)
87296 {
87297- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
87298+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
87299 }
87300
87301 /**
87302@@ -749,7 +749,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
87303 static int dyntick_save_progress_counter(struct rcu_data *rdp,
87304 bool *isidle, unsigned long *maxj)
87305 {
87306- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
87307+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
87308 rcu_sysidle_check_cpu(rdp, isidle, maxj);
87309 return (rdp->dynticks_snap & 0x1) == 0;
87310 }
87311@@ -766,7 +766,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
87312 unsigned int curr;
87313 unsigned int snap;
87314
87315- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
87316+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
87317 snap = (unsigned int)rdp->dynticks_snap;
87318
87319 /*
87320@@ -1412,9 +1412,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
87321 rdp = this_cpu_ptr(rsp->rda);
87322 rcu_preempt_check_blocked_tasks(rnp);
87323 rnp->qsmask = rnp->qsmaskinit;
87324- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
87325+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
87326 WARN_ON_ONCE(rnp->completed != rsp->completed);
87327- ACCESS_ONCE(rnp->completed) = rsp->completed;
87328+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
87329 if (rnp == rdp->mynode)
87330 __note_gp_changes(rsp, rnp, rdp);
87331 rcu_preempt_boost_start_gp(rnp);
87332@@ -1505,7 +1505,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
87333 */
87334 rcu_for_each_node_breadth_first(rsp, rnp) {
87335 raw_spin_lock_irq(&rnp->lock);
87336- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
87337+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
87338 rdp = this_cpu_ptr(rsp->rda);
87339 if (rnp == rdp->mynode)
87340 __note_gp_changes(rsp, rnp, rdp);
87341@@ -1865,7 +1865,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
87342 rsp->qlen += rdp->qlen;
87343 rdp->n_cbs_orphaned += rdp->qlen;
87344 rdp->qlen_lazy = 0;
87345- ACCESS_ONCE(rdp->qlen) = 0;
87346+ ACCESS_ONCE_RW(rdp->qlen) = 0;
87347 }
87348
87349 /*
87350@@ -2111,7 +2111,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
87351 }
87352 smp_mb(); /* List handling before counting for rcu_barrier(). */
87353 rdp->qlen_lazy -= count_lazy;
87354- ACCESS_ONCE(rdp->qlen) -= count;
87355+ ACCESS_ONCE_RW(rdp->qlen) -= count;
87356 rdp->n_cbs_invoked += count;
87357
87358 /* Reinstate batch limit if we have worked down the excess. */
87359@@ -2308,7 +2308,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
87360 /*
87361 * Do RCU core processing for the current CPU.
87362 */
87363-static void rcu_process_callbacks(struct softirq_action *unused)
87364+static void rcu_process_callbacks(void)
87365 {
87366 struct rcu_state *rsp;
87367
87368@@ -2415,7 +2415,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
87369 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
87370 if (debug_rcu_head_queue(head)) {
87371 /* Probable double call_rcu(), so leak the callback. */
87372- ACCESS_ONCE(head->func) = rcu_leak_callback;
87373+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
87374 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
87375 return;
87376 }
87377@@ -2443,7 +2443,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
87378 local_irq_restore(flags);
87379 return;
87380 }
87381- ACCESS_ONCE(rdp->qlen)++;
87382+ ACCESS_ONCE_RW(rdp->qlen)++;
87383 if (lazy)
87384 rdp->qlen_lazy++;
87385 else
87386@@ -2652,11 +2652,11 @@ void synchronize_sched_expedited(void)
87387 * counter wrap on a 32-bit system. Quite a few more CPUs would of
87388 * course be required on a 64-bit system.
87389 */
87390- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
87391+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
87392 (ulong)atomic_long_read(&rsp->expedited_done) +
87393 ULONG_MAX / 8)) {
87394 synchronize_sched();
87395- atomic_long_inc(&rsp->expedited_wrap);
87396+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
87397 return;
87398 }
87399
87400@@ -2664,7 +2664,7 @@ void synchronize_sched_expedited(void)
87401 * Take a ticket. Note that atomic_inc_return() implies a
87402 * full memory barrier.
87403 */
87404- snap = atomic_long_inc_return(&rsp->expedited_start);
87405+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
87406 firstsnap = snap;
87407 get_online_cpus();
87408 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
87409@@ -2677,14 +2677,14 @@ void synchronize_sched_expedited(void)
87410 synchronize_sched_expedited_cpu_stop,
87411 NULL) == -EAGAIN) {
87412 put_online_cpus();
87413- atomic_long_inc(&rsp->expedited_tryfail);
87414+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
87415
87416 /* Check to see if someone else did our work for us. */
87417 s = atomic_long_read(&rsp->expedited_done);
87418 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
87419 /* ensure test happens before caller kfree */
87420 smp_mb__before_atomic_inc(); /* ^^^ */
87421- atomic_long_inc(&rsp->expedited_workdone1);
87422+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
87423 return;
87424 }
87425
87426@@ -2693,7 +2693,7 @@ void synchronize_sched_expedited(void)
87427 udelay(trycount * num_online_cpus());
87428 } else {
87429 wait_rcu_gp(call_rcu_sched);
87430- atomic_long_inc(&rsp->expedited_normal);
87431+ atomic_long_inc_unchecked(&rsp->expedited_normal);
87432 return;
87433 }
87434
87435@@ -2702,7 +2702,7 @@ void synchronize_sched_expedited(void)
87436 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
87437 /* ensure test happens before caller kfree */
87438 smp_mb__before_atomic_inc(); /* ^^^ */
87439- atomic_long_inc(&rsp->expedited_workdone2);
87440+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
87441 return;
87442 }
87443
87444@@ -2714,10 +2714,10 @@ void synchronize_sched_expedited(void)
87445 * period works for us.
87446 */
87447 get_online_cpus();
87448- snap = atomic_long_read(&rsp->expedited_start);
87449+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
87450 smp_mb(); /* ensure read is before try_stop_cpus(). */
87451 }
87452- atomic_long_inc(&rsp->expedited_stoppedcpus);
87453+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
87454
87455 /*
87456 * Everyone up to our most recent fetch is covered by our grace
87457@@ -2726,16 +2726,16 @@ void synchronize_sched_expedited(void)
87458 * than we did already did their update.
87459 */
87460 do {
87461- atomic_long_inc(&rsp->expedited_done_tries);
87462+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
87463 s = atomic_long_read(&rsp->expedited_done);
87464 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
87465 /* ensure test happens before caller kfree */
87466 smp_mb__before_atomic_inc(); /* ^^^ */
87467- atomic_long_inc(&rsp->expedited_done_lost);
87468+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
87469 break;
87470 }
87471 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
87472- atomic_long_inc(&rsp->expedited_done_exit);
87473+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
87474
87475 put_online_cpus();
87476 }
87477@@ -2931,7 +2931,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
87478 * ACCESS_ONCE() to prevent the compiler from speculating
87479 * the increment to precede the early-exit check.
87480 */
87481- ACCESS_ONCE(rsp->n_barrier_done)++;
87482+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
87483 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
87484 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
87485 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
87486@@ -2981,7 +2981,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
87487
87488 /* Increment ->n_barrier_done to prevent duplicate work. */
87489 smp_mb(); /* Keep increment after above mechanism. */
87490- ACCESS_ONCE(rsp->n_barrier_done)++;
87491+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
87492 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
87493 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
87494 smp_mb(); /* Keep increment before caller's subsequent code. */
87495@@ -3026,10 +3026,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
87496 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
87497 init_callback_list(rdp);
87498 rdp->qlen_lazy = 0;
87499- ACCESS_ONCE(rdp->qlen) = 0;
87500+ ACCESS_ONCE_RW(rdp->qlen) = 0;
87501 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
87502 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
87503- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
87504+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
87505 rdp->cpu = cpu;
87506 rdp->rsp = rsp;
87507 rcu_boot_init_nocb_percpu_data(rdp);
87508@@ -3063,8 +3063,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
87509 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
87510 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
87511 rcu_sysidle_init_percpu_data(rdp->dynticks);
87512- atomic_set(&rdp->dynticks->dynticks,
87513- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
87514+ atomic_set_unchecked(&rdp->dynticks->dynticks,
87515+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
87516 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
87517
87518 /* Add CPU to rcu_node bitmasks. */
87519diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
87520index 52be957..365ded3 100644
87521--- a/kernel/rcu/tree.h
87522+++ b/kernel/rcu/tree.h
87523@@ -87,11 +87,11 @@ struct rcu_dynticks {
87524 long long dynticks_nesting; /* Track irq/process nesting level. */
87525 /* Process level is worth LLONG_MAX/2. */
87526 int dynticks_nmi_nesting; /* Track NMI nesting level. */
87527- atomic_t dynticks; /* Even value for idle, else odd. */
87528+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
87529 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
87530 long long dynticks_idle_nesting;
87531 /* irq/process nesting level from idle. */
87532- atomic_t dynticks_idle; /* Even value for idle, else odd. */
87533+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
87534 /* "Idle" excludes userspace execution. */
87535 unsigned long dynticks_idle_jiffies;
87536 /* End of last non-NMI non-idle period. */
87537@@ -429,17 +429,17 @@ struct rcu_state {
87538 /* _rcu_barrier(). */
87539 /* End of fields guarded by barrier_mutex. */
87540
87541- atomic_long_t expedited_start; /* Starting ticket. */
87542- atomic_long_t expedited_done; /* Done ticket. */
87543- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
87544- atomic_long_t expedited_tryfail; /* # acquisition failures. */
87545- atomic_long_t expedited_workdone1; /* # done by others #1. */
87546- atomic_long_t expedited_workdone2; /* # done by others #2. */
87547- atomic_long_t expedited_normal; /* # fallbacks to normal. */
87548- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
87549- atomic_long_t expedited_done_tries; /* # tries to update _done. */
87550- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
87551- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
87552+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
87553+ atomic_long_t expedited_done; /* Done ticket. */
87554+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
87555+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
87556+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
87557+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
87558+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
87559+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
87560+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
87561+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
87562+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
87563
87564 unsigned long jiffies_force_qs; /* Time at which to invoke */
87565 /* force_quiescent_state(). */
87566diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
87567index 08a7652..3598c7e 100644
87568--- a/kernel/rcu/tree_plugin.h
87569+++ b/kernel/rcu/tree_plugin.h
87570@@ -749,7 +749,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
87571 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
87572 {
87573 return !rcu_preempted_readers_exp(rnp) &&
87574- ACCESS_ONCE(rnp->expmask) == 0;
87575+ ACCESS_ONCE_RW(rnp->expmask) == 0;
87576 }
87577
87578 /*
87579@@ -905,7 +905,7 @@ void synchronize_rcu_expedited(void)
87580
87581 /* Clean up and exit. */
87582 smp_mb(); /* ensure expedited GP seen before counter increment. */
87583- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
87584+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
87585 unlock_mb_ret:
87586 mutex_unlock(&sync_rcu_preempt_exp_mutex);
87587 mb_ret:
87588@@ -1479,7 +1479,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
87589 free_cpumask_var(cm);
87590 }
87591
87592-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
87593+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
87594 .store = &rcu_cpu_kthread_task,
87595 .thread_should_run = rcu_cpu_kthread_should_run,
87596 .thread_fn = rcu_cpu_kthread,
87597@@ -1946,7 +1946,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
87598 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
87599 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
87600 cpu, ticks_value, ticks_title,
87601- atomic_read(&rdtp->dynticks) & 0xfff,
87602+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
87603 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
87604 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
87605 fast_no_hz);
87606@@ -2109,7 +2109,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
87607
87608 /* Enqueue the callback on the nocb list and update counts. */
87609 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
87610- ACCESS_ONCE(*old_rhpp) = rhp;
87611+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
87612 atomic_long_add(rhcount, &rdp->nocb_q_count);
87613 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
87614
87615@@ -2272,12 +2272,12 @@ static int rcu_nocb_kthread(void *arg)
87616 * Extract queued callbacks, update counts, and wait
87617 * for a grace period to elapse.
87618 */
87619- ACCESS_ONCE(rdp->nocb_head) = NULL;
87620+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
87621 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
87622 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
87623 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
87624- ACCESS_ONCE(rdp->nocb_p_count) += c;
87625- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
87626+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
87627+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
87628 rcu_nocb_wait_gp(rdp);
87629
87630 /* Each pass through the following loop invokes a callback. */
87631@@ -2303,8 +2303,8 @@ static int rcu_nocb_kthread(void *arg)
87632 list = next;
87633 }
87634 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
87635- ACCESS_ONCE(rdp->nocb_p_count) -= c;
87636- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
87637+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
87638+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
87639 rdp->n_nocbs_invoked += c;
87640 }
87641 return 0;
87642@@ -2331,7 +2331,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
87643 t = kthread_run(rcu_nocb_kthread, rdp,
87644 "rcuo%c/%d", rsp->abbr, cpu);
87645 BUG_ON(IS_ERR(t));
87646- ACCESS_ONCE(rdp->nocb_kthread) = t;
87647+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
87648 }
87649 }
87650
87651@@ -2457,11 +2457,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
87652
87653 /* Record start of fully idle period. */
87654 j = jiffies;
87655- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
87656+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
87657 smp_mb__before_atomic_inc();
87658- atomic_inc(&rdtp->dynticks_idle);
87659+ atomic_inc_unchecked(&rdtp->dynticks_idle);
87660 smp_mb__after_atomic_inc();
87661- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
87662+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
87663 }
87664
87665 /*
87666@@ -2526,9 +2526,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
87667
87668 /* Record end of idle period. */
87669 smp_mb__before_atomic_inc();
87670- atomic_inc(&rdtp->dynticks_idle);
87671+ atomic_inc_unchecked(&rdtp->dynticks_idle);
87672 smp_mb__after_atomic_inc();
87673- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
87674+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
87675
87676 /*
87677 * If we are the timekeeping CPU, we are permitted to be non-idle
87678@@ -2569,7 +2569,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
87679 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
87680
87681 /* Pick up current idle and NMI-nesting counter and check. */
87682- cur = atomic_read(&rdtp->dynticks_idle);
87683+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
87684 if (cur & 0x1) {
87685 *isidle = false; /* We are not idle! */
87686 return;
87687@@ -2632,7 +2632,7 @@ static void rcu_sysidle(unsigned long j)
87688 case RCU_SYSIDLE_NOT:
87689
87690 /* First time all are idle, so note a short idle period. */
87691- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
87692+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
87693 break;
87694
87695 case RCU_SYSIDLE_SHORT:
87696@@ -2669,7 +2669,7 @@ static void rcu_sysidle(unsigned long j)
87697 static void rcu_sysidle_cancel(void)
87698 {
87699 smp_mb();
87700- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
87701+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
87702 }
87703
87704 /*
87705@@ -2717,7 +2717,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
87706 smp_mb(); /* grace period precedes setting inuse. */
87707
87708 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
87709- ACCESS_ONCE(rshp->inuse) = 0;
87710+ ACCESS_ONCE_RW(rshp->inuse) = 0;
87711 }
87712
87713 /*
87714diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
87715index 3596797..f78391c 100644
87716--- a/kernel/rcu/tree_trace.c
87717+++ b/kernel/rcu/tree_trace.c
87718@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
87719 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
87720 rdp->passed_quiesce, rdp->qs_pending);
87721 seq_printf(m, " dt=%d/%llx/%d df=%lu",
87722- atomic_read(&rdp->dynticks->dynticks),
87723+ atomic_read_unchecked(&rdp->dynticks->dynticks),
87724 rdp->dynticks->dynticks_nesting,
87725 rdp->dynticks->dynticks_nmi_nesting,
87726 rdp->dynticks_fqs);
87727@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
87728 struct rcu_state *rsp = (struct rcu_state *)m->private;
87729
87730 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",
87731- atomic_long_read(&rsp->expedited_start),
87732+ atomic_long_read_unchecked(&rsp->expedited_start),
87733 atomic_long_read(&rsp->expedited_done),
87734- atomic_long_read(&rsp->expedited_wrap),
87735- atomic_long_read(&rsp->expedited_tryfail),
87736- atomic_long_read(&rsp->expedited_workdone1),
87737- atomic_long_read(&rsp->expedited_workdone2),
87738- atomic_long_read(&rsp->expedited_normal),
87739- atomic_long_read(&rsp->expedited_stoppedcpus),
87740- atomic_long_read(&rsp->expedited_done_tries),
87741- atomic_long_read(&rsp->expedited_done_lost),
87742- atomic_long_read(&rsp->expedited_done_exit));
87743+ atomic_long_read_unchecked(&rsp->expedited_wrap),
87744+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
87745+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
87746+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
87747+ atomic_long_read_unchecked(&rsp->expedited_normal),
87748+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
87749+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
87750+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
87751+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
87752 return 0;
87753 }
87754
87755diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
87756index 6cb3dff..dc5710f 100644
87757--- a/kernel/rcu/update.c
87758+++ b/kernel/rcu/update.c
87759@@ -318,10 +318,10 @@ int rcu_jiffies_till_stall_check(void)
87760 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
87761 */
87762 if (till_stall_check < 3) {
87763- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
87764+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
87765 till_stall_check = 3;
87766 } else if (till_stall_check > 300) {
87767- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
87768+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
87769 till_stall_check = 300;
87770 }
87771 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
87772diff --git a/kernel/resource.c b/kernel/resource.c
87773index 3f285dc..5755f62 100644
87774--- a/kernel/resource.c
87775+++ b/kernel/resource.c
87776@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
87777
87778 static int __init ioresources_init(void)
87779 {
87780+#ifdef CONFIG_GRKERNSEC_PROC_ADD
87781+#ifdef CONFIG_GRKERNSEC_PROC_USER
87782+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
87783+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
87784+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
87785+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
87786+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
87787+#endif
87788+#else
87789 proc_create("ioports", 0, NULL, &proc_ioports_operations);
87790 proc_create("iomem", 0, NULL, &proc_iomem_operations);
87791+#endif
87792 return 0;
87793 }
87794 __initcall(ioresources_init);
87795diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
87796index 4a07353..66b5291 100644
87797--- a/kernel/sched/auto_group.c
87798+++ b/kernel/sched/auto_group.c
87799@@ -11,7 +11,7 @@
87800
87801 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
87802 static struct autogroup autogroup_default;
87803-static atomic_t autogroup_seq_nr;
87804+static atomic_unchecked_t autogroup_seq_nr;
87805
87806 void __init autogroup_init(struct task_struct *init_task)
87807 {
87808@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
87809
87810 kref_init(&ag->kref);
87811 init_rwsem(&ag->lock);
87812- ag->id = atomic_inc_return(&autogroup_seq_nr);
87813+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
87814 ag->tg = tg;
87815 #ifdef CONFIG_RT_GROUP_SCHED
87816 /*
87817diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
87818index a63f4dc..349bbb0 100644
87819--- a/kernel/sched/completion.c
87820+++ b/kernel/sched/completion.c
87821@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
87822 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
87823 * or number of jiffies left till timeout) if completed.
87824 */
87825-long __sched
87826+long __sched __intentional_overflow(-1)
87827 wait_for_completion_interruptible_timeout(struct completion *x,
87828 unsigned long timeout)
87829 {
87830@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
87831 *
87832 * Return: -ERESTARTSYS if interrupted, 0 if completed.
87833 */
87834-int __sched wait_for_completion_killable(struct completion *x)
87835+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
87836 {
87837 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
87838 if (t == -ERESTARTSYS)
87839@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
87840 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
87841 * or number of jiffies left till timeout) if completed.
87842 */
87843-long __sched
87844+long __sched __intentional_overflow(-1)
87845 wait_for_completion_killable_timeout(struct completion *x,
87846 unsigned long timeout)
87847 {
87848diff --git a/kernel/sched/core.c b/kernel/sched/core.c
87849index a88f4a4..9d57ac9 100644
87850--- a/kernel/sched/core.c
87851+++ b/kernel/sched/core.c
87852@@ -2871,6 +2871,8 @@ int can_nice(const struct task_struct *p, const int nice)
87853 /* convert nice value [19,-20] to rlimit style value [1,40] */
87854 int nice_rlim = 20 - nice;
87855
87856+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
87857+
87858 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
87859 capable(CAP_SYS_NICE));
87860 }
87861@@ -2904,7 +2906,8 @@ SYSCALL_DEFINE1(nice, int, increment)
87862 if (nice > 19)
87863 nice = 19;
87864
87865- if (increment < 0 && !can_nice(current, nice))
87866+ if (increment < 0 && (!can_nice(current, nice) ||
87867+ gr_handle_chroot_nice()))
87868 return -EPERM;
87869
87870 retval = security_task_setnice(current, nice);
87871@@ -3066,6 +3069,7 @@ recheck:
87872 unsigned long rlim_rtprio =
87873 task_rlimit(p, RLIMIT_RTPRIO);
87874
87875+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
87876 /* can't set/change the rt policy */
87877 if (policy != p->policy && !rlim_rtprio)
87878 return -EPERM;
87879@@ -4232,7 +4236,7 @@ static void migrate_tasks(unsigned int dead_cpu)
87880
87881 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
87882
87883-static struct ctl_table sd_ctl_dir[] = {
87884+static ctl_table_no_const sd_ctl_dir[] __read_only = {
87885 {
87886 .procname = "sched_domain",
87887 .mode = 0555,
87888@@ -4249,17 +4253,17 @@ static struct ctl_table sd_ctl_root[] = {
87889 {}
87890 };
87891
87892-static struct ctl_table *sd_alloc_ctl_entry(int n)
87893+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
87894 {
87895- struct ctl_table *entry =
87896+ ctl_table_no_const *entry =
87897 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
87898
87899 return entry;
87900 }
87901
87902-static void sd_free_ctl_entry(struct ctl_table **tablep)
87903+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
87904 {
87905- struct ctl_table *entry;
87906+ ctl_table_no_const *entry;
87907
87908 /*
87909 * In the intermediate directories, both the child directory and
87910@@ -4267,22 +4271,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
87911 * will always be set. In the lowest directory the names are
87912 * static strings and all have proc handlers.
87913 */
87914- for (entry = *tablep; entry->mode; entry++) {
87915- if (entry->child)
87916- sd_free_ctl_entry(&entry->child);
87917+ for (entry = tablep; entry->mode; entry++) {
87918+ if (entry->child) {
87919+ sd_free_ctl_entry(entry->child);
87920+ pax_open_kernel();
87921+ entry->child = NULL;
87922+ pax_close_kernel();
87923+ }
87924 if (entry->proc_handler == NULL)
87925 kfree(entry->procname);
87926 }
87927
87928- kfree(*tablep);
87929- *tablep = NULL;
87930+ kfree(tablep);
87931 }
87932
87933 static int min_load_idx = 0;
87934 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
87935
87936 static void
87937-set_table_entry(struct ctl_table *entry,
87938+set_table_entry(ctl_table_no_const *entry,
87939 const char *procname, void *data, int maxlen,
87940 umode_t mode, proc_handler *proc_handler,
87941 bool load_idx)
87942@@ -4302,7 +4309,7 @@ set_table_entry(struct ctl_table *entry,
87943 static struct ctl_table *
87944 sd_alloc_ctl_domain_table(struct sched_domain *sd)
87945 {
87946- struct ctl_table *table = sd_alloc_ctl_entry(13);
87947+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
87948
87949 if (table == NULL)
87950 return NULL;
87951@@ -4337,9 +4344,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
87952 return table;
87953 }
87954
87955-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
87956+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
87957 {
87958- struct ctl_table *entry, *table;
87959+ ctl_table_no_const *entry, *table;
87960 struct sched_domain *sd;
87961 int domain_num = 0, i;
87962 char buf[32];
87963@@ -4366,11 +4373,13 @@ static struct ctl_table_header *sd_sysctl_header;
87964 static void register_sched_domain_sysctl(void)
87965 {
87966 int i, cpu_num = num_possible_cpus();
87967- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
87968+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
87969 char buf[32];
87970
87971 WARN_ON(sd_ctl_dir[0].child);
87972+ pax_open_kernel();
87973 sd_ctl_dir[0].child = entry;
87974+ pax_close_kernel();
87975
87976 if (entry == NULL)
87977 return;
87978@@ -4393,8 +4402,12 @@ static void unregister_sched_domain_sysctl(void)
87979 if (sd_sysctl_header)
87980 unregister_sysctl_table(sd_sysctl_header);
87981 sd_sysctl_header = NULL;
87982- if (sd_ctl_dir[0].child)
87983- sd_free_ctl_entry(&sd_ctl_dir[0].child);
87984+ if (sd_ctl_dir[0].child) {
87985+ sd_free_ctl_entry(sd_ctl_dir[0].child);
87986+ pax_open_kernel();
87987+ sd_ctl_dir[0].child = NULL;
87988+ pax_close_kernel();
87989+ }
87990 }
87991 #else
87992 static void register_sched_domain_sysctl(void)
87993diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
87994index e64b079..a46bd34 100644
87995--- a/kernel/sched/fair.c
87996+++ b/kernel/sched/fair.c
87997@@ -1652,7 +1652,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
87998
87999 static void reset_ptenuma_scan(struct task_struct *p)
88000 {
88001- ACCESS_ONCE(p->mm->numa_scan_seq)++;
88002+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
88003 p->mm->numa_scan_offset = 0;
88004 }
88005
88006@@ -6863,7 +6863,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
88007 * run_rebalance_domains is triggered when needed from the scheduler tick.
88008 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
88009 */
88010-static void run_rebalance_domains(struct softirq_action *h)
88011+static __latent_entropy void run_rebalance_domains(void)
88012 {
88013 int this_cpu = smp_processor_id();
88014 struct rq *this_rq = cpu_rq(this_cpu);
88015diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
88016index 88c85b2..a1dec86 100644
88017--- a/kernel/sched/sched.h
88018+++ b/kernel/sched/sched.h
88019@@ -1035,7 +1035,7 @@ struct sched_class {
88020 #ifdef CONFIG_FAIR_GROUP_SCHED
88021 void (*task_move_group) (struct task_struct *p, int on_rq);
88022 #endif
88023-};
88024+} __do_const;
88025
88026 #define sched_class_highest (&stop_sched_class)
88027 #define for_each_class(class) \
88028diff --git a/kernel/signal.c b/kernel/signal.c
88029index 940b30e..7fd6041 100644
88030--- a/kernel/signal.c
88031+++ b/kernel/signal.c
88032@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
88033
88034 int print_fatal_signals __read_mostly;
88035
88036-static void __user *sig_handler(struct task_struct *t, int sig)
88037+static __sighandler_t sig_handler(struct task_struct *t, int sig)
88038 {
88039 return t->sighand->action[sig - 1].sa.sa_handler;
88040 }
88041
88042-static int sig_handler_ignored(void __user *handler, int sig)
88043+static int sig_handler_ignored(__sighandler_t handler, int sig)
88044 {
88045 /* Is it explicitly or implicitly ignored? */
88046 return handler == SIG_IGN ||
88047@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
88048
88049 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
88050 {
88051- void __user *handler;
88052+ __sighandler_t handler;
88053
88054 handler = sig_handler(t, sig);
88055
88056@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
88057 atomic_inc(&user->sigpending);
88058 rcu_read_unlock();
88059
88060+ if (!override_rlimit)
88061+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
88062+
88063 if (override_rlimit ||
88064 atomic_read(&user->sigpending) <=
88065 task_rlimit(t, RLIMIT_SIGPENDING)) {
88066@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
88067
88068 int unhandled_signal(struct task_struct *tsk, int sig)
88069 {
88070- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
88071+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
88072 if (is_global_init(tsk))
88073 return 1;
88074 if (handler != SIG_IGN && handler != SIG_DFL)
88075@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
88076 }
88077 }
88078
88079+ /* allow glibc communication via tgkill to other threads in our
88080+ thread group */
88081+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
88082+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
88083+ && gr_handle_signal(t, sig))
88084+ return -EPERM;
88085+
88086 return security_task_kill(t, info, sig, 0);
88087 }
88088
88089@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
88090 return send_signal(sig, info, p, 1);
88091 }
88092
88093-static int
88094+int
88095 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
88096 {
88097 return send_signal(sig, info, t, 0);
88098@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
88099 unsigned long int flags;
88100 int ret, blocked, ignored;
88101 struct k_sigaction *action;
88102+ int is_unhandled = 0;
88103
88104 spin_lock_irqsave(&t->sighand->siglock, flags);
88105 action = &t->sighand->action[sig-1];
88106@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
88107 }
88108 if (action->sa.sa_handler == SIG_DFL)
88109 t->signal->flags &= ~SIGNAL_UNKILLABLE;
88110+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
88111+ is_unhandled = 1;
88112 ret = specific_send_sig_info(sig, info, t);
88113 spin_unlock_irqrestore(&t->sighand->siglock, flags);
88114
88115+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
88116+ normal operation */
88117+ if (is_unhandled) {
88118+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
88119+ gr_handle_crash(t, sig);
88120+ }
88121+
88122 return ret;
88123 }
88124
88125@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
88126 ret = check_kill_permission(sig, info, p);
88127 rcu_read_unlock();
88128
88129- if (!ret && sig)
88130+ if (!ret && sig) {
88131 ret = do_send_sig_info(sig, info, p, true);
88132+ if (!ret)
88133+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
88134+ }
88135
88136 return ret;
88137 }
88138@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
88139 int error = -ESRCH;
88140
88141 rcu_read_lock();
88142- p = find_task_by_vpid(pid);
88143+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
88144+ /* allow glibc communication via tgkill to other threads in our
88145+ thread group */
88146+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
88147+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
88148+ p = find_task_by_vpid_unrestricted(pid);
88149+ else
88150+#endif
88151+ p = find_task_by_vpid(pid);
88152 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
88153 error = check_kill_permission(sig, info, p);
88154 /*
88155@@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
88156 }
88157 seg = get_fs();
88158 set_fs(KERNEL_DS);
88159- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
88160- (stack_t __force __user *) &uoss,
88161+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
88162+ (stack_t __force_user *) &uoss,
88163 compat_user_stack_pointer());
88164 set_fs(seg);
88165 if (ret >= 0 && uoss_ptr) {
88166diff --git a/kernel/smpboot.c b/kernel/smpboot.c
88167index eb89e18..a4e6792 100644
88168--- a/kernel/smpboot.c
88169+++ b/kernel/smpboot.c
88170@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
88171 }
88172 smpboot_unpark_thread(plug_thread, cpu);
88173 }
88174- list_add(&plug_thread->list, &hotplug_threads);
88175+ pax_list_add(&plug_thread->list, &hotplug_threads);
88176 out:
88177 mutex_unlock(&smpboot_threads_lock);
88178 return ret;
88179@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
88180 {
88181 get_online_cpus();
88182 mutex_lock(&smpboot_threads_lock);
88183- list_del(&plug_thread->list);
88184+ pax_list_del(&plug_thread->list);
88185 smpboot_destroy_threads(plug_thread);
88186 mutex_unlock(&smpboot_threads_lock);
88187 put_online_cpus();
88188diff --git a/kernel/softirq.c b/kernel/softirq.c
88189index 11025cc..bc0e4dc 100644
88190--- a/kernel/softirq.c
88191+++ b/kernel/softirq.c
88192@@ -50,11 +50,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
88193 EXPORT_SYMBOL(irq_stat);
88194 #endif
88195
88196-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
88197+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
88198
88199 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
88200
88201-char *softirq_to_name[NR_SOFTIRQS] = {
88202+const char * const softirq_to_name[NR_SOFTIRQS] = {
88203 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
88204 "TASKLET", "SCHED", "HRTIMER", "RCU"
88205 };
88206@@ -250,7 +250,7 @@ restart:
88207 kstat_incr_softirqs_this_cpu(vec_nr);
88208
88209 trace_softirq_entry(vec_nr);
88210- h->action(h);
88211+ h->action();
88212 trace_softirq_exit(vec_nr);
88213 if (unlikely(prev_count != preempt_count())) {
88214 printk(KERN_ERR "huh, entered softirq %u %s %p"
88215@@ -419,7 +419,7 @@ void __raise_softirq_irqoff(unsigned int nr)
88216 or_softirq_pending(1UL << nr);
88217 }
88218
88219-void open_softirq(int nr, void (*action)(struct softirq_action *))
88220+void __init open_softirq(int nr, void (*action)(void))
88221 {
88222 softirq_vec[nr].action = action;
88223 }
88224@@ -475,7 +475,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
88225
88226 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
88227
88228-static void tasklet_action(struct softirq_action *a)
88229+static __latent_entropy void tasklet_action(void)
88230 {
88231 struct tasklet_struct *list;
88232
88233@@ -510,7 +510,7 @@ static void tasklet_action(struct softirq_action *a)
88234 }
88235 }
88236
88237-static void tasklet_hi_action(struct softirq_action *a)
88238+static __latent_entropy void tasklet_hi_action(void)
88239 {
88240 struct tasklet_struct *list;
88241
88242@@ -740,7 +740,7 @@ static struct notifier_block cpu_nfb = {
88243 .notifier_call = cpu_callback
88244 };
88245
88246-static struct smp_hotplug_thread softirq_threads = {
88247+static struct smp_hotplug_thread softirq_threads __read_only = {
88248 .store = &ksoftirqd,
88249 .thread_should_run = ksoftirqd_should_run,
88250 .thread_fn = run_ksoftirqd,
88251diff --git a/kernel/sys.c b/kernel/sys.c
88252index c723113..46bf922 100644
88253--- a/kernel/sys.c
88254+++ b/kernel/sys.c
88255@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
88256 error = -EACCES;
88257 goto out;
88258 }
88259+
88260+ if (gr_handle_chroot_setpriority(p, niceval)) {
88261+ error = -EACCES;
88262+ goto out;
88263+ }
88264+
88265 no_nice = security_task_setnice(p, niceval);
88266 if (no_nice) {
88267 error = no_nice;
88268@@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
88269 goto error;
88270 }
88271
88272+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
88273+ goto error;
88274+
88275 if (rgid != (gid_t) -1 ||
88276 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
88277 new->sgid = new->egid;
88278@@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
88279 old = current_cred();
88280
88281 retval = -EPERM;
88282+
88283+ if (gr_check_group_change(kgid, kgid, kgid))
88284+ goto error;
88285+
88286 if (ns_capable(old->user_ns, CAP_SETGID))
88287 new->gid = new->egid = new->sgid = new->fsgid = kgid;
88288 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
88289@@ -403,7 +416,7 @@ error:
88290 /*
88291 * change the user struct in a credentials set to match the new UID
88292 */
88293-static int set_user(struct cred *new)
88294+int set_user(struct cred *new)
88295 {
88296 struct user_struct *new_user;
88297
88298@@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
88299 goto error;
88300 }
88301
88302+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
88303+ goto error;
88304+
88305 if (!uid_eq(new->uid, old->uid)) {
88306 retval = set_user(new);
88307 if (retval < 0)
88308@@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
88309 old = current_cred();
88310
88311 retval = -EPERM;
88312+
88313+ if (gr_check_crash_uid(kuid))
88314+ goto error;
88315+ if (gr_check_user_change(kuid, kuid, kuid))
88316+ goto error;
88317+
88318 if (ns_capable(old->user_ns, CAP_SETUID)) {
88319 new->suid = new->uid = kuid;
88320 if (!uid_eq(kuid, old->uid)) {
88321@@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
88322 goto error;
88323 }
88324
88325+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
88326+ goto error;
88327+
88328 if (ruid != (uid_t) -1) {
88329 new->uid = kruid;
88330 if (!uid_eq(kruid, old->uid)) {
88331@@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
88332 goto error;
88333 }
88334
88335+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
88336+ goto error;
88337+
88338 if (rgid != (gid_t) -1)
88339 new->gid = krgid;
88340 if (egid != (gid_t) -1)
88341@@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
88342 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
88343 ns_capable(old->user_ns, CAP_SETUID)) {
88344 if (!uid_eq(kuid, old->fsuid)) {
88345+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
88346+ goto error;
88347+
88348 new->fsuid = kuid;
88349 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
88350 goto change_okay;
88351 }
88352 }
88353
88354+error:
88355 abort_creds(new);
88356 return old_fsuid;
88357
88358@@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
88359 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
88360 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
88361 ns_capable(old->user_ns, CAP_SETGID)) {
88362+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
88363+ goto error;
88364+
88365 if (!gid_eq(kgid, old->fsgid)) {
88366 new->fsgid = kgid;
88367 goto change_okay;
88368 }
88369 }
88370
88371+error:
88372 abort_creds(new);
88373 return old_fsgid;
88374
88375@@ -1168,19 +1204,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
88376 return -EFAULT;
88377
88378 down_read(&uts_sem);
88379- error = __copy_to_user(&name->sysname, &utsname()->sysname,
88380+ error = __copy_to_user(name->sysname, &utsname()->sysname,
88381 __OLD_UTS_LEN);
88382 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
88383- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
88384+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
88385 __OLD_UTS_LEN);
88386 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
88387- error |= __copy_to_user(&name->release, &utsname()->release,
88388+ error |= __copy_to_user(name->release, &utsname()->release,
88389 __OLD_UTS_LEN);
88390 error |= __put_user(0, name->release + __OLD_UTS_LEN);
88391- error |= __copy_to_user(&name->version, &utsname()->version,
88392+ error |= __copy_to_user(name->version, &utsname()->version,
88393 __OLD_UTS_LEN);
88394 error |= __put_user(0, name->version + __OLD_UTS_LEN);
88395- error |= __copy_to_user(&name->machine, &utsname()->machine,
88396+ error |= __copy_to_user(name->machine, &utsname()->machine,
88397 __OLD_UTS_LEN);
88398 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
88399 up_read(&uts_sem);
88400@@ -1382,6 +1418,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
88401 */
88402 new_rlim->rlim_cur = 1;
88403 }
88404+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
88405+ is changed to a lower value. Since tasks can be created by the same
88406+ user in between this limit change and an execve by this task, force
88407+ a recheck only for this task by setting PF_NPROC_EXCEEDED
88408+ */
88409+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
88410+ tsk->flags |= PF_NPROC_EXCEEDED;
88411 }
88412 if (!retval) {
88413 if (old_rlim)
88414diff --git a/kernel/sysctl.c b/kernel/sysctl.c
88415index 34a6047..5665aa7 100644
88416--- a/kernel/sysctl.c
88417+++ b/kernel/sysctl.c
88418@@ -93,7 +93,6 @@
88419
88420
88421 #if defined(CONFIG_SYSCTL)
88422-
88423 /* External variables not in a header file. */
88424 extern int sysctl_overcommit_memory;
88425 extern int sysctl_overcommit_ratio;
88426@@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
88427
88428 /* Constants used for minimum and maximum */
88429 #ifdef CONFIG_LOCKUP_DETECTOR
88430-static int sixty = 60;
88431+static int sixty __read_only = 60;
88432 #endif
88433
88434-static int zero;
88435-static int __maybe_unused one = 1;
88436-static int __maybe_unused two = 2;
88437-static int __maybe_unused three = 3;
88438-static unsigned long one_ul = 1;
88439-static int one_hundred = 100;
88440+static int neg_one __read_only = -1;
88441+static int zero __read_only = 0;
88442+static int __maybe_unused one __read_only = 1;
88443+static int __maybe_unused two __read_only = 2;
88444+static int __maybe_unused three __read_only = 3;
88445+static unsigned long one_ul __read_only = 1;
88446+static int one_hundred __read_only = 100;
88447 #ifdef CONFIG_PRINTK
88448-static int ten_thousand = 10000;
88449+static int ten_thousand __read_only = 10000;
88450 #endif
88451
88452 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
88453@@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
88454 void __user *buffer, size_t *lenp, loff_t *ppos);
88455 #endif
88456
88457-#ifdef CONFIG_PRINTK
88458 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
88459 void __user *buffer, size_t *lenp, loff_t *ppos);
88460-#endif
88461
88462 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
88463 void __user *buffer, size_t *lenp, loff_t *ppos);
88464@@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
88465
88466 #endif
88467
88468+extern struct ctl_table grsecurity_table[];
88469+
88470 static struct ctl_table kern_table[];
88471 static struct ctl_table vm_table[];
88472 static struct ctl_table fs_table[];
88473@@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
88474 int sysctl_legacy_va_layout;
88475 #endif
88476
88477+#ifdef CONFIG_PAX_SOFTMODE
88478+static ctl_table pax_table[] = {
88479+ {
88480+ .procname = "softmode",
88481+ .data = &pax_softmode,
88482+ .maxlen = sizeof(unsigned int),
88483+ .mode = 0600,
88484+ .proc_handler = &proc_dointvec,
88485+ },
88486+
88487+ { }
88488+};
88489+#endif
88490+
88491 /* The default sysctl tables: */
88492
88493 static struct ctl_table sysctl_base_table[] = {
88494@@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
88495 #endif
88496
88497 static struct ctl_table kern_table[] = {
88498+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
88499+ {
88500+ .procname = "grsecurity",
88501+ .mode = 0500,
88502+ .child = grsecurity_table,
88503+ },
88504+#endif
88505+
88506+#ifdef CONFIG_PAX_SOFTMODE
88507+ {
88508+ .procname = "pax",
88509+ .mode = 0500,
88510+ .child = pax_table,
88511+ },
88512+#endif
88513+
88514 {
88515 .procname = "sched_child_runs_first",
88516 .data = &sysctl_sched_child_runs_first,
88517@@ -620,7 +650,7 @@ static struct ctl_table kern_table[] = {
88518 .data = &modprobe_path,
88519 .maxlen = KMOD_PATH_LEN,
88520 .mode = 0644,
88521- .proc_handler = proc_dostring,
88522+ .proc_handler = proc_dostring_modpriv,
88523 },
88524 {
88525 .procname = "modules_disabled",
88526@@ -787,16 +817,20 @@ static struct ctl_table kern_table[] = {
88527 .extra1 = &zero,
88528 .extra2 = &one,
88529 },
88530+#endif
88531 {
88532 .procname = "kptr_restrict",
88533 .data = &kptr_restrict,
88534 .maxlen = sizeof(int),
88535 .mode = 0644,
88536 .proc_handler = proc_dointvec_minmax_sysadmin,
88537+#ifdef CONFIG_GRKERNSEC_HIDESYM
88538+ .extra1 = &two,
88539+#else
88540 .extra1 = &zero,
88541+#endif
88542 .extra2 = &two,
88543 },
88544-#endif
88545 {
88546 .procname = "ngroups_max",
88547 .data = &ngroups_max,
88548@@ -1039,10 +1073,17 @@ static struct ctl_table kern_table[] = {
88549 */
88550 {
88551 .procname = "perf_event_paranoid",
88552- .data = &sysctl_perf_event_paranoid,
88553- .maxlen = sizeof(sysctl_perf_event_paranoid),
88554+ .data = &sysctl_perf_event_legitimately_concerned,
88555+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
88556 .mode = 0644,
88557- .proc_handler = proc_dointvec,
88558+ /* go ahead, be a hero */
88559+ .proc_handler = proc_dointvec_minmax_sysadmin,
88560+ .extra1 = &neg_one,
88561+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
88562+ .extra2 = &three,
88563+#else
88564+ .extra2 = &two,
88565+#endif
88566 },
88567 {
88568 .procname = "perf_event_mlock_kb",
88569@@ -1306,6 +1347,13 @@ static struct ctl_table vm_table[] = {
88570 .proc_handler = proc_dointvec_minmax,
88571 .extra1 = &zero,
88572 },
88573+ {
88574+ .procname = "heap_stack_gap",
88575+ .data = &sysctl_heap_stack_gap,
88576+ .maxlen = sizeof(sysctl_heap_stack_gap),
88577+ .mode = 0644,
88578+ .proc_handler = proc_doulongvec_minmax,
88579+ },
88580 #else
88581 {
88582 .procname = "nr_trim_pages",
88583@@ -1770,6 +1818,16 @@ int proc_dostring(struct ctl_table *table, int write,
88584 buffer, lenp, ppos);
88585 }
88586
88587+int proc_dostring_modpriv(struct ctl_table *table, int write,
88588+ void __user *buffer, size_t *lenp, loff_t *ppos)
88589+{
88590+ if (write && !capable(CAP_SYS_MODULE))
88591+ return -EPERM;
88592+
88593+ return _proc_do_string(table->data, table->maxlen, write,
88594+ buffer, lenp, ppos);
88595+}
88596+
88597 static size_t proc_skip_spaces(char **buf)
88598 {
88599 size_t ret;
88600@@ -1875,6 +1933,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
88601 len = strlen(tmp);
88602 if (len > *size)
88603 len = *size;
88604+ if (len > sizeof(tmp))
88605+ len = sizeof(tmp);
88606 if (copy_to_user(*buf, tmp, len))
88607 return -EFAULT;
88608 *size -= len;
88609@@ -2039,7 +2099,7 @@ int proc_dointvec(struct ctl_table *table, int write,
88610 static int proc_taint(struct ctl_table *table, int write,
88611 void __user *buffer, size_t *lenp, loff_t *ppos)
88612 {
88613- struct ctl_table t;
88614+ ctl_table_no_const t;
88615 unsigned long tmptaint = get_taint();
88616 int err;
88617
88618@@ -2067,7 +2127,6 @@ static int proc_taint(struct ctl_table *table, int write,
88619 return err;
88620 }
88621
88622-#ifdef CONFIG_PRINTK
88623 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
88624 void __user *buffer, size_t *lenp, loff_t *ppos)
88625 {
88626@@ -2076,7 +2135,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
88627
88628 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
88629 }
88630-#endif
88631
88632 struct do_proc_dointvec_minmax_conv_param {
88633 int *min;
88634@@ -2623,6 +2681,12 @@ int proc_dostring(struct ctl_table *table, int write,
88635 return -ENOSYS;
88636 }
88637
88638+int proc_dostring_modpriv(struct ctl_table *table, int write,
88639+ void __user *buffer, size_t *lenp, loff_t *ppos)
88640+{
88641+ return -ENOSYS;
88642+}
88643+
88644 int proc_dointvec(struct ctl_table *table, int write,
88645 void __user *buffer, size_t *lenp, loff_t *ppos)
88646 {
88647@@ -2679,5 +2743,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
88648 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
88649 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
88650 EXPORT_SYMBOL(proc_dostring);
88651+EXPORT_SYMBOL(proc_dostring_modpriv);
88652 EXPORT_SYMBOL(proc_doulongvec_minmax);
88653 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
88654diff --git a/kernel/taskstats.c b/kernel/taskstats.c
88655index 13d2f7c..c93d0b0 100644
88656--- a/kernel/taskstats.c
88657+++ b/kernel/taskstats.c
88658@@ -28,9 +28,12 @@
88659 #include <linux/fs.h>
88660 #include <linux/file.h>
88661 #include <linux/pid_namespace.h>
88662+#include <linux/grsecurity.h>
88663 #include <net/genetlink.h>
88664 #include <linux/atomic.h>
88665
88666+extern int gr_is_taskstats_denied(int pid);
88667+
88668 /*
88669 * Maximum length of a cpumask that can be specified in
88670 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
88671@@ -576,6 +579,9 @@ err:
88672
88673 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
88674 {
88675+ if (gr_is_taskstats_denied(current->pid))
88676+ return -EACCES;
88677+
88678 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
88679 return cmd_attr_register_cpumask(info);
88680 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
88681diff --git a/kernel/time.c b/kernel/time.c
88682index 7c7964c..2a0d412 100644
88683--- a/kernel/time.c
88684+++ b/kernel/time.c
88685@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
88686 return error;
88687
88688 if (tz) {
88689+ /* we log in do_settimeofday called below, so don't log twice
88690+ */
88691+ if (!tv)
88692+ gr_log_timechange();
88693+
88694 sys_tz = *tz;
88695 update_vsyscall_tz();
88696 if (firsttime) {
88697diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
88698index 88c9c65..7497ebc 100644
88699--- a/kernel/time/alarmtimer.c
88700+++ b/kernel/time/alarmtimer.c
88701@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
88702 struct platform_device *pdev;
88703 int error = 0;
88704 int i;
88705- struct k_clock alarm_clock = {
88706+ static struct k_clock alarm_clock = {
88707 .clock_getres = alarm_clock_getres,
88708 .clock_get = alarm_clock_get,
88709 .timer_create = alarm_timer_create,
88710diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
88711index 87b4f00..b7f77a7 100644
88712--- a/kernel/time/timekeeping.c
88713+++ b/kernel/time/timekeeping.c
88714@@ -15,6 +15,7 @@
88715 #include <linux/init.h>
88716 #include <linux/mm.h>
88717 #include <linux/sched.h>
88718+#include <linux/grsecurity.h>
88719 #include <linux/syscore_ops.h>
88720 #include <linux/clocksource.h>
88721 #include <linux/jiffies.h>
88722@@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
88723 if (!timespec_valid_strict(tv))
88724 return -EINVAL;
88725
88726+ gr_log_timechange();
88727+
88728 raw_spin_lock_irqsave(&timekeeper_lock, flags);
88729 write_seqcount_begin(&timekeeper_seq);
88730
88731diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
88732index 61ed862..3b52c65 100644
88733--- a/kernel/time/timer_list.c
88734+++ b/kernel/time/timer_list.c
88735@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
88736
88737 static void print_name_offset(struct seq_file *m, void *sym)
88738 {
88739+#ifdef CONFIG_GRKERNSEC_HIDESYM
88740+ SEQ_printf(m, "<%p>", NULL);
88741+#else
88742 char symname[KSYM_NAME_LEN];
88743
88744 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
88745 SEQ_printf(m, "<%pK>", sym);
88746 else
88747 SEQ_printf(m, "%s", symname);
88748+#endif
88749 }
88750
88751 static void
88752@@ -119,7 +123,11 @@ next_one:
88753 static void
88754 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
88755 {
88756+#ifdef CONFIG_GRKERNSEC_HIDESYM
88757+ SEQ_printf(m, " .base: %p\n", NULL);
88758+#else
88759 SEQ_printf(m, " .base: %pK\n", base);
88760+#endif
88761 SEQ_printf(m, " .index: %d\n",
88762 base->index);
88763 SEQ_printf(m, " .resolution: %Lu nsecs\n",
88764@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
88765 {
88766 struct proc_dir_entry *pe;
88767
88768+#ifdef CONFIG_GRKERNSEC_PROC_ADD
88769+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
88770+#else
88771 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
88772+#endif
88773 if (!pe)
88774 return -ENOMEM;
88775 return 0;
88776diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
88777index 1fb08f2..ca4bb1e 100644
88778--- a/kernel/time/timer_stats.c
88779+++ b/kernel/time/timer_stats.c
88780@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
88781 static unsigned long nr_entries;
88782 static struct entry entries[MAX_ENTRIES];
88783
88784-static atomic_t overflow_count;
88785+static atomic_unchecked_t overflow_count;
88786
88787 /*
88788 * The entries are in a hash-table, for fast lookup:
88789@@ -140,7 +140,7 @@ static void reset_entries(void)
88790 nr_entries = 0;
88791 memset(entries, 0, sizeof(entries));
88792 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
88793- atomic_set(&overflow_count, 0);
88794+ atomic_set_unchecked(&overflow_count, 0);
88795 }
88796
88797 static struct entry *alloc_entry(void)
88798@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
88799 if (likely(entry))
88800 entry->count++;
88801 else
88802- atomic_inc(&overflow_count);
88803+ atomic_inc_unchecked(&overflow_count);
88804
88805 out_unlock:
88806 raw_spin_unlock_irqrestore(lock, flags);
88807@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
88808
88809 static void print_name_offset(struct seq_file *m, unsigned long addr)
88810 {
88811+#ifdef CONFIG_GRKERNSEC_HIDESYM
88812+ seq_printf(m, "<%p>", NULL);
88813+#else
88814 char symname[KSYM_NAME_LEN];
88815
88816 if (lookup_symbol_name(addr, symname) < 0)
88817- seq_printf(m, "<%p>", (void *)addr);
88818+ seq_printf(m, "<%pK>", (void *)addr);
88819 else
88820 seq_printf(m, "%s", symname);
88821+#endif
88822 }
88823
88824 static int tstats_show(struct seq_file *m, void *v)
88825@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
88826
88827 seq_puts(m, "Timer Stats Version: v0.3\n");
88828 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
88829- if (atomic_read(&overflow_count))
88830- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
88831+ if (atomic_read_unchecked(&overflow_count))
88832+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
88833 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
88834
88835 for (i = 0; i < nr_entries; i++) {
88836@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
88837 {
88838 struct proc_dir_entry *pe;
88839
88840+#ifdef CONFIG_GRKERNSEC_PROC_ADD
88841+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
88842+#else
88843 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
88844+#endif
88845 if (!pe)
88846 return -ENOMEM;
88847 return 0;
88848diff --git a/kernel/timer.c b/kernel/timer.c
88849index accfd24..e00f0c0 100644
88850--- a/kernel/timer.c
88851+++ b/kernel/timer.c
88852@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
88853 /*
88854 * This function runs timers and the timer-tq in bottom half context.
88855 */
88856-static void run_timer_softirq(struct softirq_action *h)
88857+static __latent_entropy void run_timer_softirq(void)
88858 {
88859 struct tvec_base *base = __this_cpu_read(tvec_bases);
88860
88861@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
88862 *
88863 * In all cases the return value is guaranteed to be non-negative.
88864 */
88865-signed long __sched schedule_timeout(signed long timeout)
88866+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
88867 {
88868 struct timer_list timer;
88869 unsigned long expire;
88870diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
88871index f785aef..59f1b18 100644
88872--- a/kernel/trace/blktrace.c
88873+++ b/kernel/trace/blktrace.c
88874@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
88875 struct blk_trace *bt = filp->private_data;
88876 char buf[16];
88877
88878- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
88879+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
88880
88881 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
88882 }
88883@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
88884 return 1;
88885
88886 bt = buf->chan->private_data;
88887- atomic_inc(&bt->dropped);
88888+ atomic_inc_unchecked(&bt->dropped);
88889 return 0;
88890 }
88891
88892@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
88893
88894 bt->dir = dir;
88895 bt->dev = dev;
88896- atomic_set(&bt->dropped, 0);
88897+ atomic_set_unchecked(&bt->dropped, 0);
88898 INIT_LIST_HEAD(&bt->running_list);
88899
88900 ret = -EIO;
88901diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
88902index 72a0f81..0bbfd090 100644
88903--- a/kernel/trace/ftrace.c
88904+++ b/kernel/trace/ftrace.c
88905@@ -1944,12 +1944,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
88906 if (unlikely(ftrace_disabled))
88907 return 0;
88908
88909+ ret = ftrace_arch_code_modify_prepare();
88910+ FTRACE_WARN_ON(ret);
88911+ if (ret)
88912+ return 0;
88913+
88914 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
88915+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
88916 if (ret) {
88917 ftrace_bug(ret, ip);
88918- return 0;
88919 }
88920- return 1;
88921+ return ret ? 0 : 1;
88922 }
88923
88924 /*
88925@@ -4119,8 +4124,10 @@ static int ftrace_process_locs(struct module *mod,
88926 if (!count)
88927 return 0;
88928
88929+ pax_open_kernel();
88930 sort(start, count, sizeof(*start),
88931 ftrace_cmp_ips, ftrace_swap_ips);
88932+ pax_close_kernel();
88933
88934 start_pg = ftrace_allocate_pages(count);
88935 if (!start_pg)
88936@@ -4851,8 +4858,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
88937 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
88938
88939 static int ftrace_graph_active;
88940-static struct notifier_block ftrace_suspend_notifier;
88941-
88942 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
88943 {
88944 return 0;
88945@@ -5003,6 +5008,10 @@ static struct ftrace_ops fgraph_ops __read_mostly = {
88946 FTRACE_OPS_FL_RECURSION_SAFE,
88947 };
88948
88949+static struct notifier_block ftrace_suspend_notifier = {
88950+ .notifier_call = ftrace_suspend_notifier_call
88951+};
88952+
88953 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
88954 trace_func_graph_ent_t entryfunc)
88955 {
88956@@ -5016,7 +5025,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
88957 goto out;
88958 }
88959
88960- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
88961 register_pm_notifier(&ftrace_suspend_notifier);
88962
88963 ftrace_graph_active++;
88964diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
88965index cc2f66f..05edd54 100644
88966--- a/kernel/trace/ring_buffer.c
88967+++ b/kernel/trace/ring_buffer.c
88968@@ -352,9 +352,9 @@ struct buffer_data_page {
88969 */
88970 struct buffer_page {
88971 struct list_head list; /* list of buffer pages */
88972- local_t write; /* index for next write */
88973+ local_unchecked_t write; /* index for next write */
88974 unsigned read; /* index for next read */
88975- local_t entries; /* entries on this page */
88976+ local_unchecked_t entries; /* entries on this page */
88977 unsigned long real_end; /* real end of data */
88978 struct buffer_data_page *page; /* Actual data page */
88979 };
88980@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
88981 unsigned long last_overrun;
88982 local_t entries_bytes;
88983 local_t entries;
88984- local_t overrun;
88985- local_t commit_overrun;
88986+ local_unchecked_t overrun;
88987+ local_unchecked_t commit_overrun;
88988 local_t dropped_events;
88989 local_t committing;
88990 local_t commits;
88991@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
88992 *
88993 * We add a counter to the write field to denote this.
88994 */
88995- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
88996- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
88997+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
88998+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
88999
89000 /*
89001 * Just make sure we have seen our old_write and synchronize
89002@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
89003 * cmpxchg to only update if an interrupt did not already
89004 * do it for us. If the cmpxchg fails, we don't care.
89005 */
89006- (void)local_cmpxchg(&next_page->write, old_write, val);
89007- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
89008+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
89009+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
89010
89011 /*
89012 * No need to worry about races with clearing out the commit.
89013@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
89014
89015 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
89016 {
89017- return local_read(&bpage->entries) & RB_WRITE_MASK;
89018+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
89019 }
89020
89021 static inline unsigned long rb_page_write(struct buffer_page *bpage)
89022 {
89023- return local_read(&bpage->write) & RB_WRITE_MASK;
89024+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
89025 }
89026
89027 static int
89028@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
89029 * bytes consumed in ring buffer from here.
89030 * Increment overrun to account for the lost events.
89031 */
89032- local_add(page_entries, &cpu_buffer->overrun);
89033+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
89034 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
89035 }
89036
89037@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
89038 * it is our responsibility to update
89039 * the counters.
89040 */
89041- local_add(entries, &cpu_buffer->overrun);
89042+ local_add_unchecked(entries, &cpu_buffer->overrun);
89043 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
89044
89045 /*
89046@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
89047 if (tail == BUF_PAGE_SIZE)
89048 tail_page->real_end = 0;
89049
89050- local_sub(length, &tail_page->write);
89051+ local_sub_unchecked(length, &tail_page->write);
89052 return;
89053 }
89054
89055@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
89056 rb_event_set_padding(event);
89057
89058 /* Set the write back to the previous setting */
89059- local_sub(length, &tail_page->write);
89060+ local_sub_unchecked(length, &tail_page->write);
89061 return;
89062 }
89063
89064@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
89065
89066 /* Set write to end of buffer */
89067 length = (tail + length) - BUF_PAGE_SIZE;
89068- local_sub(length, &tail_page->write);
89069+ local_sub_unchecked(length, &tail_page->write);
89070 }
89071
89072 /*
89073@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
89074 * about it.
89075 */
89076 if (unlikely(next_page == commit_page)) {
89077- local_inc(&cpu_buffer->commit_overrun);
89078+ local_inc_unchecked(&cpu_buffer->commit_overrun);
89079 goto out_reset;
89080 }
89081
89082@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
89083 cpu_buffer->tail_page) &&
89084 (cpu_buffer->commit_page ==
89085 cpu_buffer->reader_page))) {
89086- local_inc(&cpu_buffer->commit_overrun);
89087+ local_inc_unchecked(&cpu_buffer->commit_overrun);
89088 goto out_reset;
89089 }
89090 }
89091@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
89092 length += RB_LEN_TIME_EXTEND;
89093
89094 tail_page = cpu_buffer->tail_page;
89095- write = local_add_return(length, &tail_page->write);
89096+ write = local_add_return_unchecked(length, &tail_page->write);
89097
89098 /* set write to only the index of the write */
89099 write &= RB_WRITE_MASK;
89100@@ -2408,7 +2408,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
89101 kmemcheck_annotate_bitfield(event, bitfield);
89102 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
89103
89104- local_inc(&tail_page->entries);
89105+ local_inc_unchecked(&tail_page->entries);
89106
89107 /*
89108 * If this is the first commit on the page, then update
89109@@ -2441,7 +2441,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
89110
89111 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
89112 unsigned long write_mask =
89113- local_read(&bpage->write) & ~RB_WRITE_MASK;
89114+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
89115 unsigned long event_length = rb_event_length(event);
89116 /*
89117 * This is on the tail page. It is possible that
89118@@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
89119 */
89120 old_index += write_mask;
89121 new_index += write_mask;
89122- index = local_cmpxchg(&bpage->write, old_index, new_index);
89123+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
89124 if (index == old_index) {
89125 /* update counters */
89126 local_sub(event_length, &cpu_buffer->entries_bytes);
89127@@ -2843,7 +2843,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
89128
89129 /* Do the likely case first */
89130 if (likely(bpage->page == (void *)addr)) {
89131- local_dec(&bpage->entries);
89132+ local_dec_unchecked(&bpage->entries);
89133 return;
89134 }
89135
89136@@ -2855,7 +2855,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
89137 start = bpage;
89138 do {
89139 if (bpage->page == (void *)addr) {
89140- local_dec(&bpage->entries);
89141+ local_dec_unchecked(&bpage->entries);
89142 return;
89143 }
89144 rb_inc_page(cpu_buffer, &bpage);
89145@@ -3139,7 +3139,7 @@ static inline unsigned long
89146 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
89147 {
89148 return local_read(&cpu_buffer->entries) -
89149- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
89150+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
89151 }
89152
89153 /**
89154@@ -3228,7 +3228,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
89155 return 0;
89156
89157 cpu_buffer = buffer->buffers[cpu];
89158- ret = local_read(&cpu_buffer->overrun);
89159+ ret = local_read_unchecked(&cpu_buffer->overrun);
89160
89161 return ret;
89162 }
89163@@ -3251,7 +3251,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
89164 return 0;
89165
89166 cpu_buffer = buffer->buffers[cpu];
89167- ret = local_read(&cpu_buffer->commit_overrun);
89168+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
89169
89170 return ret;
89171 }
89172@@ -3336,7 +3336,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
89173 /* if you care about this being correct, lock the buffer */
89174 for_each_buffer_cpu(buffer, cpu) {
89175 cpu_buffer = buffer->buffers[cpu];
89176- overruns += local_read(&cpu_buffer->overrun);
89177+ overruns += local_read_unchecked(&cpu_buffer->overrun);
89178 }
89179
89180 return overruns;
89181@@ -3512,8 +3512,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
89182 /*
89183 * Reset the reader page to size zero.
89184 */
89185- local_set(&cpu_buffer->reader_page->write, 0);
89186- local_set(&cpu_buffer->reader_page->entries, 0);
89187+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
89188+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
89189 local_set(&cpu_buffer->reader_page->page->commit, 0);
89190 cpu_buffer->reader_page->real_end = 0;
89191
89192@@ -3547,7 +3547,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
89193 * want to compare with the last_overrun.
89194 */
89195 smp_mb();
89196- overwrite = local_read(&(cpu_buffer->overrun));
89197+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
89198
89199 /*
89200 * Here's the tricky part.
89201@@ -4117,8 +4117,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
89202
89203 cpu_buffer->head_page
89204 = list_entry(cpu_buffer->pages, struct buffer_page, list);
89205- local_set(&cpu_buffer->head_page->write, 0);
89206- local_set(&cpu_buffer->head_page->entries, 0);
89207+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
89208+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
89209 local_set(&cpu_buffer->head_page->page->commit, 0);
89210
89211 cpu_buffer->head_page->read = 0;
89212@@ -4128,14 +4128,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
89213
89214 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
89215 INIT_LIST_HEAD(&cpu_buffer->new_pages);
89216- local_set(&cpu_buffer->reader_page->write, 0);
89217- local_set(&cpu_buffer->reader_page->entries, 0);
89218+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
89219+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
89220 local_set(&cpu_buffer->reader_page->page->commit, 0);
89221 cpu_buffer->reader_page->read = 0;
89222
89223 local_set(&cpu_buffer->entries_bytes, 0);
89224- local_set(&cpu_buffer->overrun, 0);
89225- local_set(&cpu_buffer->commit_overrun, 0);
89226+ local_set_unchecked(&cpu_buffer->overrun, 0);
89227+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
89228 local_set(&cpu_buffer->dropped_events, 0);
89229 local_set(&cpu_buffer->entries, 0);
89230 local_set(&cpu_buffer->committing, 0);
89231@@ -4540,8 +4540,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
89232 rb_init_page(bpage);
89233 bpage = reader->page;
89234 reader->page = *data_page;
89235- local_set(&reader->write, 0);
89236- local_set(&reader->entries, 0);
89237+ local_set_unchecked(&reader->write, 0);
89238+ local_set_unchecked(&reader->entries, 0);
89239 reader->read = 0;
89240 *data_page = bpage;
89241
89242diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
89243index 9d20cd9..221d816 100644
89244--- a/kernel/trace/trace.c
89245+++ b/kernel/trace/trace.c
89246@@ -3346,7 +3346,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
89247 return 0;
89248 }
89249
89250-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
89251+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
89252 {
89253 /* do nothing if flag is already set */
89254 if (!!(trace_flags & mask) == !!enabled)
89255diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
89256index ea189e0..a5b48c4 100644
89257--- a/kernel/trace/trace.h
89258+++ b/kernel/trace/trace.h
89259@@ -1040,7 +1040,7 @@ extern const char *__stop___tracepoint_str[];
89260 void trace_printk_init_buffers(void);
89261 void trace_printk_start_comm(void);
89262 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
89263-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
89264+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
89265
89266 /*
89267 * Normal trace_printk() and friends allocates special buffers
89268diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
89269index 26dc348..8708ca7 100644
89270--- a/kernel/trace/trace_clock.c
89271+++ b/kernel/trace/trace_clock.c
89272@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
89273 return now;
89274 }
89275
89276-static atomic64_t trace_counter;
89277+static atomic64_unchecked_t trace_counter;
89278
89279 /*
89280 * trace_clock_counter(): simply an atomic counter.
89281@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
89282 */
89283 u64 notrace trace_clock_counter(void)
89284 {
89285- return atomic64_add_return(1, &trace_counter);
89286+ return atomic64_inc_return_unchecked(&trace_counter);
89287 }
89288diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
89289index a11800a..3dafde5 100644
89290--- a/kernel/trace/trace_events.c
89291+++ b/kernel/trace/trace_events.c
89292@@ -1681,7 +1681,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
89293 return 0;
89294 }
89295
89296-struct ftrace_module_file_ops;
89297 static void __add_event_to_tracers(struct ftrace_event_call *call);
89298
89299 /* Add an additional event_call dynamically */
89300diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
89301index 0abd9b8..6a663a2 100644
89302--- a/kernel/trace/trace_mmiotrace.c
89303+++ b/kernel/trace/trace_mmiotrace.c
89304@@ -24,7 +24,7 @@ struct header_iter {
89305 static struct trace_array *mmio_trace_array;
89306 static bool overrun_detected;
89307 static unsigned long prev_overruns;
89308-static atomic_t dropped_count;
89309+static atomic_unchecked_t dropped_count;
89310
89311 static void mmio_reset_data(struct trace_array *tr)
89312 {
89313@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
89314
89315 static unsigned long count_overruns(struct trace_iterator *iter)
89316 {
89317- unsigned long cnt = atomic_xchg(&dropped_count, 0);
89318+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
89319 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
89320
89321 if (over > prev_overruns)
89322@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
89323 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
89324 sizeof(*entry), 0, pc);
89325 if (!event) {
89326- atomic_inc(&dropped_count);
89327+ atomic_inc_unchecked(&dropped_count);
89328 return;
89329 }
89330 entry = ring_buffer_event_data(event);
89331@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
89332 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
89333 sizeof(*entry), 0, pc);
89334 if (!event) {
89335- atomic_inc(&dropped_count);
89336+ atomic_inc_unchecked(&dropped_count);
89337 return;
89338 }
89339 entry = ring_buffer_event_data(event);
89340diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
89341index ed32284..884d6c3 100644
89342--- a/kernel/trace/trace_output.c
89343+++ b/kernel/trace/trace_output.c
89344@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
89345
89346 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
89347 if (!IS_ERR(p)) {
89348- p = mangle_path(s->buffer + s->len, p, "\n");
89349+ p = mangle_path(s->buffer + s->len, p, "\n\\");
89350 if (p) {
89351 s->len = p - s->buffer;
89352 return 1;
89353@@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
89354 goto out;
89355 }
89356
89357+ pax_open_kernel();
89358 if (event->funcs->trace == NULL)
89359- event->funcs->trace = trace_nop_print;
89360+ *(void **)&event->funcs->trace = trace_nop_print;
89361 if (event->funcs->raw == NULL)
89362- event->funcs->raw = trace_nop_print;
89363+ *(void **)&event->funcs->raw = trace_nop_print;
89364 if (event->funcs->hex == NULL)
89365- event->funcs->hex = trace_nop_print;
89366+ *(void **)&event->funcs->hex = trace_nop_print;
89367 if (event->funcs->binary == NULL)
89368- event->funcs->binary = trace_nop_print;
89369+ *(void **)&event->funcs->binary = trace_nop_print;
89370+ pax_close_kernel();
89371
89372 key = event->type & (EVENT_HASHSIZE - 1);
89373
89374diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
89375index b20428c..4845a10 100644
89376--- a/kernel/trace/trace_stack.c
89377+++ b/kernel/trace/trace_stack.c
89378@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
89379 return;
89380
89381 /* we do not handle interrupt stacks yet */
89382- if (!object_is_on_stack(stack))
89383+ if (!object_starts_on_stack(stack))
89384 return;
89385
89386 local_irq_save(flags);
89387diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
89388index 240fb62..583473e 100644
89389--- a/kernel/user_namespace.c
89390+++ b/kernel/user_namespace.c
89391@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
89392 !kgid_has_mapping(parent_ns, group))
89393 return -EPERM;
89394
89395+#ifdef CONFIG_GRKERNSEC
89396+ /*
89397+ * This doesn't really inspire confidence:
89398+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
89399+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
89400+ * Increases kernel attack surface in areas developers
89401+ * previously cared little about ("low importance due
89402+ * to requiring "root" capability")
89403+ * To be removed when this code receives *proper* review
89404+ */
89405+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
89406+ !capable(CAP_SETGID))
89407+ return -EPERM;
89408+#endif
89409+
89410 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
89411 if (!ns)
89412 return -ENOMEM;
89413@@ -866,7 +881,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
89414 if (atomic_read(&current->mm->mm_users) > 1)
89415 return -EINVAL;
89416
89417- if (current->fs->users != 1)
89418+ if (atomic_read(&current->fs->users) != 1)
89419 return -EINVAL;
89420
89421 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
89422diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
89423index 4f69f9a..7c6f8f8 100644
89424--- a/kernel/utsname_sysctl.c
89425+++ b/kernel/utsname_sysctl.c
89426@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
89427 static int proc_do_uts_string(ctl_table *table, int write,
89428 void __user *buffer, size_t *lenp, loff_t *ppos)
89429 {
89430- struct ctl_table uts_table;
89431+ ctl_table_no_const uts_table;
89432 int r;
89433 memcpy(&uts_table, table, sizeof(uts_table));
89434 uts_table.data = get_uts(table, write);
89435diff --git a/kernel/watchdog.c b/kernel/watchdog.c
89436index 4431610..4265616 100644
89437--- a/kernel/watchdog.c
89438+++ b/kernel/watchdog.c
89439@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
89440 static void watchdog_nmi_disable(unsigned int cpu) { return; }
89441 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
89442
89443-static struct smp_hotplug_thread watchdog_threads = {
89444+static struct smp_hotplug_thread watchdog_threads __read_only = {
89445 .store = &softlockup_watchdog,
89446 .thread_should_run = watchdog_should_run,
89447 .thread_fn = watchdog,
89448diff --git a/kernel/workqueue.c b/kernel/workqueue.c
89449index b010eac..e4bda78 100644
89450--- a/kernel/workqueue.c
89451+++ b/kernel/workqueue.c
89452@@ -4671,7 +4671,7 @@ static void rebind_workers(struct worker_pool *pool)
89453 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
89454 worker_flags |= WORKER_REBOUND;
89455 worker_flags &= ~WORKER_UNBOUND;
89456- ACCESS_ONCE(worker->flags) = worker_flags;
89457+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
89458 }
89459
89460 spin_unlock_irq(&pool->lock);
89461diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
89462index db25707..8b16430 100644
89463--- a/lib/Kconfig.debug
89464+++ b/lib/Kconfig.debug
89465@@ -845,7 +845,7 @@ config DEBUG_MUTEXES
89466
89467 config DEBUG_WW_MUTEX_SLOWPATH
89468 bool "Wait/wound mutex debugging: Slowpath testing"
89469- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89470+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89471 select DEBUG_LOCK_ALLOC
89472 select DEBUG_SPINLOCK
89473 select DEBUG_MUTEXES
89474@@ -858,7 +858,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
89475
89476 config DEBUG_LOCK_ALLOC
89477 bool "Lock debugging: detect incorrect freeing of live locks"
89478- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89479+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89480 select DEBUG_SPINLOCK
89481 select DEBUG_MUTEXES
89482 select LOCKDEP
89483@@ -872,7 +872,7 @@ config DEBUG_LOCK_ALLOC
89484
89485 config PROVE_LOCKING
89486 bool "Lock debugging: prove locking correctness"
89487- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89488+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89489 select LOCKDEP
89490 select DEBUG_SPINLOCK
89491 select DEBUG_MUTEXES
89492@@ -923,7 +923,7 @@ config LOCKDEP
89493
89494 config LOCK_STAT
89495 bool "Lock usage statistics"
89496- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89497+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89498 select LOCKDEP
89499 select DEBUG_SPINLOCK
89500 select DEBUG_MUTEXES
89501@@ -1385,6 +1385,7 @@ config LATENCYTOP
89502 depends on DEBUG_KERNEL
89503 depends on STACKTRACE_SUPPORT
89504 depends on PROC_FS
89505+ depends on !GRKERNSEC_HIDESYM
89506 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
89507 select KALLSYMS
89508 select KALLSYMS_ALL
89509@@ -1401,7 +1402,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
89510 config DEBUG_STRICT_USER_COPY_CHECKS
89511 bool "Strict user copy size checks"
89512 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
89513- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
89514+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
89515 help
89516 Enabling this option turns a certain set of sanity checks for user
89517 copy operations into compile time failures.
89518@@ -1520,7 +1521,7 @@ endmenu # runtime tests
89519
89520 config PROVIDE_OHCI1394_DMA_INIT
89521 bool "Remote debugging over FireWire early on boot"
89522- depends on PCI && X86
89523+ depends on PCI && X86 && !GRKERNSEC
89524 help
89525 If you want to debug problems which hang or crash the kernel early
89526 on boot and the crashing machine has a FireWire port, you can use
89527@@ -1549,7 +1550,7 @@ config PROVIDE_OHCI1394_DMA_INIT
89528
89529 config FIREWIRE_OHCI_REMOTE_DMA
89530 bool "Remote debugging over FireWire with firewire-ohci"
89531- depends on FIREWIRE_OHCI
89532+ depends on FIREWIRE_OHCI && !GRKERNSEC
89533 help
89534 This option lets you use the FireWire bus for remote debugging
89535 with help of the firewire-ohci driver. It enables unfiltered
89536diff --git a/lib/Makefile b/lib/Makefile
89537index a459c31..3320e82 100644
89538--- a/lib/Makefile
89539+++ b/lib/Makefile
89540@@ -49,7 +49,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
89541 obj-$(CONFIG_BTREE) += btree.o
89542 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
89543 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
89544-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
89545+obj-y += list_debug.o
89546 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
89547
89548 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
89549diff --git a/lib/bitmap.c b/lib/bitmap.c
89550index 06f7e4f..f3cf2b0 100644
89551--- a/lib/bitmap.c
89552+++ b/lib/bitmap.c
89553@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
89554 {
89555 int c, old_c, totaldigits, ndigits, nchunks, nbits;
89556 u32 chunk;
89557- const char __user __force *ubuf = (const char __user __force *)buf;
89558+ const char __user *ubuf = (const char __force_user *)buf;
89559
89560 bitmap_zero(maskp, nmaskbits);
89561
89562@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
89563 {
89564 if (!access_ok(VERIFY_READ, ubuf, ulen))
89565 return -EFAULT;
89566- return __bitmap_parse((const char __force *)ubuf,
89567+ return __bitmap_parse((const char __force_kernel *)ubuf,
89568 ulen, 1, maskp, nmaskbits);
89569
89570 }
89571@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
89572 {
89573 unsigned a, b;
89574 int c, old_c, totaldigits;
89575- const char __user __force *ubuf = (const char __user __force *)buf;
89576+ const char __user *ubuf = (const char __force_user *)buf;
89577 int exp_digit, in_range;
89578
89579 totaldigits = c = 0;
89580@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
89581 {
89582 if (!access_ok(VERIFY_READ, ubuf, ulen))
89583 return -EFAULT;
89584- return __bitmap_parselist((const char __force *)ubuf,
89585+ return __bitmap_parselist((const char __force_kernel *)ubuf,
89586 ulen, 1, maskp, nmaskbits);
89587 }
89588 EXPORT_SYMBOL(bitmap_parselist_user);
89589diff --git a/lib/bug.c b/lib/bug.c
89590index 1686034..a9c00c8 100644
89591--- a/lib/bug.c
89592+++ b/lib/bug.c
89593@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
89594 return BUG_TRAP_TYPE_NONE;
89595
89596 bug = find_bug(bugaddr);
89597+ if (!bug)
89598+ return BUG_TRAP_TYPE_NONE;
89599
89600 file = NULL;
89601 line = 0;
89602diff --git a/lib/debugobjects.c b/lib/debugobjects.c
89603index e0731c3..ad66444 100644
89604--- a/lib/debugobjects.c
89605+++ b/lib/debugobjects.c
89606@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
89607 if (limit > 4)
89608 return;
89609
89610- is_on_stack = object_is_on_stack(addr);
89611+ is_on_stack = object_starts_on_stack(addr);
89612 if (is_on_stack == onstack)
89613 return;
89614
89615diff --git a/lib/devres.c b/lib/devres.c
89616index 8235331..5881053 100644
89617--- a/lib/devres.c
89618+++ b/lib/devres.c
89619@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
89620 void devm_iounmap(struct device *dev, void __iomem *addr)
89621 {
89622 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
89623- (void *)addr));
89624+ (void __force *)addr));
89625 iounmap(addr);
89626 }
89627 EXPORT_SYMBOL(devm_iounmap);
89628@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
89629 {
89630 ioport_unmap(addr);
89631 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
89632- devm_ioport_map_match, (void *)addr));
89633+ devm_ioport_map_match, (void __force *)addr));
89634 }
89635 EXPORT_SYMBOL(devm_ioport_unmap);
89636 #endif /* CONFIG_HAS_IOPORT */
89637diff --git a/lib/div64.c b/lib/div64.c
89638index 4382ad7..08aa558 100644
89639--- a/lib/div64.c
89640+++ b/lib/div64.c
89641@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
89642 EXPORT_SYMBOL(__div64_32);
89643
89644 #ifndef div_s64_rem
89645-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
89646+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
89647 {
89648 u64 quotient;
89649
89650@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
89651 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
89652 */
89653 #ifndef div64_u64
89654-u64 div64_u64(u64 dividend, u64 divisor)
89655+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
89656 {
89657 u32 high = divisor >> 32;
89658 u64 quot;
89659diff --git a/lib/dma-debug.c b/lib/dma-debug.c
89660index d87a17a..ac0d79a 100644
89661--- a/lib/dma-debug.c
89662+++ b/lib/dma-debug.c
89663@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
89664
89665 void dma_debug_add_bus(struct bus_type *bus)
89666 {
89667- struct notifier_block *nb;
89668+ notifier_block_no_const *nb;
89669
89670 if (global_disable)
89671 return;
89672@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
89673
89674 static void check_for_stack(struct device *dev, void *addr)
89675 {
89676- if (object_is_on_stack(addr))
89677+ if (object_starts_on_stack(addr))
89678 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
89679 "stack [addr=%p]\n", addr);
89680 }
89681diff --git a/lib/inflate.c b/lib/inflate.c
89682index 013a761..c28f3fc 100644
89683--- a/lib/inflate.c
89684+++ b/lib/inflate.c
89685@@ -269,7 +269,7 @@ static void free(void *where)
89686 malloc_ptr = free_mem_ptr;
89687 }
89688 #else
89689-#define malloc(a) kmalloc(a, GFP_KERNEL)
89690+#define malloc(a) kmalloc((a), GFP_KERNEL)
89691 #define free(a) kfree(a)
89692 #endif
89693
89694diff --git a/lib/ioremap.c b/lib/ioremap.c
89695index 0c9216c..863bd89 100644
89696--- a/lib/ioremap.c
89697+++ b/lib/ioremap.c
89698@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
89699 unsigned long next;
89700
89701 phys_addr -= addr;
89702- pmd = pmd_alloc(&init_mm, pud, addr);
89703+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
89704 if (!pmd)
89705 return -ENOMEM;
89706 do {
89707@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
89708 unsigned long next;
89709
89710 phys_addr -= addr;
89711- pud = pud_alloc(&init_mm, pgd, addr);
89712+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
89713 if (!pud)
89714 return -ENOMEM;
89715 do {
89716diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
89717index bd2bea9..6b3c95e 100644
89718--- a/lib/is_single_threaded.c
89719+++ b/lib/is_single_threaded.c
89720@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
89721 struct task_struct *p, *t;
89722 bool ret;
89723
89724+ if (!mm)
89725+ return true;
89726+
89727 if (atomic_read(&task->signal->live) != 1)
89728 return false;
89729
89730diff --git a/lib/kobject.c b/lib/kobject.c
89731index 5b4b888..c2950f7 100644
89732--- a/lib/kobject.c
89733+++ b/lib/kobject.c
89734@@ -957,9 +957,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
89735
89736
89737 static DEFINE_SPINLOCK(kobj_ns_type_lock);
89738-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
89739+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
89740
89741-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
89742+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
89743 {
89744 enum kobj_ns_type type = ops->type;
89745 int error;
89746diff --git a/lib/list_debug.c b/lib/list_debug.c
89747index c24c2f7..f0296f4 100644
89748--- a/lib/list_debug.c
89749+++ b/lib/list_debug.c
89750@@ -11,7 +11,9 @@
89751 #include <linux/bug.h>
89752 #include <linux/kernel.h>
89753 #include <linux/rculist.h>
89754+#include <linux/mm.h>
89755
89756+#ifdef CONFIG_DEBUG_LIST
89757 /*
89758 * Insert a new entry between two known consecutive entries.
89759 *
89760@@ -19,21 +21,40 @@
89761 * the prev/next entries already!
89762 */
89763
89764+static bool __list_add_debug(struct list_head *new,
89765+ struct list_head *prev,
89766+ struct list_head *next)
89767+{
89768+ if (unlikely(next->prev != prev)) {
89769+ printk(KERN_ERR "list_add corruption. next->prev should be "
89770+ "prev (%p), but was %p. (next=%p).\n",
89771+ prev, next->prev, next);
89772+ BUG();
89773+ return false;
89774+ }
89775+ if (unlikely(prev->next != next)) {
89776+ printk(KERN_ERR "list_add corruption. prev->next should be "
89777+ "next (%p), but was %p. (prev=%p).\n",
89778+ next, prev->next, prev);
89779+ BUG();
89780+ return false;
89781+ }
89782+ if (unlikely(new == prev || new == next)) {
89783+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
89784+ new, prev, next);
89785+ BUG();
89786+ return false;
89787+ }
89788+ return true;
89789+}
89790+
89791 void __list_add(struct list_head *new,
89792- struct list_head *prev,
89793- struct list_head *next)
89794+ struct list_head *prev,
89795+ struct list_head *next)
89796 {
89797- WARN(next->prev != prev,
89798- "list_add corruption. next->prev should be "
89799- "prev (%p), but was %p. (next=%p).\n",
89800- prev, next->prev, next);
89801- WARN(prev->next != next,
89802- "list_add corruption. prev->next should be "
89803- "next (%p), but was %p. (prev=%p).\n",
89804- next, prev->next, prev);
89805- WARN(new == prev || new == next,
89806- "list_add double add: new=%p, prev=%p, next=%p.\n",
89807- new, prev, next);
89808+ if (!__list_add_debug(new, prev, next))
89809+ return;
89810+
89811 next->prev = new;
89812 new->next = next;
89813 new->prev = prev;
89814@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
89815 }
89816 EXPORT_SYMBOL(__list_add);
89817
89818-void __list_del_entry(struct list_head *entry)
89819+static bool __list_del_entry_debug(struct list_head *entry)
89820 {
89821 struct list_head *prev, *next;
89822
89823 prev = entry->prev;
89824 next = entry->next;
89825
89826- if (WARN(next == LIST_POISON1,
89827- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
89828- entry, LIST_POISON1) ||
89829- WARN(prev == LIST_POISON2,
89830- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
89831- entry, LIST_POISON2) ||
89832- WARN(prev->next != entry,
89833- "list_del corruption. prev->next should be %p, "
89834- "but was %p\n", entry, prev->next) ||
89835- WARN(next->prev != entry,
89836- "list_del corruption. next->prev should be %p, "
89837- "but was %p\n", entry, next->prev))
89838+ if (unlikely(next == LIST_POISON1)) {
89839+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
89840+ entry, LIST_POISON1);
89841+ BUG();
89842+ return false;
89843+ }
89844+ if (unlikely(prev == LIST_POISON2)) {
89845+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
89846+ entry, LIST_POISON2);
89847+ BUG();
89848+ return false;
89849+ }
89850+ if (unlikely(entry->prev->next != entry)) {
89851+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
89852+ "but was %p\n", entry, prev->next);
89853+ BUG();
89854+ return false;
89855+ }
89856+ if (unlikely(entry->next->prev != entry)) {
89857+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
89858+ "but was %p\n", entry, next->prev);
89859+ BUG();
89860+ return false;
89861+ }
89862+ return true;
89863+}
89864+
89865+void __list_del_entry(struct list_head *entry)
89866+{
89867+ if (!__list_del_entry_debug(entry))
89868 return;
89869
89870- __list_del(prev, next);
89871+ __list_del(entry->prev, entry->next);
89872 }
89873 EXPORT_SYMBOL(__list_del_entry);
89874
89875@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
89876 void __list_add_rcu(struct list_head *new,
89877 struct list_head *prev, struct list_head *next)
89878 {
89879- WARN(next->prev != prev,
89880- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
89881- prev, next->prev, next);
89882- WARN(prev->next != next,
89883- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
89884- next, prev->next, prev);
89885+ if (!__list_add_debug(new, prev, next))
89886+ return;
89887+
89888 new->next = next;
89889 new->prev = prev;
89890 rcu_assign_pointer(list_next_rcu(prev), new);
89891 next->prev = new;
89892 }
89893 EXPORT_SYMBOL(__list_add_rcu);
89894+#endif
89895+
89896+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
89897+{
89898+#ifdef CONFIG_DEBUG_LIST
89899+ if (!__list_add_debug(new, prev, next))
89900+ return;
89901+#endif
89902+
89903+ pax_open_kernel();
89904+ next->prev = new;
89905+ new->next = next;
89906+ new->prev = prev;
89907+ prev->next = new;
89908+ pax_close_kernel();
89909+}
89910+EXPORT_SYMBOL(__pax_list_add);
89911+
89912+void pax_list_del(struct list_head *entry)
89913+{
89914+#ifdef CONFIG_DEBUG_LIST
89915+ if (!__list_del_entry_debug(entry))
89916+ return;
89917+#endif
89918+
89919+ pax_open_kernel();
89920+ __list_del(entry->prev, entry->next);
89921+ entry->next = LIST_POISON1;
89922+ entry->prev = LIST_POISON2;
89923+ pax_close_kernel();
89924+}
89925+EXPORT_SYMBOL(pax_list_del);
89926+
89927+void pax_list_del_init(struct list_head *entry)
89928+{
89929+ pax_open_kernel();
89930+ __list_del(entry->prev, entry->next);
89931+ INIT_LIST_HEAD(entry);
89932+ pax_close_kernel();
89933+}
89934+EXPORT_SYMBOL(pax_list_del_init);
89935+
89936+void __pax_list_add_rcu(struct list_head *new,
89937+ struct list_head *prev, struct list_head *next)
89938+{
89939+#ifdef CONFIG_DEBUG_LIST
89940+ if (!__list_add_debug(new, prev, next))
89941+ return;
89942+#endif
89943+
89944+ pax_open_kernel();
89945+ new->next = next;
89946+ new->prev = prev;
89947+ rcu_assign_pointer(list_next_rcu(prev), new);
89948+ next->prev = new;
89949+ pax_close_kernel();
89950+}
89951+EXPORT_SYMBOL(__pax_list_add_rcu);
89952+
89953+void pax_list_del_rcu(struct list_head *entry)
89954+{
89955+#ifdef CONFIG_DEBUG_LIST
89956+ if (!__list_del_entry_debug(entry))
89957+ return;
89958+#endif
89959+
89960+ pax_open_kernel();
89961+ __list_del(entry->prev, entry->next);
89962+ entry->next = LIST_POISON1;
89963+ entry->prev = LIST_POISON2;
89964+ pax_close_kernel();
89965+}
89966+EXPORT_SYMBOL(pax_list_del_rcu);
89967diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
89968index 1a53d49..ace934c 100644
89969--- a/lib/percpu-refcount.c
89970+++ b/lib/percpu-refcount.c
89971@@ -29,7 +29,7 @@
89972 * can't hit 0 before we've added up all the percpu refs.
89973 */
89974
89975-#define PCPU_COUNT_BIAS (1U << 31)
89976+#define PCPU_COUNT_BIAS (1U << 30)
89977
89978 /**
89979 * percpu_ref_init - initialize a percpu refcount
89980diff --git a/lib/radix-tree.c b/lib/radix-tree.c
89981index 7811ed3..f80ca19 100644
89982--- a/lib/radix-tree.c
89983+++ b/lib/radix-tree.c
89984@@ -93,7 +93,7 @@ struct radix_tree_preload {
89985 int nr;
89986 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
89987 };
89988-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
89989+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
89990
89991 static inline void *ptr_to_indirect(void *ptr)
89992 {
89993diff --git a/lib/rbtree.c b/lib/rbtree.c
89994index 65f4eff..2cfa167 100644
89995--- a/lib/rbtree.c
89996+++ b/lib/rbtree.c
89997@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
89998 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
89999
90000 static const struct rb_augment_callbacks dummy_callbacks = {
90001- dummy_propagate, dummy_copy, dummy_rotate
90002+ .propagate = dummy_propagate,
90003+ .copy = dummy_copy,
90004+ .rotate = dummy_rotate
90005 };
90006
90007 void rb_insert_color(struct rb_node *node, struct rb_root *root)
90008diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
90009index bb2b201..46abaf9 100644
90010--- a/lib/strncpy_from_user.c
90011+++ b/lib/strncpy_from_user.c
90012@@ -21,7 +21,7 @@
90013 */
90014 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
90015 {
90016- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
90017+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
90018 long res = 0;
90019
90020 /*
90021diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
90022index a28df52..3d55877 100644
90023--- a/lib/strnlen_user.c
90024+++ b/lib/strnlen_user.c
90025@@ -26,7 +26,7 @@
90026 */
90027 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
90028 {
90029- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
90030+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
90031 long align, res = 0;
90032 unsigned long c;
90033
90034diff --git a/lib/swiotlb.c b/lib/swiotlb.c
90035index e4399fa..5e8b214 100644
90036--- a/lib/swiotlb.c
90037+++ b/lib/swiotlb.c
90038@@ -668,7 +668,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
90039
90040 void
90041 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
90042- dma_addr_t dev_addr)
90043+ dma_addr_t dev_addr, struct dma_attrs *attrs)
90044 {
90045 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
90046
90047diff --git a/lib/usercopy.c b/lib/usercopy.c
90048index 4f5b1dd..7cab418 100644
90049--- a/lib/usercopy.c
90050+++ b/lib/usercopy.c
90051@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
90052 WARN(1, "Buffer overflow detected!\n");
90053 }
90054 EXPORT_SYMBOL(copy_from_user_overflow);
90055+
90056+void copy_to_user_overflow(void)
90057+{
90058+ WARN(1, "Buffer overflow detected!\n");
90059+}
90060+EXPORT_SYMBOL(copy_to_user_overflow);
90061diff --git a/lib/vsprintf.c b/lib/vsprintf.c
90062index 10909c5..653e1b8 100644
90063--- a/lib/vsprintf.c
90064+++ b/lib/vsprintf.c
90065@@ -16,6 +16,9 @@
90066 * - scnprintf and vscnprintf
90067 */
90068
90069+#ifdef CONFIG_GRKERNSEC_HIDESYM
90070+#define __INCLUDED_BY_HIDESYM 1
90071+#endif
90072 #include <stdarg.h>
90073 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
90074 #include <linux/types.h>
90075@@ -1155,7 +1158,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
90076 return number(buf, end, *(const netdev_features_t *)addr, spec);
90077 }
90078
90079+#ifdef CONFIG_GRKERNSEC_HIDESYM
90080+int kptr_restrict __read_mostly = 2;
90081+#else
90082 int kptr_restrict __read_mostly;
90083+#endif
90084
90085 /*
90086 * Show a '%p' thing. A kernel extension is that the '%p' is followed
90087@@ -1168,6 +1175,7 @@ int kptr_restrict __read_mostly;
90088 * - 'f' For simple symbolic function names without offset
90089 * - 'S' For symbolic direct pointers with offset
90090 * - 's' For symbolic direct pointers without offset
90091+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
90092 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
90093 * - 'B' For backtraced symbolic direct pointers with offset
90094 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
90095@@ -1234,12 +1242,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
90096
90097 if (!ptr && *fmt != 'K') {
90098 /*
90099- * Print (null) with the same width as a pointer so it makes
90100+ * Print (nil) with the same width as a pointer so it makes
90101 * tabular output look nice.
90102 */
90103 if (spec.field_width == -1)
90104 spec.field_width = default_width;
90105- return string(buf, end, "(null)", spec);
90106+ return string(buf, end, "(nil)", spec);
90107 }
90108
90109 switch (*fmt) {
90110@@ -1249,6 +1257,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
90111 /* Fallthrough */
90112 case 'S':
90113 case 's':
90114+#ifdef CONFIG_GRKERNSEC_HIDESYM
90115+ break;
90116+#else
90117+ return symbol_string(buf, end, ptr, spec, fmt);
90118+#endif
90119+ case 'A':
90120 case 'B':
90121 return symbol_string(buf, end, ptr, spec, fmt);
90122 case 'R':
90123@@ -1304,6 +1318,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
90124 va_end(va);
90125 return buf;
90126 }
90127+ case 'P':
90128+ break;
90129 case 'K':
90130 /*
90131 * %pK cannot be used in IRQ context because its test
90132@@ -1365,6 +1381,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
90133 ((const struct file *)ptr)->f_path.dentry,
90134 spec, fmt);
90135 }
90136+
90137+#ifdef CONFIG_GRKERNSEC_HIDESYM
90138+ /* 'P' = approved pointers to copy to userland,
90139+ as in the /proc/kallsyms case, as we make it display nothing
90140+ for non-root users, and the real contents for root users
90141+ Also ignore 'K' pointers, since we force their NULLing for non-root users
90142+ above
90143+ */
90144+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
90145+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
90146+ dump_stack();
90147+ ptr = NULL;
90148+ }
90149+#endif
90150+
90151 spec.flags |= SMALL;
90152 if (spec.field_width == -1) {
90153 spec.field_width = default_width;
90154@@ -2086,11 +2117,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
90155 typeof(type) value; \
90156 if (sizeof(type) == 8) { \
90157 args = PTR_ALIGN(args, sizeof(u32)); \
90158- *(u32 *)&value = *(u32 *)args; \
90159- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
90160+ *(u32 *)&value = *(const u32 *)args; \
90161+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
90162 } else { \
90163 args = PTR_ALIGN(args, sizeof(type)); \
90164- value = *(typeof(type) *)args; \
90165+ value = *(const typeof(type) *)args; \
90166 } \
90167 args += sizeof(type); \
90168 value; \
90169@@ -2153,7 +2184,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
90170 case FORMAT_TYPE_STR: {
90171 const char *str_arg = args;
90172 args += strlen(str_arg) + 1;
90173- str = string(str, end, (char *)str_arg, spec);
90174+ str = string(str, end, str_arg, spec);
90175 break;
90176 }
90177
90178diff --git a/localversion-grsec b/localversion-grsec
90179new file mode 100644
90180index 0000000..7cd6065
90181--- /dev/null
90182+++ b/localversion-grsec
90183@@ -0,0 +1 @@
90184+-grsec
90185diff --git a/mm/Kconfig b/mm/Kconfig
90186index 723bbe0..ea624b1 100644
90187--- a/mm/Kconfig
90188+++ b/mm/Kconfig
90189@@ -326,10 +326,11 @@ config KSM
90190 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
90191
90192 config DEFAULT_MMAP_MIN_ADDR
90193- int "Low address space to protect from user allocation"
90194+ int "Low address space to protect from user allocation"
90195 depends on MMU
90196- default 4096
90197- help
90198+ default 32768 if ALPHA || ARM || PARISC || SPARC32
90199+ default 65536
90200+ help
90201 This is the portion of low virtual memory which should be protected
90202 from userspace allocation. Keeping a user from writing to low pages
90203 can help reduce the impact of kernel NULL pointer bugs.
90204@@ -360,7 +361,7 @@ config MEMORY_FAILURE
90205
90206 config HWPOISON_INJECT
90207 tristate "HWPoison pages injector"
90208- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
90209+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
90210 select PROC_PAGE_MONITOR
90211
90212 config NOMMU_INITIAL_TRIM_EXCESS
90213diff --git a/mm/backing-dev.c b/mm/backing-dev.c
90214index ce682f7..1fb54f9 100644
90215--- a/mm/backing-dev.c
90216+++ b/mm/backing-dev.c
90217@@ -12,7 +12,7 @@
90218 #include <linux/device.h>
90219 #include <trace/events/writeback.h>
90220
90221-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
90222+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
90223
90224 struct backing_dev_info default_backing_dev_info = {
90225 .name = "default",
90226@@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
90227 return err;
90228
90229 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
90230- atomic_long_inc_return(&bdi_seq));
90231+ atomic_long_inc_return_unchecked(&bdi_seq));
90232 if (err) {
90233 bdi_destroy(bdi);
90234 return err;
90235diff --git a/mm/filemap.c b/mm/filemap.c
90236index b7749a9..50d1123 100644
90237--- a/mm/filemap.c
90238+++ b/mm/filemap.c
90239@@ -1768,7 +1768,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
90240 struct address_space *mapping = file->f_mapping;
90241
90242 if (!mapping->a_ops->readpage)
90243- return -ENOEXEC;
90244+ return -ENODEV;
90245 file_accessed(file);
90246 vma->vm_ops = &generic_file_vm_ops;
90247 return 0;
90248@@ -1950,7 +1950,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
90249
90250 while (bytes) {
90251 char __user *buf = iov->iov_base + base;
90252- int copy = min(bytes, iov->iov_len - base);
90253+ size_t copy = min(bytes, iov->iov_len - base);
90254
90255 base = 0;
90256 left = __copy_from_user_inatomic(vaddr, buf, copy);
90257@@ -1979,7 +1979,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
90258 BUG_ON(!in_atomic());
90259 kaddr = kmap_atomic(page);
90260 if (likely(i->nr_segs == 1)) {
90261- int left;
90262+ size_t left;
90263 char __user *buf = i->iov->iov_base + i->iov_offset;
90264 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
90265 copied = bytes - left;
90266@@ -2007,7 +2007,7 @@ size_t iov_iter_copy_from_user(struct page *page,
90267
90268 kaddr = kmap(page);
90269 if (likely(i->nr_segs == 1)) {
90270- int left;
90271+ size_t left;
90272 char __user *buf = i->iov->iov_base + i->iov_offset;
90273 left = __copy_from_user(kaddr + offset, buf, bytes);
90274 copied = bytes - left;
90275@@ -2037,7 +2037,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
90276 * zero-length segments (without overruning the iovec).
90277 */
90278 while (bytes || unlikely(i->count && !iov->iov_len)) {
90279- int copy;
90280+ size_t copy;
90281
90282 copy = min(bytes, iov->iov_len - base);
90283 BUG_ON(!i->count || i->count < copy);
90284@@ -2108,6 +2108,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
90285 *pos = i_size_read(inode);
90286
90287 if (limit != RLIM_INFINITY) {
90288+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
90289 if (*pos >= limit) {
90290 send_sig(SIGXFSZ, current, 0);
90291 return -EFBIG;
90292diff --git a/mm/fremap.c b/mm/fremap.c
90293index bbc4d66..117b798 100644
90294--- a/mm/fremap.c
90295+++ b/mm/fremap.c
90296@@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
90297 retry:
90298 vma = find_vma(mm, start);
90299
90300+#ifdef CONFIG_PAX_SEGMEXEC
90301+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
90302+ goto out;
90303+#endif
90304+
90305 /*
90306 * Make sure the vma is shared, that it supports prefaulting,
90307 * and that the remapped range is valid and fully within
90308diff --git a/mm/highmem.c b/mm/highmem.c
90309index b32b70c..e512eb0 100644
90310--- a/mm/highmem.c
90311+++ b/mm/highmem.c
90312@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
90313 * So no dangers, even with speculative execution.
90314 */
90315 page = pte_page(pkmap_page_table[i]);
90316+ pax_open_kernel();
90317 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
90318-
90319+ pax_close_kernel();
90320 set_page_address(page, NULL);
90321 need_flush = 1;
90322 }
90323@@ -198,9 +199,11 @@ start:
90324 }
90325 }
90326 vaddr = PKMAP_ADDR(last_pkmap_nr);
90327+
90328+ pax_open_kernel();
90329 set_pte_at(&init_mm, vaddr,
90330 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
90331-
90332+ pax_close_kernel();
90333 pkmap_count[last_pkmap_nr] = 1;
90334 set_page_address(page, (void *)vaddr);
90335
90336diff --git a/mm/hugetlb.c b/mm/hugetlb.c
90337index dee6cf4..52b94f7 100644
90338--- a/mm/hugetlb.c
90339+++ b/mm/hugetlb.c
90340@@ -2077,15 +2077,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
90341 struct hstate *h = &default_hstate;
90342 unsigned long tmp;
90343 int ret;
90344+ ctl_table_no_const hugetlb_table;
90345
90346 tmp = h->max_huge_pages;
90347
90348 if (write && h->order >= MAX_ORDER)
90349 return -EINVAL;
90350
90351- table->data = &tmp;
90352- table->maxlen = sizeof(unsigned long);
90353- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
90354+ hugetlb_table = *table;
90355+ hugetlb_table.data = &tmp;
90356+ hugetlb_table.maxlen = sizeof(unsigned long);
90357+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
90358 if (ret)
90359 goto out;
90360
90361@@ -2130,15 +2132,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
90362 struct hstate *h = &default_hstate;
90363 unsigned long tmp;
90364 int ret;
90365+ ctl_table_no_const hugetlb_table;
90366
90367 tmp = h->nr_overcommit_huge_pages;
90368
90369 if (write && h->order >= MAX_ORDER)
90370 return -EINVAL;
90371
90372- table->data = &tmp;
90373- table->maxlen = sizeof(unsigned long);
90374- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
90375+ hugetlb_table = *table;
90376+ hugetlb_table.data = &tmp;
90377+ hugetlb_table.maxlen = sizeof(unsigned long);
90378+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
90379 if (ret)
90380 goto out;
90381
90382@@ -2596,6 +2600,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
90383 return 1;
90384 }
90385
90386+#ifdef CONFIG_PAX_SEGMEXEC
90387+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
90388+{
90389+ struct mm_struct *mm = vma->vm_mm;
90390+ struct vm_area_struct *vma_m;
90391+ unsigned long address_m;
90392+ pte_t *ptep_m;
90393+
90394+ vma_m = pax_find_mirror_vma(vma);
90395+ if (!vma_m)
90396+ return;
90397+
90398+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90399+ address_m = address + SEGMEXEC_TASK_SIZE;
90400+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
90401+ get_page(page_m);
90402+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
90403+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
90404+}
90405+#endif
90406+
90407 /*
90408 * Hugetlb_cow() should be called with page lock of the original hugepage held.
90409 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
90410@@ -2712,6 +2737,11 @@ retry_avoidcopy:
90411 make_huge_pte(vma, new_page, 1));
90412 page_remove_rmap(old_page);
90413 hugepage_add_new_anon_rmap(new_page, vma, address);
90414+
90415+#ifdef CONFIG_PAX_SEGMEXEC
90416+ pax_mirror_huge_pte(vma, address, new_page);
90417+#endif
90418+
90419 /* Make the old page be freed below */
90420 new_page = old_page;
90421 }
90422@@ -2876,6 +2906,10 @@ retry:
90423 && (vma->vm_flags & VM_SHARED)));
90424 set_huge_pte_at(mm, address, ptep, new_pte);
90425
90426+#ifdef CONFIG_PAX_SEGMEXEC
90427+ pax_mirror_huge_pte(vma, address, page);
90428+#endif
90429+
90430 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
90431 /* Optimization, do the COW without a second fault */
90432 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
90433@@ -2906,6 +2940,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
90434 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
90435 struct hstate *h = hstate_vma(vma);
90436
90437+#ifdef CONFIG_PAX_SEGMEXEC
90438+ struct vm_area_struct *vma_m;
90439+#endif
90440+
90441 address &= huge_page_mask(h);
90442
90443 ptep = huge_pte_offset(mm, address);
90444@@ -2919,6 +2957,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
90445 VM_FAULT_SET_HINDEX(hstate_index(h));
90446 }
90447
90448+#ifdef CONFIG_PAX_SEGMEXEC
90449+ vma_m = pax_find_mirror_vma(vma);
90450+ if (vma_m) {
90451+ unsigned long address_m;
90452+
90453+ if (vma->vm_start > vma_m->vm_start) {
90454+ address_m = address;
90455+ address -= SEGMEXEC_TASK_SIZE;
90456+ vma = vma_m;
90457+ h = hstate_vma(vma);
90458+ } else
90459+ address_m = address + SEGMEXEC_TASK_SIZE;
90460+
90461+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
90462+ return VM_FAULT_OOM;
90463+ address_m &= HPAGE_MASK;
90464+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
90465+ }
90466+#endif
90467+
90468 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
90469 if (!ptep)
90470 return VM_FAULT_OOM;
90471diff --git a/mm/internal.h b/mm/internal.h
90472index 684f7aa..9eb9edc 100644
90473--- a/mm/internal.h
90474+++ b/mm/internal.h
90475@@ -97,6 +97,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
90476 * in mm/page_alloc.c
90477 */
90478 extern void __free_pages_bootmem(struct page *page, unsigned int order);
90479+extern void free_compound_page(struct page *page);
90480 extern void prep_compound_page(struct page *page, unsigned long order);
90481 #ifdef CONFIG_MEMORY_FAILURE
90482 extern bool is_free_buddy_page(struct page *page);
90483@@ -352,7 +353,7 @@ extern u32 hwpoison_filter_enable;
90484
90485 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
90486 unsigned long, unsigned long,
90487- unsigned long, unsigned long);
90488+ unsigned long, unsigned long) __intentional_overflow(-1);
90489
90490 extern void set_pageblock_order(void);
90491 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
90492diff --git a/mm/kmemleak.c b/mm/kmemleak.c
90493index 31f01c5..7015178 100644
90494--- a/mm/kmemleak.c
90495+++ b/mm/kmemleak.c
90496@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
90497
90498 for (i = 0; i < object->trace_len; i++) {
90499 void *ptr = (void *)object->trace[i];
90500- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
90501+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
90502 }
90503 }
90504
90505@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
90506 return -ENOMEM;
90507 }
90508
90509- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
90510+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
90511 &kmemleak_fops);
90512 if (!dentry)
90513 pr_warning("Failed to create the debugfs kmemleak file\n");
90514diff --git a/mm/maccess.c b/mm/maccess.c
90515index d53adf9..03a24bf 100644
90516--- a/mm/maccess.c
90517+++ b/mm/maccess.c
90518@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
90519 set_fs(KERNEL_DS);
90520 pagefault_disable();
90521 ret = __copy_from_user_inatomic(dst,
90522- (__force const void __user *)src, size);
90523+ (const void __force_user *)src, size);
90524 pagefault_enable();
90525 set_fs(old_fs);
90526
90527@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
90528
90529 set_fs(KERNEL_DS);
90530 pagefault_disable();
90531- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
90532+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
90533 pagefault_enable();
90534 set_fs(old_fs);
90535
90536diff --git a/mm/madvise.c b/mm/madvise.c
90537index 539eeb9..e24a987 100644
90538--- a/mm/madvise.c
90539+++ b/mm/madvise.c
90540@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
90541 pgoff_t pgoff;
90542 unsigned long new_flags = vma->vm_flags;
90543
90544+#ifdef CONFIG_PAX_SEGMEXEC
90545+ struct vm_area_struct *vma_m;
90546+#endif
90547+
90548 switch (behavior) {
90549 case MADV_NORMAL:
90550 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
90551@@ -126,6 +130,13 @@ success:
90552 /*
90553 * vm_flags is protected by the mmap_sem held in write mode.
90554 */
90555+
90556+#ifdef CONFIG_PAX_SEGMEXEC
90557+ vma_m = pax_find_mirror_vma(vma);
90558+ if (vma_m)
90559+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
90560+#endif
90561+
90562 vma->vm_flags = new_flags;
90563
90564 out:
90565@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
90566 struct vm_area_struct **prev,
90567 unsigned long start, unsigned long end)
90568 {
90569+
90570+#ifdef CONFIG_PAX_SEGMEXEC
90571+ struct vm_area_struct *vma_m;
90572+#endif
90573+
90574 *prev = vma;
90575 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
90576 return -EINVAL;
90577@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
90578 zap_page_range(vma, start, end - start, &details);
90579 } else
90580 zap_page_range(vma, start, end - start, NULL);
90581+
90582+#ifdef CONFIG_PAX_SEGMEXEC
90583+ vma_m = pax_find_mirror_vma(vma);
90584+ if (vma_m) {
90585+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
90586+ struct zap_details details = {
90587+ .nonlinear_vma = vma_m,
90588+ .last_index = ULONG_MAX,
90589+ };
90590+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
90591+ } else
90592+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
90593+ }
90594+#endif
90595+
90596 return 0;
90597 }
90598
90599@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
90600 if (end < start)
90601 return error;
90602
90603+#ifdef CONFIG_PAX_SEGMEXEC
90604+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
90605+ if (end > SEGMEXEC_TASK_SIZE)
90606+ return error;
90607+ } else
90608+#endif
90609+
90610+ if (end > TASK_SIZE)
90611+ return error;
90612+
90613 error = 0;
90614 if (end == start)
90615 return error;
90616diff --git a/mm/memory-failure.c b/mm/memory-failure.c
90617index fabe550..f31b51c 100644
90618--- a/mm/memory-failure.c
90619+++ b/mm/memory-failure.c
90620@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
90621
90622 int sysctl_memory_failure_recovery __read_mostly = 1;
90623
90624-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
90625+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
90626
90627 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
90628
90629@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
90630 pfn, t->comm, t->pid);
90631 si.si_signo = SIGBUS;
90632 si.si_errno = 0;
90633- si.si_addr = (void *)addr;
90634+ si.si_addr = (void __user *)addr;
90635 #ifdef __ARCH_SI_TRAPNO
90636 si.si_trapno = trapno;
90637 #endif
90638@@ -762,7 +762,7 @@ static struct page_state {
90639 unsigned long res;
90640 char *msg;
90641 int (*action)(struct page *p, unsigned long pfn);
90642-} error_states[] = {
90643+} __do_const error_states[] = {
90644 { reserved, reserved, "reserved kernel", me_kernel },
90645 /*
90646 * free pages are specially detected outside this table:
90647@@ -1063,7 +1063,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
90648 nr_pages = 1 << compound_order(hpage);
90649 else /* normal page or thp */
90650 nr_pages = 1;
90651- atomic_long_add(nr_pages, &num_poisoned_pages);
90652+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
90653
90654 /*
90655 * We need/can do nothing about count=0 pages.
90656@@ -1093,7 +1093,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
90657 if (!PageHWPoison(hpage)
90658 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
90659 || (p != hpage && TestSetPageHWPoison(hpage))) {
90660- atomic_long_sub(nr_pages, &num_poisoned_pages);
90661+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
90662 return 0;
90663 }
90664 set_page_hwpoison_huge_page(hpage);
90665@@ -1162,7 +1162,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
90666 }
90667 if (hwpoison_filter(p)) {
90668 if (TestClearPageHWPoison(p))
90669- atomic_long_sub(nr_pages, &num_poisoned_pages);
90670+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
90671 unlock_page(hpage);
90672 put_page(hpage);
90673 return 0;
90674@@ -1380,7 +1380,7 @@ int unpoison_memory(unsigned long pfn)
90675 return 0;
90676 }
90677 if (TestClearPageHWPoison(p))
90678- atomic_long_dec(&num_poisoned_pages);
90679+ atomic_long_dec_unchecked(&num_poisoned_pages);
90680 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
90681 return 0;
90682 }
90683@@ -1394,7 +1394,7 @@ int unpoison_memory(unsigned long pfn)
90684 */
90685 if (TestClearPageHWPoison(page)) {
90686 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
90687- atomic_long_sub(nr_pages, &num_poisoned_pages);
90688+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
90689 freeit = 1;
90690 if (PageHuge(page))
90691 clear_page_hwpoison_huge_page(page);
90692@@ -1519,11 +1519,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
90693 if (PageHuge(page)) {
90694 set_page_hwpoison_huge_page(hpage);
90695 dequeue_hwpoisoned_huge_page(hpage);
90696- atomic_long_add(1 << compound_order(hpage),
90697+ atomic_long_add_unchecked(1 << compound_order(hpage),
90698 &num_poisoned_pages);
90699 } else {
90700 SetPageHWPoison(page);
90701- atomic_long_inc(&num_poisoned_pages);
90702+ atomic_long_inc_unchecked(&num_poisoned_pages);
90703 }
90704 }
90705 return ret;
90706@@ -1562,7 +1562,7 @@ static int __soft_offline_page(struct page *page, int flags)
90707 put_page(page);
90708 pr_info("soft_offline: %#lx: invalidated\n", pfn);
90709 SetPageHWPoison(page);
90710- atomic_long_inc(&num_poisoned_pages);
90711+ atomic_long_inc_unchecked(&num_poisoned_pages);
90712 return 0;
90713 }
90714
90715@@ -1607,7 +1607,7 @@ static int __soft_offline_page(struct page *page, int flags)
90716 if (!is_free_buddy_page(page))
90717 pr_info("soft offline: %#lx: page leaked\n",
90718 pfn);
90719- atomic_long_inc(&num_poisoned_pages);
90720+ atomic_long_inc_unchecked(&num_poisoned_pages);
90721 }
90722 } else {
90723 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
90724@@ -1681,11 +1681,11 @@ int soft_offline_page(struct page *page, int flags)
90725 if (PageHuge(page)) {
90726 set_page_hwpoison_huge_page(hpage);
90727 dequeue_hwpoisoned_huge_page(hpage);
90728- atomic_long_add(1 << compound_order(hpage),
90729+ atomic_long_add_unchecked(1 << compound_order(hpage),
90730 &num_poisoned_pages);
90731 } else {
90732 SetPageHWPoison(page);
90733- atomic_long_inc(&num_poisoned_pages);
90734+ atomic_long_inc_unchecked(&num_poisoned_pages);
90735 }
90736 }
90737 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
90738diff --git a/mm/memory.c b/mm/memory.c
90739index 6768ce9..4c41d69 100644
90740--- a/mm/memory.c
90741+++ b/mm/memory.c
90742@@ -402,6 +402,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
90743 free_pte_range(tlb, pmd, addr);
90744 } while (pmd++, addr = next, addr != end);
90745
90746+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
90747 start &= PUD_MASK;
90748 if (start < floor)
90749 return;
90750@@ -416,6 +417,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
90751 pmd = pmd_offset(pud, start);
90752 pud_clear(pud);
90753 pmd_free_tlb(tlb, pmd, start);
90754+#endif
90755+
90756 }
90757
90758 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
90759@@ -435,6 +438,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
90760 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
90761 } while (pud++, addr = next, addr != end);
90762
90763+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
90764 start &= PGDIR_MASK;
90765 if (start < floor)
90766 return;
90767@@ -449,6 +453,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
90768 pud = pud_offset(pgd, start);
90769 pgd_clear(pgd);
90770 pud_free_tlb(tlb, pud, start);
90771+#endif
90772+
90773 }
90774
90775 /*
90776@@ -1635,12 +1641,6 @@ no_page_table:
90777 return page;
90778 }
90779
90780-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
90781-{
90782- return stack_guard_page_start(vma, addr) ||
90783- stack_guard_page_end(vma, addr+PAGE_SIZE);
90784-}
90785-
90786 /**
90787 * __get_user_pages() - pin user pages in memory
90788 * @tsk: task_struct of target task
90789@@ -1727,10 +1727,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
90790
90791 i = 0;
90792
90793- do {
90794+ while (nr_pages) {
90795 struct vm_area_struct *vma;
90796
90797- vma = find_extend_vma(mm, start);
90798+ vma = find_vma(mm, start);
90799 if (!vma && in_gate_area(mm, start)) {
90800 unsigned long pg = start & PAGE_MASK;
90801 pgd_t *pgd;
90802@@ -1779,7 +1779,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
90803 goto next_page;
90804 }
90805
90806- if (!vma ||
90807+ if (!vma || start < vma->vm_start ||
90808 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
90809 !(vm_flags & vma->vm_flags))
90810 return i ? : -EFAULT;
90811@@ -1808,11 +1808,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
90812 int ret;
90813 unsigned int fault_flags = 0;
90814
90815- /* For mlock, just skip the stack guard page. */
90816- if (foll_flags & FOLL_MLOCK) {
90817- if (stack_guard_page(vma, start))
90818- goto next_page;
90819- }
90820 if (foll_flags & FOLL_WRITE)
90821 fault_flags |= FAULT_FLAG_WRITE;
90822 if (nonblocking)
90823@@ -1892,7 +1887,7 @@ next_page:
90824 start += page_increm * PAGE_SIZE;
90825 nr_pages -= page_increm;
90826 } while (nr_pages && start < vma->vm_end);
90827- } while (nr_pages);
90828+ }
90829 return i;
90830 }
90831 EXPORT_SYMBOL(__get_user_pages);
90832@@ -2099,6 +2094,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
90833 page_add_file_rmap(page);
90834 set_pte_at(mm, addr, pte, mk_pte(page, prot));
90835
90836+#ifdef CONFIG_PAX_SEGMEXEC
90837+ pax_mirror_file_pte(vma, addr, page, ptl);
90838+#endif
90839+
90840 retval = 0;
90841 pte_unmap_unlock(pte, ptl);
90842 return retval;
90843@@ -2143,9 +2142,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
90844 if (!page_count(page))
90845 return -EINVAL;
90846 if (!(vma->vm_flags & VM_MIXEDMAP)) {
90847+
90848+#ifdef CONFIG_PAX_SEGMEXEC
90849+ struct vm_area_struct *vma_m;
90850+#endif
90851+
90852 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
90853 BUG_ON(vma->vm_flags & VM_PFNMAP);
90854 vma->vm_flags |= VM_MIXEDMAP;
90855+
90856+#ifdef CONFIG_PAX_SEGMEXEC
90857+ vma_m = pax_find_mirror_vma(vma);
90858+ if (vma_m)
90859+ vma_m->vm_flags |= VM_MIXEDMAP;
90860+#endif
90861+
90862 }
90863 return insert_page(vma, addr, page, vma->vm_page_prot);
90864 }
90865@@ -2228,6 +2239,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
90866 unsigned long pfn)
90867 {
90868 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
90869+ BUG_ON(vma->vm_mirror);
90870
90871 if (addr < vma->vm_start || addr >= vma->vm_end)
90872 return -EFAULT;
90873@@ -2475,7 +2487,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
90874
90875 BUG_ON(pud_huge(*pud));
90876
90877- pmd = pmd_alloc(mm, pud, addr);
90878+ pmd = (mm == &init_mm) ?
90879+ pmd_alloc_kernel(mm, pud, addr) :
90880+ pmd_alloc(mm, pud, addr);
90881 if (!pmd)
90882 return -ENOMEM;
90883 do {
90884@@ -2495,7 +2509,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
90885 unsigned long next;
90886 int err;
90887
90888- pud = pud_alloc(mm, pgd, addr);
90889+ pud = (mm == &init_mm) ?
90890+ pud_alloc_kernel(mm, pgd, addr) :
90891+ pud_alloc(mm, pgd, addr);
90892 if (!pud)
90893 return -ENOMEM;
90894 do {
90895@@ -2583,6 +2599,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
90896 copy_user_highpage(dst, src, va, vma);
90897 }
90898
90899+#ifdef CONFIG_PAX_SEGMEXEC
90900+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
90901+{
90902+ struct mm_struct *mm = vma->vm_mm;
90903+ spinlock_t *ptl;
90904+ pte_t *pte, entry;
90905+
90906+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
90907+ entry = *pte;
90908+ if (!pte_present(entry)) {
90909+ if (!pte_none(entry)) {
90910+ BUG_ON(pte_file(entry));
90911+ free_swap_and_cache(pte_to_swp_entry(entry));
90912+ pte_clear_not_present_full(mm, address, pte, 0);
90913+ }
90914+ } else {
90915+ struct page *page;
90916+
90917+ flush_cache_page(vma, address, pte_pfn(entry));
90918+ entry = ptep_clear_flush(vma, address, pte);
90919+ BUG_ON(pte_dirty(entry));
90920+ page = vm_normal_page(vma, address, entry);
90921+ if (page) {
90922+ update_hiwater_rss(mm);
90923+ if (PageAnon(page))
90924+ dec_mm_counter_fast(mm, MM_ANONPAGES);
90925+ else
90926+ dec_mm_counter_fast(mm, MM_FILEPAGES);
90927+ page_remove_rmap(page);
90928+ page_cache_release(page);
90929+ }
90930+ }
90931+ pte_unmap_unlock(pte, ptl);
90932+}
90933+
90934+/* PaX: if vma is mirrored, synchronize the mirror's PTE
90935+ *
90936+ * the ptl of the lower mapped page is held on entry and is not released on exit
90937+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
90938+ */
90939+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
90940+{
90941+ struct mm_struct *mm = vma->vm_mm;
90942+ unsigned long address_m;
90943+ spinlock_t *ptl_m;
90944+ struct vm_area_struct *vma_m;
90945+ pmd_t *pmd_m;
90946+ pte_t *pte_m, entry_m;
90947+
90948+ BUG_ON(!page_m || !PageAnon(page_m));
90949+
90950+ vma_m = pax_find_mirror_vma(vma);
90951+ if (!vma_m)
90952+ return;
90953+
90954+ BUG_ON(!PageLocked(page_m));
90955+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90956+ address_m = address + SEGMEXEC_TASK_SIZE;
90957+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
90958+ pte_m = pte_offset_map(pmd_m, address_m);
90959+ ptl_m = pte_lockptr(mm, pmd_m);
90960+ if (ptl != ptl_m) {
90961+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
90962+ if (!pte_none(*pte_m))
90963+ goto out;
90964+ }
90965+
90966+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
90967+ page_cache_get(page_m);
90968+ page_add_anon_rmap(page_m, vma_m, address_m);
90969+ inc_mm_counter_fast(mm, MM_ANONPAGES);
90970+ set_pte_at(mm, address_m, pte_m, entry_m);
90971+ update_mmu_cache(vma_m, address_m, pte_m);
90972+out:
90973+ if (ptl != ptl_m)
90974+ spin_unlock(ptl_m);
90975+ pte_unmap(pte_m);
90976+ unlock_page(page_m);
90977+}
90978+
90979+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
90980+{
90981+ struct mm_struct *mm = vma->vm_mm;
90982+ unsigned long address_m;
90983+ spinlock_t *ptl_m;
90984+ struct vm_area_struct *vma_m;
90985+ pmd_t *pmd_m;
90986+ pte_t *pte_m, entry_m;
90987+
90988+ BUG_ON(!page_m || PageAnon(page_m));
90989+
90990+ vma_m = pax_find_mirror_vma(vma);
90991+ if (!vma_m)
90992+ return;
90993+
90994+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90995+ address_m = address + SEGMEXEC_TASK_SIZE;
90996+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
90997+ pte_m = pte_offset_map(pmd_m, address_m);
90998+ ptl_m = pte_lockptr(mm, pmd_m);
90999+ if (ptl != ptl_m) {
91000+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
91001+ if (!pte_none(*pte_m))
91002+ goto out;
91003+ }
91004+
91005+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
91006+ page_cache_get(page_m);
91007+ page_add_file_rmap(page_m);
91008+ inc_mm_counter_fast(mm, MM_FILEPAGES);
91009+ set_pte_at(mm, address_m, pte_m, entry_m);
91010+ update_mmu_cache(vma_m, address_m, pte_m);
91011+out:
91012+ if (ptl != ptl_m)
91013+ spin_unlock(ptl_m);
91014+ pte_unmap(pte_m);
91015+}
91016+
91017+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
91018+{
91019+ struct mm_struct *mm = vma->vm_mm;
91020+ unsigned long address_m;
91021+ spinlock_t *ptl_m;
91022+ struct vm_area_struct *vma_m;
91023+ pmd_t *pmd_m;
91024+ pte_t *pte_m, entry_m;
91025+
91026+ vma_m = pax_find_mirror_vma(vma);
91027+ if (!vma_m)
91028+ return;
91029+
91030+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91031+ address_m = address + SEGMEXEC_TASK_SIZE;
91032+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
91033+ pte_m = pte_offset_map(pmd_m, address_m);
91034+ ptl_m = pte_lockptr(mm, pmd_m);
91035+ if (ptl != ptl_m) {
91036+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
91037+ if (!pte_none(*pte_m))
91038+ goto out;
91039+ }
91040+
91041+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
91042+ set_pte_at(mm, address_m, pte_m, entry_m);
91043+out:
91044+ if (ptl != ptl_m)
91045+ spin_unlock(ptl_m);
91046+ pte_unmap(pte_m);
91047+}
91048+
91049+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
91050+{
91051+ struct page *page_m;
91052+ pte_t entry;
91053+
91054+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
91055+ goto out;
91056+
91057+ entry = *pte;
91058+ page_m = vm_normal_page(vma, address, entry);
91059+ if (!page_m)
91060+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
91061+ else if (PageAnon(page_m)) {
91062+ if (pax_find_mirror_vma(vma)) {
91063+ pte_unmap_unlock(pte, ptl);
91064+ lock_page(page_m);
91065+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
91066+ if (pte_same(entry, *pte))
91067+ pax_mirror_anon_pte(vma, address, page_m, ptl);
91068+ else
91069+ unlock_page(page_m);
91070+ }
91071+ } else
91072+ pax_mirror_file_pte(vma, address, page_m, ptl);
91073+
91074+out:
91075+ pte_unmap_unlock(pte, ptl);
91076+}
91077+#endif
91078+
91079 /*
91080 * This routine handles present pages, when users try to write
91081 * to a shared page. It is done by copying the page to a new address
91082@@ -2807,6 +3003,12 @@ gotten:
91083 */
91084 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
91085 if (likely(pte_same(*page_table, orig_pte))) {
91086+
91087+#ifdef CONFIG_PAX_SEGMEXEC
91088+ if (pax_find_mirror_vma(vma))
91089+ BUG_ON(!trylock_page(new_page));
91090+#endif
91091+
91092 if (old_page) {
91093 if (!PageAnon(old_page)) {
91094 dec_mm_counter_fast(mm, MM_FILEPAGES);
91095@@ -2858,6 +3060,10 @@ gotten:
91096 page_remove_rmap(old_page);
91097 }
91098
91099+#ifdef CONFIG_PAX_SEGMEXEC
91100+ pax_mirror_anon_pte(vma, address, new_page, ptl);
91101+#endif
91102+
91103 /* Free the old page.. */
91104 new_page = old_page;
91105 ret |= VM_FAULT_WRITE;
91106@@ -3135,6 +3341,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
91107 swap_free(entry);
91108 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
91109 try_to_free_swap(page);
91110+
91111+#ifdef CONFIG_PAX_SEGMEXEC
91112+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
91113+#endif
91114+
91115 unlock_page(page);
91116 if (page != swapcache) {
91117 /*
91118@@ -3158,6 +3369,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
91119
91120 /* No need to invalidate - it was non-present before */
91121 update_mmu_cache(vma, address, page_table);
91122+
91123+#ifdef CONFIG_PAX_SEGMEXEC
91124+ pax_mirror_anon_pte(vma, address, page, ptl);
91125+#endif
91126+
91127 unlock:
91128 pte_unmap_unlock(page_table, ptl);
91129 out:
91130@@ -3177,40 +3393,6 @@ out_release:
91131 }
91132
91133 /*
91134- * This is like a special single-page "expand_{down|up}wards()",
91135- * except we must first make sure that 'address{-|+}PAGE_SIZE'
91136- * doesn't hit another vma.
91137- */
91138-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
91139-{
91140- address &= PAGE_MASK;
91141- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
91142- struct vm_area_struct *prev = vma->vm_prev;
91143-
91144- /*
91145- * Is there a mapping abutting this one below?
91146- *
91147- * That's only ok if it's the same stack mapping
91148- * that has gotten split..
91149- */
91150- if (prev && prev->vm_end == address)
91151- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
91152-
91153- expand_downwards(vma, address - PAGE_SIZE);
91154- }
91155- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
91156- struct vm_area_struct *next = vma->vm_next;
91157-
91158- /* As VM_GROWSDOWN but s/below/above/ */
91159- if (next && next->vm_start == address + PAGE_SIZE)
91160- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
91161-
91162- expand_upwards(vma, address + PAGE_SIZE);
91163- }
91164- return 0;
91165-}
91166-
91167-/*
91168 * We enter with non-exclusive mmap_sem (to exclude vma changes,
91169 * but allow concurrent faults), and pte mapped but not yet locked.
91170 * We return with mmap_sem still held, but pte unmapped and unlocked.
91171@@ -3219,27 +3401,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
91172 unsigned long address, pte_t *page_table, pmd_t *pmd,
91173 unsigned int flags)
91174 {
91175- struct page *page;
91176+ struct page *page = NULL;
91177 spinlock_t *ptl;
91178 pte_t entry;
91179
91180- pte_unmap(page_table);
91181-
91182- /* Check if we need to add a guard page to the stack */
91183- if (check_stack_guard_page(vma, address) < 0)
91184- return VM_FAULT_SIGBUS;
91185-
91186- /* Use the zero-page for reads */
91187 if (!(flags & FAULT_FLAG_WRITE)) {
91188 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
91189 vma->vm_page_prot));
91190- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
91191+ ptl = pte_lockptr(mm, pmd);
91192+ spin_lock(ptl);
91193 if (!pte_none(*page_table))
91194 goto unlock;
91195 goto setpte;
91196 }
91197
91198 /* Allocate our own private page. */
91199+ pte_unmap(page_table);
91200+
91201 if (unlikely(anon_vma_prepare(vma)))
91202 goto oom;
91203 page = alloc_zeroed_user_highpage_movable(vma, address);
91204@@ -3263,6 +3441,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
91205 if (!pte_none(*page_table))
91206 goto release;
91207
91208+#ifdef CONFIG_PAX_SEGMEXEC
91209+ if (pax_find_mirror_vma(vma))
91210+ BUG_ON(!trylock_page(page));
91211+#endif
91212+
91213 inc_mm_counter_fast(mm, MM_ANONPAGES);
91214 page_add_new_anon_rmap(page, vma, address);
91215 setpte:
91216@@ -3270,6 +3453,12 @@ setpte:
91217
91218 /* No need to invalidate - it was non-present before */
91219 update_mmu_cache(vma, address, page_table);
91220+
91221+#ifdef CONFIG_PAX_SEGMEXEC
91222+ if (page)
91223+ pax_mirror_anon_pte(vma, address, page, ptl);
91224+#endif
91225+
91226 unlock:
91227 pte_unmap_unlock(page_table, ptl);
91228 return 0;
91229@@ -3413,6 +3602,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91230 */
91231 /* Only go through if we didn't race with anybody else... */
91232 if (likely(pte_same(*page_table, orig_pte))) {
91233+
91234+#ifdef CONFIG_PAX_SEGMEXEC
91235+ if (anon && pax_find_mirror_vma(vma))
91236+ BUG_ON(!trylock_page(page));
91237+#endif
91238+
91239 flush_icache_page(vma, page);
91240 entry = mk_pte(page, vma->vm_page_prot);
91241 if (flags & FAULT_FLAG_WRITE)
91242@@ -3434,6 +3629,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91243
91244 /* no need to invalidate: a not-present page won't be cached */
91245 update_mmu_cache(vma, address, page_table);
91246+
91247+#ifdef CONFIG_PAX_SEGMEXEC
91248+ if (anon)
91249+ pax_mirror_anon_pte(vma, address, page, ptl);
91250+ else
91251+ pax_mirror_file_pte(vma, address, page, ptl);
91252+#endif
91253+
91254 } else {
91255 if (cow_page)
91256 mem_cgroup_uncharge_page(cow_page);
91257@@ -3681,6 +3884,12 @@ static int handle_pte_fault(struct mm_struct *mm,
91258 if (flags & FAULT_FLAG_WRITE)
91259 flush_tlb_fix_spurious_fault(vma, address);
91260 }
91261+
91262+#ifdef CONFIG_PAX_SEGMEXEC
91263+ pax_mirror_pte(vma, address, pte, pmd, ptl);
91264+ return 0;
91265+#endif
91266+
91267 unlock:
91268 pte_unmap_unlock(pte, ptl);
91269 return 0;
91270@@ -3697,9 +3906,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91271 pmd_t *pmd;
91272 pte_t *pte;
91273
91274+#ifdef CONFIG_PAX_SEGMEXEC
91275+ struct vm_area_struct *vma_m;
91276+#endif
91277+
91278 if (unlikely(is_vm_hugetlb_page(vma)))
91279 return hugetlb_fault(mm, vma, address, flags);
91280
91281+#ifdef CONFIG_PAX_SEGMEXEC
91282+ vma_m = pax_find_mirror_vma(vma);
91283+ if (vma_m) {
91284+ unsigned long address_m;
91285+ pgd_t *pgd_m;
91286+ pud_t *pud_m;
91287+ pmd_t *pmd_m;
91288+
91289+ if (vma->vm_start > vma_m->vm_start) {
91290+ address_m = address;
91291+ address -= SEGMEXEC_TASK_SIZE;
91292+ vma = vma_m;
91293+ } else
91294+ address_m = address + SEGMEXEC_TASK_SIZE;
91295+
91296+ pgd_m = pgd_offset(mm, address_m);
91297+ pud_m = pud_alloc(mm, pgd_m, address_m);
91298+ if (!pud_m)
91299+ return VM_FAULT_OOM;
91300+ pmd_m = pmd_alloc(mm, pud_m, address_m);
91301+ if (!pmd_m)
91302+ return VM_FAULT_OOM;
91303+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
91304+ return VM_FAULT_OOM;
91305+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
91306+ }
91307+#endif
91308+
91309 retry:
91310 pgd = pgd_offset(mm, address);
91311 pud = pud_alloc(mm, pgd, address);
91312@@ -3838,6 +4079,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
91313 spin_unlock(&mm->page_table_lock);
91314 return 0;
91315 }
91316+
91317+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
91318+{
91319+ pud_t *new = pud_alloc_one(mm, address);
91320+ if (!new)
91321+ return -ENOMEM;
91322+
91323+ smp_wmb(); /* See comment in __pte_alloc */
91324+
91325+ spin_lock(&mm->page_table_lock);
91326+ if (pgd_present(*pgd)) /* Another has populated it */
91327+ pud_free(mm, new);
91328+ else
91329+ pgd_populate_kernel(mm, pgd, new);
91330+ spin_unlock(&mm->page_table_lock);
91331+ return 0;
91332+}
91333 #endif /* __PAGETABLE_PUD_FOLDED */
91334
91335 #ifndef __PAGETABLE_PMD_FOLDED
91336@@ -3868,6 +4126,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
91337 spin_unlock(&mm->page_table_lock);
91338 return 0;
91339 }
91340+
91341+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
91342+{
91343+ pmd_t *new = pmd_alloc_one(mm, address);
91344+ if (!new)
91345+ return -ENOMEM;
91346+
91347+ smp_wmb(); /* See comment in __pte_alloc */
91348+
91349+ spin_lock(&mm->page_table_lock);
91350+#ifndef __ARCH_HAS_4LEVEL_HACK
91351+ if (pud_present(*pud)) /* Another has populated it */
91352+ pmd_free(mm, new);
91353+ else
91354+ pud_populate_kernel(mm, pud, new);
91355+#else
91356+ if (pgd_present(*pud)) /* Another has populated it */
91357+ pmd_free(mm, new);
91358+ else
91359+ pgd_populate_kernel(mm, pud, new);
91360+#endif /* __ARCH_HAS_4LEVEL_HACK */
91361+ spin_unlock(&mm->page_table_lock);
91362+ return 0;
91363+}
91364 #endif /* __PAGETABLE_PMD_FOLDED */
91365
91366 #if !defined(__HAVE_ARCH_GATE_AREA)
91367@@ -3881,7 +4163,7 @@ static int __init gate_vma_init(void)
91368 gate_vma.vm_start = FIXADDR_USER_START;
91369 gate_vma.vm_end = FIXADDR_USER_END;
91370 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
91371- gate_vma.vm_page_prot = __P101;
91372+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
91373
91374 return 0;
91375 }
91376@@ -4015,8 +4297,8 @@ out:
91377 return ret;
91378 }
91379
91380-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
91381- void *buf, int len, int write)
91382+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
91383+ void *buf, size_t len, int write)
91384 {
91385 resource_size_t phys_addr;
91386 unsigned long prot = 0;
91387@@ -4042,8 +4324,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
91388 * Access another process' address space as given in mm. If non-NULL, use the
91389 * given task for page fault accounting.
91390 */
91391-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91392- unsigned long addr, void *buf, int len, int write)
91393+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91394+ unsigned long addr, void *buf, size_t len, int write)
91395 {
91396 struct vm_area_struct *vma;
91397 void *old_buf = buf;
91398@@ -4051,7 +4333,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91399 down_read(&mm->mmap_sem);
91400 /* ignore errors, just check how much was successfully transferred */
91401 while (len) {
91402- int bytes, ret, offset;
91403+ ssize_t bytes, ret, offset;
91404 void *maddr;
91405 struct page *page = NULL;
91406
91407@@ -4110,8 +4392,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91408 *
91409 * The caller must hold a reference on @mm.
91410 */
91411-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
91412- void *buf, int len, int write)
91413+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
91414+ void *buf, size_t len, int write)
91415 {
91416 return __access_remote_vm(NULL, mm, addr, buf, len, write);
91417 }
91418@@ -4121,11 +4403,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
91419 * Source/target buffer must be kernel space,
91420 * Do not walk the page table directly, use get_user_pages
91421 */
91422-int access_process_vm(struct task_struct *tsk, unsigned long addr,
91423- void *buf, int len, int write)
91424+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
91425+ void *buf, size_t len, int write)
91426 {
91427 struct mm_struct *mm;
91428- int ret;
91429+ ssize_t ret;
91430
91431 mm = get_task_mm(tsk);
91432 if (!mm)
91433diff --git a/mm/mempolicy.c b/mm/mempolicy.c
91434index e1bd997..055f496 100644
91435--- a/mm/mempolicy.c
91436+++ b/mm/mempolicy.c
91437@@ -747,6 +747,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
91438 unsigned long vmstart;
91439 unsigned long vmend;
91440
91441+#ifdef CONFIG_PAX_SEGMEXEC
91442+ struct vm_area_struct *vma_m;
91443+#endif
91444+
91445 vma = find_vma(mm, start);
91446 if (!vma || vma->vm_start > start)
91447 return -EFAULT;
91448@@ -790,6 +794,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
91449 err = vma_replace_policy(vma, new_pol);
91450 if (err)
91451 goto out;
91452+
91453+#ifdef CONFIG_PAX_SEGMEXEC
91454+ vma_m = pax_find_mirror_vma(vma);
91455+ if (vma_m) {
91456+ err = vma_replace_policy(vma_m, new_pol);
91457+ if (err)
91458+ goto out;
91459+ }
91460+#endif
91461+
91462 }
91463
91464 out:
91465@@ -1255,6 +1269,17 @@ static long do_mbind(unsigned long start, unsigned long len,
91466
91467 if (end < start)
91468 return -EINVAL;
91469+
91470+#ifdef CONFIG_PAX_SEGMEXEC
91471+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
91472+ if (end > SEGMEXEC_TASK_SIZE)
91473+ return -EINVAL;
91474+ } else
91475+#endif
91476+
91477+ if (end > TASK_SIZE)
91478+ return -EINVAL;
91479+
91480 if (end == start)
91481 return 0;
91482
91483@@ -1483,8 +1508,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
91484 */
91485 tcred = __task_cred(task);
91486 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
91487- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
91488- !capable(CAP_SYS_NICE)) {
91489+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
91490 rcu_read_unlock();
91491 err = -EPERM;
91492 goto out_put;
91493@@ -1515,6 +1539,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
91494 goto out;
91495 }
91496
91497+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
91498+ if (mm != current->mm &&
91499+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
91500+ mmput(mm);
91501+ err = -EPERM;
91502+ goto out;
91503+ }
91504+#endif
91505+
91506 err = do_migrate_pages(mm, old, new,
91507 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
91508
91509diff --git a/mm/migrate.c b/mm/migrate.c
91510index 9194375..75c81e2 100644
91511--- a/mm/migrate.c
91512+++ b/mm/migrate.c
91513@@ -1464,8 +1464,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
91514 */
91515 tcred = __task_cred(task);
91516 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
91517- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
91518- !capable(CAP_SYS_NICE)) {
91519+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
91520 rcu_read_unlock();
91521 err = -EPERM;
91522 goto out;
91523diff --git a/mm/mlock.c b/mm/mlock.c
91524index 192e6ee..b044449 100644
91525--- a/mm/mlock.c
91526+++ b/mm/mlock.c
91527@@ -14,6 +14,7 @@
91528 #include <linux/pagevec.h>
91529 #include <linux/mempolicy.h>
91530 #include <linux/syscalls.h>
91531+#include <linux/security.h>
91532 #include <linux/sched.h>
91533 #include <linux/export.h>
91534 #include <linux/rmap.h>
91535@@ -588,7 +589,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
91536 {
91537 unsigned long nstart, end, tmp;
91538 struct vm_area_struct * vma, * prev;
91539- int error;
91540+ int error = 0;
91541
91542 VM_BUG_ON(start & ~PAGE_MASK);
91543 VM_BUG_ON(len != PAGE_ALIGN(len));
91544@@ -597,6 +598,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
91545 return -EINVAL;
91546 if (end == start)
91547 return 0;
91548+ if (end > TASK_SIZE)
91549+ return -EINVAL;
91550+
91551 vma = find_vma(current->mm, start);
91552 if (!vma || vma->vm_start > start)
91553 return -ENOMEM;
91554@@ -608,6 +612,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
91555 for (nstart = start ; ; ) {
91556 vm_flags_t newflags;
91557
91558+#ifdef CONFIG_PAX_SEGMEXEC
91559+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
91560+ break;
91561+#endif
91562+
91563 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
91564
91565 newflags = vma->vm_flags & ~VM_LOCKED;
91566@@ -720,6 +729,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
91567 lock_limit >>= PAGE_SHIFT;
91568
91569 /* check against resource limits */
91570+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
91571 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
91572 error = do_mlock(start, len, 1);
91573 up_write(&current->mm->mmap_sem);
91574@@ -754,6 +764,11 @@ static int do_mlockall(int flags)
91575 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
91576 vm_flags_t newflags;
91577
91578+#ifdef CONFIG_PAX_SEGMEXEC
91579+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
91580+ break;
91581+#endif
91582+
91583 newflags = vma->vm_flags & ~VM_LOCKED;
91584 if (flags & MCL_CURRENT)
91585 newflags |= VM_LOCKED;
91586@@ -787,6 +802,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
91587 lock_limit >>= PAGE_SHIFT;
91588
91589 ret = -ENOMEM;
91590+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
91591 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
91592 capable(CAP_IPC_LOCK))
91593 ret = do_mlockall(flags);
91594diff --git a/mm/mmap.c b/mm/mmap.c
91595index 834b2d7..650d1b9 100644
91596--- a/mm/mmap.c
91597+++ b/mm/mmap.c
91598@@ -36,6 +36,7 @@
91599 #include <linux/sched/sysctl.h>
91600 #include <linux/notifier.h>
91601 #include <linux/memory.h>
91602+#include <linux/random.h>
91603
91604 #include <asm/uaccess.h>
91605 #include <asm/cacheflush.h>
91606@@ -52,6 +53,16 @@
91607 #define arch_rebalance_pgtables(addr, len) (addr)
91608 #endif
91609
91610+static inline void verify_mm_writelocked(struct mm_struct *mm)
91611+{
91612+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
91613+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
91614+ up_read(&mm->mmap_sem);
91615+ BUG();
91616+ }
91617+#endif
91618+}
91619+
91620 static void unmap_region(struct mm_struct *mm,
91621 struct vm_area_struct *vma, struct vm_area_struct *prev,
91622 unsigned long start, unsigned long end);
91623@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
91624 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
91625 *
91626 */
91627-pgprot_t protection_map[16] = {
91628+pgprot_t protection_map[16] __read_only = {
91629 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
91630 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
91631 };
91632
91633-pgprot_t vm_get_page_prot(unsigned long vm_flags)
91634+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
91635 {
91636- return __pgprot(pgprot_val(protection_map[vm_flags &
91637+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
91638 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
91639 pgprot_val(arch_vm_get_page_prot(vm_flags)));
91640+
91641+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
91642+ if (!(__supported_pte_mask & _PAGE_NX) &&
91643+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
91644+ (vm_flags & (VM_READ | VM_WRITE)))
91645+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
91646+#endif
91647+
91648+ return prot;
91649 }
91650 EXPORT_SYMBOL(vm_get_page_prot);
91651
91652@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
91653 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
91654 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
91655 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
91656+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
91657 /*
91658 * Make sure vm_committed_as in one cacheline and not cacheline shared with
91659 * other variables. It can be updated by several CPUs frequently.
91660@@ -245,6 +266,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
91661 struct vm_area_struct *next = vma->vm_next;
91662
91663 might_sleep();
91664+ BUG_ON(vma->vm_mirror);
91665 if (vma->vm_ops && vma->vm_ops->close)
91666 vma->vm_ops->close(vma);
91667 if (vma->vm_file)
91668@@ -289,6 +311,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
91669 * not page aligned -Ram Gupta
91670 */
91671 rlim = rlimit(RLIMIT_DATA);
91672+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
91673 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
91674 (mm->end_data - mm->start_data) > rlim)
91675 goto out;
91676@@ -893,7 +916,15 @@ again: remove_next = 1 + (end > next->vm_end);
91677 static inline int is_mergeable_vma(struct vm_area_struct *vma,
91678 struct file *file, unsigned long vm_flags)
91679 {
91680- if (vma->vm_flags ^ vm_flags)
91681+ /*
91682+ * VM_SOFTDIRTY should not prevent from VMA merging, if we
91683+ * match the flags but dirty bit -- the caller should mark
91684+ * merged VMA as dirty. If dirty bit won't be excluded from
91685+ * comparison, we increase pressue on the memory system forcing
91686+ * the kernel to generate new VMAs when old one could be
91687+ * extended instead.
91688+ */
91689+ if ((vma->vm_flags ^ vm_flags) & ~VM_SOFTDIRTY)
91690 return 0;
91691 if (vma->vm_file != file)
91692 return 0;
91693@@ -931,6 +962,12 @@ static int
91694 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
91695 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
91696 {
91697+
91698+#ifdef CONFIG_PAX_SEGMEXEC
91699+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
91700+ return 0;
91701+#endif
91702+
91703 if (is_mergeable_vma(vma, file, vm_flags) &&
91704 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
91705 if (vma->vm_pgoff == vm_pgoff)
91706@@ -950,6 +987,12 @@ static int
91707 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
91708 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
91709 {
91710+
91711+#ifdef CONFIG_PAX_SEGMEXEC
91712+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
91713+ return 0;
91714+#endif
91715+
91716 if (is_mergeable_vma(vma, file, vm_flags) &&
91717 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
91718 pgoff_t vm_pglen;
91719@@ -992,13 +1035,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
91720 struct vm_area_struct *vma_merge(struct mm_struct *mm,
91721 struct vm_area_struct *prev, unsigned long addr,
91722 unsigned long end, unsigned long vm_flags,
91723- struct anon_vma *anon_vma, struct file *file,
91724+ struct anon_vma *anon_vma, struct file *file,
91725 pgoff_t pgoff, struct mempolicy *policy)
91726 {
91727 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
91728 struct vm_area_struct *area, *next;
91729 int err;
91730
91731+#ifdef CONFIG_PAX_SEGMEXEC
91732+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
91733+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
91734+
91735+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
91736+#endif
91737+
91738 /*
91739 * We later require that vma->vm_flags == vm_flags,
91740 * so this tests vma->vm_flags & VM_SPECIAL, too.
91741@@ -1014,6 +1064,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
91742 if (next && next->vm_end == end) /* cases 6, 7, 8 */
91743 next = next->vm_next;
91744
91745+#ifdef CONFIG_PAX_SEGMEXEC
91746+ if (prev)
91747+ prev_m = pax_find_mirror_vma(prev);
91748+ if (area)
91749+ area_m = pax_find_mirror_vma(area);
91750+ if (next)
91751+ next_m = pax_find_mirror_vma(next);
91752+#endif
91753+
91754 /*
91755 * Can it merge with the predecessor?
91756 */
91757@@ -1033,9 +1092,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
91758 /* cases 1, 6 */
91759 err = vma_adjust(prev, prev->vm_start,
91760 next->vm_end, prev->vm_pgoff, NULL);
91761- } else /* cases 2, 5, 7 */
91762+
91763+#ifdef CONFIG_PAX_SEGMEXEC
91764+ if (!err && prev_m)
91765+ err = vma_adjust(prev_m, prev_m->vm_start,
91766+ next_m->vm_end, prev_m->vm_pgoff, NULL);
91767+#endif
91768+
91769+ } else { /* cases 2, 5, 7 */
91770 err = vma_adjust(prev, prev->vm_start,
91771 end, prev->vm_pgoff, NULL);
91772+
91773+#ifdef CONFIG_PAX_SEGMEXEC
91774+ if (!err && prev_m)
91775+ err = vma_adjust(prev_m, prev_m->vm_start,
91776+ end_m, prev_m->vm_pgoff, NULL);
91777+#endif
91778+
91779+ }
91780 if (err)
91781 return NULL;
91782 khugepaged_enter_vma_merge(prev);
91783@@ -1049,12 +1123,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
91784 mpol_equal(policy, vma_policy(next)) &&
91785 can_vma_merge_before(next, vm_flags,
91786 anon_vma, file, pgoff+pglen)) {
91787- if (prev && addr < prev->vm_end) /* case 4 */
91788+ if (prev && addr < prev->vm_end) { /* case 4 */
91789 err = vma_adjust(prev, prev->vm_start,
91790 addr, prev->vm_pgoff, NULL);
91791- else /* cases 3, 8 */
91792+
91793+#ifdef CONFIG_PAX_SEGMEXEC
91794+ if (!err && prev_m)
91795+ err = vma_adjust(prev_m, prev_m->vm_start,
91796+ addr_m, prev_m->vm_pgoff, NULL);
91797+#endif
91798+
91799+ } else { /* cases 3, 8 */
91800 err = vma_adjust(area, addr, next->vm_end,
91801 next->vm_pgoff - pglen, NULL);
91802+
91803+#ifdef CONFIG_PAX_SEGMEXEC
91804+ if (!err && area_m)
91805+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
91806+ next_m->vm_pgoff - pglen, NULL);
91807+#endif
91808+
91809+ }
91810 if (err)
91811 return NULL;
91812 khugepaged_enter_vma_merge(area);
91813@@ -1082,7 +1171,7 @@ static int anon_vma_compatible(struct vm_area_struct *a, struct vm_area_struct *
91814 return a->vm_end == b->vm_start &&
91815 mpol_equal(vma_policy(a), vma_policy(b)) &&
91816 a->vm_file == b->vm_file &&
91817- !((a->vm_flags ^ b->vm_flags) & ~(VM_READ|VM_WRITE|VM_EXEC)) &&
91818+ !((a->vm_flags ^ b->vm_flags) & ~(VM_READ|VM_WRITE|VM_EXEC|VM_SOFTDIRTY)) &&
91819 b->vm_pgoff == a->vm_pgoff + ((b->vm_start - a->vm_start) >> PAGE_SHIFT);
91820 }
91821
91822@@ -1163,8 +1252,10 @@ none:
91823 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
91824 struct file *file, long pages)
91825 {
91826- const unsigned long stack_flags
91827- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
91828+
91829+#ifdef CONFIG_PAX_RANDMMAP
91830+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
91831+#endif
91832
91833 mm->total_vm += pages;
91834
91835@@ -1172,7 +1263,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
91836 mm->shared_vm += pages;
91837 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
91838 mm->exec_vm += pages;
91839- } else if (flags & stack_flags)
91840+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
91841 mm->stack_vm += pages;
91842 }
91843 #endif /* CONFIG_PROC_FS */
91844@@ -1210,7 +1301,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91845 * (the exception is when the underlying filesystem is noexec
91846 * mounted, in which case we dont add PROT_EXEC.)
91847 */
91848- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
91849+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
91850 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
91851 prot |= PROT_EXEC;
91852
91853@@ -1236,7 +1327,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91854 /* Obtain the address to map to. we verify (or select) it and ensure
91855 * that it represents a valid section of the address space.
91856 */
91857- addr = get_unmapped_area(file, addr, len, pgoff, flags);
91858+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
91859 if (addr & ~PAGE_MASK)
91860 return addr;
91861
91862@@ -1247,6 +1338,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91863 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
91864 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
91865
91866+#ifdef CONFIG_PAX_MPROTECT
91867+ if (mm->pax_flags & MF_PAX_MPROTECT) {
91868+
91869+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
91870+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
91871+ mm->binfmt->handle_mmap)
91872+ mm->binfmt->handle_mmap(file);
91873+#endif
91874+
91875+#ifndef CONFIG_PAX_MPROTECT_COMPAT
91876+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
91877+ gr_log_rwxmmap(file);
91878+
91879+#ifdef CONFIG_PAX_EMUPLT
91880+ vm_flags &= ~VM_EXEC;
91881+#else
91882+ return -EPERM;
91883+#endif
91884+
91885+ }
91886+
91887+ if (!(vm_flags & VM_EXEC))
91888+ vm_flags &= ~VM_MAYEXEC;
91889+#else
91890+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
91891+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
91892+#endif
91893+ else
91894+ vm_flags &= ~VM_MAYWRITE;
91895+ }
91896+#endif
91897+
91898+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
91899+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
91900+ vm_flags &= ~VM_PAGEEXEC;
91901+#endif
91902+
91903 if (flags & MAP_LOCKED)
91904 if (!can_do_mlock())
91905 return -EPERM;
91906@@ -1258,6 +1386,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91907 locked += mm->locked_vm;
91908 lock_limit = rlimit(RLIMIT_MEMLOCK);
91909 lock_limit >>= PAGE_SHIFT;
91910+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
91911 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
91912 return -EAGAIN;
91913 }
91914@@ -1342,6 +1471,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91915 vm_flags |= VM_NORESERVE;
91916 }
91917
91918+ if (!gr_acl_handle_mmap(file, prot))
91919+ return -EACCES;
91920+
91921 addr = mmap_region(file, addr, len, vm_flags, pgoff);
91922 if (!IS_ERR_VALUE(addr) &&
91923 ((vm_flags & VM_LOCKED) ||
91924@@ -1435,7 +1567,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
91925 vm_flags_t vm_flags = vma->vm_flags;
91926
91927 /* If it was private or non-writable, the write bit is already clear */
91928- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
91929+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
91930 return 0;
91931
91932 /* The backer wishes to know when pages are first written to? */
91933@@ -1481,7 +1613,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
91934 struct rb_node **rb_link, *rb_parent;
91935 unsigned long charged = 0;
91936
91937+#ifdef CONFIG_PAX_SEGMEXEC
91938+ struct vm_area_struct *vma_m = NULL;
91939+#endif
91940+
91941+ /*
91942+ * mm->mmap_sem is required to protect against another thread
91943+ * changing the mappings in case we sleep.
91944+ */
91945+ verify_mm_writelocked(mm);
91946+
91947 /* Check against address space limit. */
91948+
91949+#ifdef CONFIG_PAX_RANDMMAP
91950+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
91951+#endif
91952+
91953 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
91954 unsigned long nr_pages;
91955
91956@@ -1500,11 +1647,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
91957
91958 /* Clear old maps */
91959 error = -ENOMEM;
91960-munmap_back:
91961 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
91962 if (do_munmap(mm, addr, len))
91963 return -ENOMEM;
91964- goto munmap_back;
91965+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
91966 }
91967
91968 /*
91969@@ -1535,6 +1681,16 @@ munmap_back:
91970 goto unacct_error;
91971 }
91972
91973+#ifdef CONFIG_PAX_SEGMEXEC
91974+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
91975+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
91976+ if (!vma_m) {
91977+ error = -ENOMEM;
91978+ goto free_vma;
91979+ }
91980+ }
91981+#endif
91982+
91983 vma->vm_mm = mm;
91984 vma->vm_start = addr;
91985 vma->vm_end = addr + len;
91986@@ -1554,6 +1710,13 @@ munmap_back:
91987 if (error)
91988 goto unmap_and_free_vma;
91989
91990+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
91991+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
91992+ vma->vm_flags |= VM_PAGEEXEC;
91993+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
91994+ }
91995+#endif
91996+
91997 /* Can addr have changed??
91998 *
91999 * Answer: Yes, several device drivers can do it in their
92000@@ -1587,6 +1750,12 @@ munmap_back:
92001 }
92002
92003 vma_link(mm, vma, prev, rb_link, rb_parent);
92004+
92005+#ifdef CONFIG_PAX_SEGMEXEC
92006+ if (vma_m)
92007+ BUG_ON(pax_mirror_vma(vma_m, vma));
92008+#endif
92009+
92010 /* Once vma denies write, undo our temporary denial count */
92011 if (vm_flags & VM_DENYWRITE)
92012 allow_write_access(file);
92013@@ -1595,6 +1764,7 @@ out:
92014 perf_event_mmap(vma);
92015
92016 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
92017+ track_exec_limit(mm, addr, addr + len, vm_flags);
92018 if (vm_flags & VM_LOCKED) {
92019 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
92020 vma == get_gate_vma(current->mm)))
92021@@ -1627,6 +1797,12 @@ unmap_and_free_vma:
92022 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
92023 charged = 0;
92024 free_vma:
92025+
92026+#ifdef CONFIG_PAX_SEGMEXEC
92027+ if (vma_m)
92028+ kmem_cache_free(vm_area_cachep, vma_m);
92029+#endif
92030+
92031 kmem_cache_free(vm_area_cachep, vma);
92032 unacct_error:
92033 if (charged)
92034@@ -1634,7 +1810,63 @@ unacct_error:
92035 return error;
92036 }
92037
92038-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
92039+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
92040+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
92041+{
92042+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
92043+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
92044+
92045+ return 0;
92046+}
92047+#endif
92048+
92049+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
92050+{
92051+ if (!vma) {
92052+#ifdef CONFIG_STACK_GROWSUP
92053+ if (addr > sysctl_heap_stack_gap)
92054+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
92055+ else
92056+ vma = find_vma(current->mm, 0);
92057+ if (vma && (vma->vm_flags & VM_GROWSUP))
92058+ return false;
92059+#endif
92060+ return true;
92061+ }
92062+
92063+ if (addr + len > vma->vm_start)
92064+ return false;
92065+
92066+ if (vma->vm_flags & VM_GROWSDOWN)
92067+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
92068+#ifdef CONFIG_STACK_GROWSUP
92069+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
92070+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
92071+#endif
92072+ else if (offset)
92073+ return offset <= vma->vm_start - addr - len;
92074+
92075+ return true;
92076+}
92077+
92078+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
92079+{
92080+ if (vma->vm_start < len)
92081+ return -ENOMEM;
92082+
92083+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
92084+ if (offset <= vma->vm_start - len)
92085+ return vma->vm_start - len - offset;
92086+ else
92087+ return -ENOMEM;
92088+ }
92089+
92090+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
92091+ return vma->vm_start - len - sysctl_heap_stack_gap;
92092+ return -ENOMEM;
92093+}
92094+
92095+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
92096 {
92097 /*
92098 * We implement the search by looking for an rbtree node that
92099@@ -1682,11 +1914,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
92100 }
92101 }
92102
92103- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
92104+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
92105 check_current:
92106 /* Check if current node has a suitable gap */
92107 if (gap_start > high_limit)
92108 return -ENOMEM;
92109+
92110+ if (gap_end - gap_start > info->threadstack_offset)
92111+ gap_start += info->threadstack_offset;
92112+ else
92113+ gap_start = gap_end;
92114+
92115+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
92116+ if (gap_end - gap_start > sysctl_heap_stack_gap)
92117+ gap_start += sysctl_heap_stack_gap;
92118+ else
92119+ gap_start = gap_end;
92120+ }
92121+ if (vma->vm_flags & VM_GROWSDOWN) {
92122+ if (gap_end - gap_start > sysctl_heap_stack_gap)
92123+ gap_end -= sysctl_heap_stack_gap;
92124+ else
92125+ gap_end = gap_start;
92126+ }
92127 if (gap_end >= low_limit && gap_end - gap_start >= length)
92128 goto found;
92129
92130@@ -1736,7 +1986,7 @@ found:
92131 return gap_start;
92132 }
92133
92134-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
92135+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
92136 {
92137 struct mm_struct *mm = current->mm;
92138 struct vm_area_struct *vma;
92139@@ -1790,6 +2040,24 @@ check_current:
92140 gap_end = vma->vm_start;
92141 if (gap_end < low_limit)
92142 return -ENOMEM;
92143+
92144+ if (gap_end - gap_start > info->threadstack_offset)
92145+ gap_end -= info->threadstack_offset;
92146+ else
92147+ gap_end = gap_start;
92148+
92149+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
92150+ if (gap_end - gap_start > sysctl_heap_stack_gap)
92151+ gap_start += sysctl_heap_stack_gap;
92152+ else
92153+ gap_start = gap_end;
92154+ }
92155+ if (vma->vm_flags & VM_GROWSDOWN) {
92156+ if (gap_end - gap_start > sysctl_heap_stack_gap)
92157+ gap_end -= sysctl_heap_stack_gap;
92158+ else
92159+ gap_end = gap_start;
92160+ }
92161 if (gap_start <= high_limit && gap_end - gap_start >= length)
92162 goto found;
92163
92164@@ -1853,6 +2121,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
92165 struct mm_struct *mm = current->mm;
92166 struct vm_area_struct *vma;
92167 struct vm_unmapped_area_info info;
92168+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
92169
92170 if (len > TASK_SIZE - mmap_min_addr)
92171 return -ENOMEM;
92172@@ -1860,11 +2129,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
92173 if (flags & MAP_FIXED)
92174 return addr;
92175
92176+#ifdef CONFIG_PAX_RANDMMAP
92177+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
92178+#endif
92179+
92180 if (addr) {
92181 addr = PAGE_ALIGN(addr);
92182 vma = find_vma(mm, addr);
92183 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
92184- (!vma || addr + len <= vma->vm_start))
92185+ check_heap_stack_gap(vma, addr, len, offset))
92186 return addr;
92187 }
92188
92189@@ -1873,6 +2146,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
92190 info.low_limit = mm->mmap_base;
92191 info.high_limit = TASK_SIZE;
92192 info.align_mask = 0;
92193+ info.threadstack_offset = offset;
92194 return vm_unmapped_area(&info);
92195 }
92196 #endif
92197@@ -1891,6 +2165,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
92198 struct mm_struct *mm = current->mm;
92199 unsigned long addr = addr0;
92200 struct vm_unmapped_area_info info;
92201+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
92202
92203 /* requested length too big for entire address space */
92204 if (len > TASK_SIZE - mmap_min_addr)
92205@@ -1899,12 +2174,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
92206 if (flags & MAP_FIXED)
92207 return addr;
92208
92209+#ifdef CONFIG_PAX_RANDMMAP
92210+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
92211+#endif
92212+
92213 /* requesting a specific address */
92214 if (addr) {
92215 addr = PAGE_ALIGN(addr);
92216 vma = find_vma(mm, addr);
92217 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
92218- (!vma || addr + len <= vma->vm_start))
92219+ check_heap_stack_gap(vma, addr, len, offset))
92220 return addr;
92221 }
92222
92223@@ -1913,6 +2192,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
92224 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
92225 info.high_limit = mm->mmap_base;
92226 info.align_mask = 0;
92227+ info.threadstack_offset = offset;
92228 addr = vm_unmapped_area(&info);
92229
92230 /*
92231@@ -1925,6 +2205,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
92232 VM_BUG_ON(addr != -ENOMEM);
92233 info.flags = 0;
92234 info.low_limit = TASK_UNMAPPED_BASE;
92235+
92236+#ifdef CONFIG_PAX_RANDMMAP
92237+ if (mm->pax_flags & MF_PAX_RANDMMAP)
92238+ info.low_limit += mm->delta_mmap;
92239+#endif
92240+
92241 info.high_limit = TASK_SIZE;
92242 addr = vm_unmapped_area(&info);
92243 }
92244@@ -2026,6 +2312,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
92245 return vma;
92246 }
92247
92248+#ifdef CONFIG_PAX_SEGMEXEC
92249+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
92250+{
92251+ struct vm_area_struct *vma_m;
92252+
92253+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
92254+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
92255+ BUG_ON(vma->vm_mirror);
92256+ return NULL;
92257+ }
92258+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
92259+ vma_m = vma->vm_mirror;
92260+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
92261+ BUG_ON(vma->vm_file != vma_m->vm_file);
92262+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
92263+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
92264+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
92265+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
92266+ return vma_m;
92267+}
92268+#endif
92269+
92270 /*
92271 * Verify that the stack growth is acceptable and
92272 * update accounting. This is shared with both the
92273@@ -2042,6 +2350,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
92274 return -ENOMEM;
92275
92276 /* Stack limit test */
92277+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
92278 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
92279 return -ENOMEM;
92280
92281@@ -2052,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
92282 locked = mm->locked_vm + grow;
92283 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
92284 limit >>= PAGE_SHIFT;
92285+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
92286 if (locked > limit && !capable(CAP_IPC_LOCK))
92287 return -ENOMEM;
92288 }
92289@@ -2081,37 +2391,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
92290 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
92291 * vma is the last one with address > vma->vm_end. Have to extend vma.
92292 */
92293+#ifndef CONFIG_IA64
92294+static
92295+#endif
92296 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
92297 {
92298 int error;
92299+ bool locknext;
92300
92301 if (!(vma->vm_flags & VM_GROWSUP))
92302 return -EFAULT;
92303
92304+ /* Also guard against wrapping around to address 0. */
92305+ if (address < PAGE_ALIGN(address+1))
92306+ address = PAGE_ALIGN(address+1);
92307+ else
92308+ return -ENOMEM;
92309+
92310 /*
92311 * We must make sure the anon_vma is allocated
92312 * so that the anon_vma locking is not a noop.
92313 */
92314 if (unlikely(anon_vma_prepare(vma)))
92315 return -ENOMEM;
92316+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
92317+ if (locknext && anon_vma_prepare(vma->vm_next))
92318+ return -ENOMEM;
92319 vma_lock_anon_vma(vma);
92320+ if (locknext)
92321+ vma_lock_anon_vma(vma->vm_next);
92322
92323 /*
92324 * vma->vm_start/vm_end cannot change under us because the caller
92325 * is required to hold the mmap_sem in read mode. We need the
92326- * anon_vma lock to serialize against concurrent expand_stacks.
92327- * Also guard against wrapping around to address 0.
92328+ * anon_vma locks to serialize against concurrent expand_stacks
92329+ * and expand_upwards.
92330 */
92331- if (address < PAGE_ALIGN(address+4))
92332- address = PAGE_ALIGN(address+4);
92333- else {
92334- vma_unlock_anon_vma(vma);
92335- return -ENOMEM;
92336- }
92337 error = 0;
92338
92339 /* Somebody else might have raced and expanded it already */
92340- if (address > vma->vm_end) {
92341+ 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)
92342+ error = -ENOMEM;
92343+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
92344 unsigned long size, grow;
92345
92346 size = address - vma->vm_start;
92347@@ -2146,6 +2467,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
92348 }
92349 }
92350 }
92351+ if (locknext)
92352+ vma_unlock_anon_vma(vma->vm_next);
92353 vma_unlock_anon_vma(vma);
92354 khugepaged_enter_vma_merge(vma);
92355 validate_mm(vma->vm_mm);
92356@@ -2160,6 +2483,8 @@ int expand_downwards(struct vm_area_struct *vma,
92357 unsigned long address)
92358 {
92359 int error;
92360+ bool lockprev = false;
92361+ struct vm_area_struct *prev;
92362
92363 /*
92364 * We must make sure the anon_vma is allocated
92365@@ -2173,6 +2498,15 @@ int expand_downwards(struct vm_area_struct *vma,
92366 if (error)
92367 return error;
92368
92369+ prev = vma->vm_prev;
92370+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
92371+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
92372+#endif
92373+ if (lockprev && anon_vma_prepare(prev))
92374+ return -ENOMEM;
92375+ if (lockprev)
92376+ vma_lock_anon_vma(prev);
92377+
92378 vma_lock_anon_vma(vma);
92379
92380 /*
92381@@ -2182,9 +2516,17 @@ int expand_downwards(struct vm_area_struct *vma,
92382 */
92383
92384 /* Somebody else might have raced and expanded it already */
92385- if (address < vma->vm_start) {
92386+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
92387+ error = -ENOMEM;
92388+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
92389 unsigned long size, grow;
92390
92391+#ifdef CONFIG_PAX_SEGMEXEC
92392+ struct vm_area_struct *vma_m;
92393+
92394+ vma_m = pax_find_mirror_vma(vma);
92395+#endif
92396+
92397 size = vma->vm_end - address;
92398 grow = (vma->vm_start - address) >> PAGE_SHIFT;
92399
92400@@ -2209,13 +2551,27 @@ int expand_downwards(struct vm_area_struct *vma,
92401 vma->vm_pgoff -= grow;
92402 anon_vma_interval_tree_post_update_vma(vma);
92403 vma_gap_update(vma);
92404+
92405+#ifdef CONFIG_PAX_SEGMEXEC
92406+ if (vma_m) {
92407+ anon_vma_interval_tree_pre_update_vma(vma_m);
92408+ vma_m->vm_start -= grow << PAGE_SHIFT;
92409+ vma_m->vm_pgoff -= grow;
92410+ anon_vma_interval_tree_post_update_vma(vma_m);
92411+ vma_gap_update(vma_m);
92412+ }
92413+#endif
92414+
92415 spin_unlock(&vma->vm_mm->page_table_lock);
92416
92417+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
92418 perf_event_mmap(vma);
92419 }
92420 }
92421 }
92422 vma_unlock_anon_vma(vma);
92423+ if (lockprev)
92424+ vma_unlock_anon_vma(prev);
92425 khugepaged_enter_vma_merge(vma);
92426 validate_mm(vma->vm_mm);
92427 return error;
92428@@ -2313,6 +2669,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
92429 do {
92430 long nrpages = vma_pages(vma);
92431
92432+#ifdef CONFIG_PAX_SEGMEXEC
92433+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
92434+ vma = remove_vma(vma);
92435+ continue;
92436+ }
92437+#endif
92438+
92439 if (vma->vm_flags & VM_ACCOUNT)
92440 nr_accounted += nrpages;
92441 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
92442@@ -2357,6 +2720,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
92443 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
92444 vma->vm_prev = NULL;
92445 do {
92446+
92447+#ifdef CONFIG_PAX_SEGMEXEC
92448+ if (vma->vm_mirror) {
92449+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
92450+ vma->vm_mirror->vm_mirror = NULL;
92451+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
92452+ vma->vm_mirror = NULL;
92453+ }
92454+#endif
92455+
92456 vma_rb_erase(vma, &mm->mm_rb);
92457 mm->map_count--;
92458 tail_vma = vma;
92459@@ -2382,14 +2755,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92460 struct vm_area_struct *new;
92461 int err = -ENOMEM;
92462
92463+#ifdef CONFIG_PAX_SEGMEXEC
92464+ struct vm_area_struct *vma_m, *new_m = NULL;
92465+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
92466+#endif
92467+
92468 if (is_vm_hugetlb_page(vma) && (addr &
92469 ~(huge_page_mask(hstate_vma(vma)))))
92470 return -EINVAL;
92471
92472+#ifdef CONFIG_PAX_SEGMEXEC
92473+ vma_m = pax_find_mirror_vma(vma);
92474+#endif
92475+
92476 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
92477 if (!new)
92478 goto out_err;
92479
92480+#ifdef CONFIG_PAX_SEGMEXEC
92481+ if (vma_m) {
92482+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
92483+ if (!new_m) {
92484+ kmem_cache_free(vm_area_cachep, new);
92485+ goto out_err;
92486+ }
92487+ }
92488+#endif
92489+
92490 /* most fields are the same, copy all, and then fixup */
92491 *new = *vma;
92492
92493@@ -2402,6 +2794,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92494 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
92495 }
92496
92497+#ifdef CONFIG_PAX_SEGMEXEC
92498+ if (vma_m) {
92499+ *new_m = *vma_m;
92500+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
92501+ new_m->vm_mirror = new;
92502+ new->vm_mirror = new_m;
92503+
92504+ if (new_below)
92505+ new_m->vm_end = addr_m;
92506+ else {
92507+ new_m->vm_start = addr_m;
92508+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
92509+ }
92510+ }
92511+#endif
92512+
92513 err = vma_dup_policy(vma, new);
92514 if (err)
92515 goto out_free_vma;
92516@@ -2421,6 +2829,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92517 else
92518 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
92519
92520+#ifdef CONFIG_PAX_SEGMEXEC
92521+ if (!err && vma_m) {
92522+ struct mempolicy *pol = vma_policy(new);
92523+
92524+ if (anon_vma_clone(new_m, vma_m))
92525+ goto out_free_mpol;
92526+
92527+ mpol_get(pol);
92528+ set_vma_policy(new_m, pol);
92529+
92530+ if (new_m->vm_file)
92531+ get_file(new_m->vm_file);
92532+
92533+ if (new_m->vm_ops && new_m->vm_ops->open)
92534+ new_m->vm_ops->open(new_m);
92535+
92536+ if (new_below)
92537+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
92538+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
92539+ else
92540+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
92541+
92542+ if (err) {
92543+ if (new_m->vm_ops && new_m->vm_ops->close)
92544+ new_m->vm_ops->close(new_m);
92545+ if (new_m->vm_file)
92546+ fput(new_m->vm_file);
92547+ mpol_put(pol);
92548+ }
92549+ }
92550+#endif
92551+
92552 /* Success. */
92553 if (!err)
92554 return 0;
92555@@ -2430,10 +2870,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92556 new->vm_ops->close(new);
92557 if (new->vm_file)
92558 fput(new->vm_file);
92559- unlink_anon_vmas(new);
92560 out_free_mpol:
92561 mpol_put(vma_policy(new));
92562 out_free_vma:
92563+
92564+#ifdef CONFIG_PAX_SEGMEXEC
92565+ if (new_m) {
92566+ unlink_anon_vmas(new_m);
92567+ kmem_cache_free(vm_area_cachep, new_m);
92568+ }
92569+#endif
92570+
92571+ unlink_anon_vmas(new);
92572 kmem_cache_free(vm_area_cachep, new);
92573 out_err:
92574 return err;
92575@@ -2446,6 +2894,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92576 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
92577 unsigned long addr, int new_below)
92578 {
92579+
92580+#ifdef CONFIG_PAX_SEGMEXEC
92581+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
92582+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
92583+ if (mm->map_count >= sysctl_max_map_count-1)
92584+ return -ENOMEM;
92585+ } else
92586+#endif
92587+
92588 if (mm->map_count >= sysctl_max_map_count)
92589 return -ENOMEM;
92590
92591@@ -2457,11 +2914,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
92592 * work. This now handles partial unmappings.
92593 * Jeremy Fitzhardinge <jeremy@goop.org>
92594 */
92595+#ifdef CONFIG_PAX_SEGMEXEC
92596 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92597 {
92598+ int ret = __do_munmap(mm, start, len);
92599+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
92600+ return ret;
92601+
92602+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
92603+}
92604+
92605+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92606+#else
92607+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92608+#endif
92609+{
92610 unsigned long end;
92611 struct vm_area_struct *vma, *prev, *last;
92612
92613+ /*
92614+ * mm->mmap_sem is required to protect against another thread
92615+ * changing the mappings in case we sleep.
92616+ */
92617+ verify_mm_writelocked(mm);
92618+
92619 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
92620 return -EINVAL;
92621
92622@@ -2536,6 +3012,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92623 /* Fix up all other VM information */
92624 remove_vma_list(mm, vma);
92625
92626+ track_exec_limit(mm, start, end, 0UL);
92627+
92628 return 0;
92629 }
92630
92631@@ -2544,6 +3022,13 @@ int vm_munmap(unsigned long start, size_t len)
92632 int ret;
92633 struct mm_struct *mm = current->mm;
92634
92635+
92636+#ifdef CONFIG_PAX_SEGMEXEC
92637+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
92638+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
92639+ return -EINVAL;
92640+#endif
92641+
92642 down_write(&mm->mmap_sem);
92643 ret = do_munmap(mm, start, len);
92644 up_write(&mm->mmap_sem);
92645@@ -2557,16 +3042,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
92646 return vm_munmap(addr, len);
92647 }
92648
92649-static inline void verify_mm_writelocked(struct mm_struct *mm)
92650-{
92651-#ifdef CONFIG_DEBUG_VM
92652- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
92653- WARN_ON(1);
92654- up_read(&mm->mmap_sem);
92655- }
92656-#endif
92657-}
92658-
92659 /*
92660 * this is really a simplified "do_mmap". it only handles
92661 * anonymous maps. eventually we may be able to do some
92662@@ -2580,6 +3055,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92663 struct rb_node ** rb_link, * rb_parent;
92664 pgoff_t pgoff = addr >> PAGE_SHIFT;
92665 int error;
92666+ unsigned long charged;
92667
92668 len = PAGE_ALIGN(len);
92669 if (!len)
92670@@ -2587,16 +3063,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92671
92672 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
92673
92674+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
92675+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
92676+ flags &= ~VM_EXEC;
92677+
92678+#ifdef CONFIG_PAX_MPROTECT
92679+ if (mm->pax_flags & MF_PAX_MPROTECT)
92680+ flags &= ~VM_MAYEXEC;
92681+#endif
92682+
92683+ }
92684+#endif
92685+
92686 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
92687 if (error & ~PAGE_MASK)
92688 return error;
92689
92690+ charged = len >> PAGE_SHIFT;
92691+
92692 /*
92693 * mlock MCL_FUTURE?
92694 */
92695 if (mm->def_flags & VM_LOCKED) {
92696 unsigned long locked, lock_limit;
92697- locked = len >> PAGE_SHIFT;
92698+ locked = charged;
92699 locked += mm->locked_vm;
92700 lock_limit = rlimit(RLIMIT_MEMLOCK);
92701 lock_limit >>= PAGE_SHIFT;
92702@@ -2613,21 +3103,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92703 /*
92704 * Clear old maps. this also does some error checking for us
92705 */
92706- munmap_back:
92707 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
92708 if (do_munmap(mm, addr, len))
92709 return -ENOMEM;
92710- goto munmap_back;
92711+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
92712 }
92713
92714 /* Check against address space limits *after* clearing old maps... */
92715- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
92716+ if (!may_expand_vm(mm, charged))
92717 return -ENOMEM;
92718
92719 if (mm->map_count > sysctl_max_map_count)
92720 return -ENOMEM;
92721
92722- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
92723+ if (security_vm_enough_memory_mm(mm, charged))
92724 return -ENOMEM;
92725
92726 /* Can we just expand an old private anonymous mapping? */
92727@@ -2641,7 +3130,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92728 */
92729 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92730 if (!vma) {
92731- vm_unacct_memory(len >> PAGE_SHIFT);
92732+ vm_unacct_memory(charged);
92733 return -ENOMEM;
92734 }
92735
92736@@ -2655,10 +3144,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92737 vma_link(mm, vma, prev, rb_link, rb_parent);
92738 out:
92739 perf_event_mmap(vma);
92740- mm->total_vm += len >> PAGE_SHIFT;
92741+ mm->total_vm += charged;
92742 if (flags & VM_LOCKED)
92743- mm->locked_vm += (len >> PAGE_SHIFT);
92744+ mm->locked_vm += charged;
92745 vma->vm_flags |= VM_SOFTDIRTY;
92746+ track_exec_limit(mm, addr, addr + len, flags);
92747 return addr;
92748 }
92749
92750@@ -2720,6 +3210,7 @@ void exit_mmap(struct mm_struct *mm)
92751 while (vma) {
92752 if (vma->vm_flags & VM_ACCOUNT)
92753 nr_accounted += vma_pages(vma);
92754+ vma->vm_mirror = NULL;
92755 vma = remove_vma(vma);
92756 }
92757 vm_unacct_memory(nr_accounted);
92758@@ -2737,6 +3228,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
92759 struct vm_area_struct *prev;
92760 struct rb_node **rb_link, *rb_parent;
92761
92762+#ifdef CONFIG_PAX_SEGMEXEC
92763+ struct vm_area_struct *vma_m = NULL;
92764+#endif
92765+
92766+ if (security_mmap_addr(vma->vm_start))
92767+ return -EPERM;
92768+
92769 /*
92770 * The vm_pgoff of a purely anonymous vma should be irrelevant
92771 * until its first write fault, when page's anon_vma and index
92772@@ -2760,7 +3258,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
92773 security_vm_enough_memory_mm(mm, vma_pages(vma)))
92774 return -ENOMEM;
92775
92776+#ifdef CONFIG_PAX_SEGMEXEC
92777+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
92778+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92779+ if (!vma_m)
92780+ return -ENOMEM;
92781+ }
92782+#endif
92783+
92784 vma_link(mm, vma, prev, rb_link, rb_parent);
92785+
92786+#ifdef CONFIG_PAX_SEGMEXEC
92787+ if (vma_m)
92788+ BUG_ON(pax_mirror_vma(vma_m, vma));
92789+#endif
92790+
92791 return 0;
92792 }
92793
92794@@ -2779,6 +3291,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
92795 struct rb_node **rb_link, *rb_parent;
92796 bool faulted_in_anon_vma = true;
92797
92798+ BUG_ON(vma->vm_mirror);
92799+
92800 /*
92801 * If anonymous vma has not yet been faulted, update new pgoff
92802 * to match new location, to increase its chance of merging.
92803@@ -2843,6 +3357,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
92804 return NULL;
92805 }
92806
92807+#ifdef CONFIG_PAX_SEGMEXEC
92808+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
92809+{
92810+ struct vm_area_struct *prev_m;
92811+ struct rb_node **rb_link_m, *rb_parent_m;
92812+ struct mempolicy *pol_m;
92813+
92814+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
92815+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
92816+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
92817+ *vma_m = *vma;
92818+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
92819+ if (anon_vma_clone(vma_m, vma))
92820+ return -ENOMEM;
92821+ pol_m = vma_policy(vma_m);
92822+ mpol_get(pol_m);
92823+ set_vma_policy(vma_m, pol_m);
92824+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
92825+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
92826+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
92827+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
92828+ if (vma_m->vm_file)
92829+ get_file(vma_m->vm_file);
92830+ if (vma_m->vm_ops && vma_m->vm_ops->open)
92831+ vma_m->vm_ops->open(vma_m);
92832+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
92833+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
92834+ vma_m->vm_mirror = vma;
92835+ vma->vm_mirror = vma_m;
92836+ return 0;
92837+}
92838+#endif
92839+
92840 /*
92841 * Return true if the calling process may expand its vm space by the passed
92842 * number of pages
92843@@ -2854,6 +3401,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
92844
92845 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
92846
92847+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
92848 if (cur + npages > lim)
92849 return 0;
92850 return 1;
92851@@ -2924,6 +3472,22 @@ int install_special_mapping(struct mm_struct *mm,
92852 vma->vm_start = addr;
92853 vma->vm_end = addr + len;
92854
92855+#ifdef CONFIG_PAX_MPROTECT
92856+ if (mm->pax_flags & MF_PAX_MPROTECT) {
92857+#ifndef CONFIG_PAX_MPROTECT_COMPAT
92858+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
92859+ return -EPERM;
92860+ if (!(vm_flags & VM_EXEC))
92861+ vm_flags &= ~VM_MAYEXEC;
92862+#else
92863+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
92864+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
92865+#endif
92866+ else
92867+ vm_flags &= ~VM_MAYWRITE;
92868+ }
92869+#endif
92870+
92871 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
92872 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
92873
92874diff --git a/mm/mprotect.c b/mm/mprotect.c
92875index bb53a65..249c052 100644
92876--- a/mm/mprotect.c
92877+++ b/mm/mprotect.c
92878@@ -23,10 +23,18 @@
92879 #include <linux/mmu_notifier.h>
92880 #include <linux/migrate.h>
92881 #include <linux/perf_event.h>
92882+#include <linux/sched/sysctl.h>
92883+
92884+#ifdef CONFIG_PAX_MPROTECT
92885+#include <linux/elf.h>
92886+#include <linux/binfmts.h>
92887+#endif
92888+
92889 #include <asm/uaccess.h>
92890 #include <asm/pgtable.h>
92891 #include <asm/cacheflush.h>
92892 #include <asm/tlbflush.h>
92893+#include <asm/mmu_context.h>
92894
92895 #ifndef pgprot_modify
92896 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
92897@@ -222,6 +230,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
92898 return pages;
92899 }
92900
92901+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
92902+/* called while holding the mmap semaphor for writing except stack expansion */
92903+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
92904+{
92905+ unsigned long oldlimit, newlimit = 0UL;
92906+
92907+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
92908+ return;
92909+
92910+ spin_lock(&mm->page_table_lock);
92911+ oldlimit = mm->context.user_cs_limit;
92912+ if ((prot & VM_EXEC) && oldlimit < end)
92913+ /* USER_CS limit moved up */
92914+ newlimit = end;
92915+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
92916+ /* USER_CS limit moved down */
92917+ newlimit = start;
92918+
92919+ if (newlimit) {
92920+ mm->context.user_cs_limit = newlimit;
92921+
92922+#ifdef CONFIG_SMP
92923+ wmb();
92924+ cpus_clear(mm->context.cpu_user_cs_mask);
92925+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
92926+#endif
92927+
92928+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
92929+ }
92930+ spin_unlock(&mm->page_table_lock);
92931+ if (newlimit == end) {
92932+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
92933+
92934+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
92935+ if (is_vm_hugetlb_page(vma))
92936+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
92937+ else
92938+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
92939+ }
92940+}
92941+#endif
92942+
92943 int
92944 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
92945 unsigned long start, unsigned long end, unsigned long newflags)
92946@@ -234,11 +284,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
92947 int error;
92948 int dirty_accountable = 0;
92949
92950+#ifdef CONFIG_PAX_SEGMEXEC
92951+ struct vm_area_struct *vma_m = NULL;
92952+ unsigned long start_m, end_m;
92953+
92954+ start_m = start + SEGMEXEC_TASK_SIZE;
92955+ end_m = end + SEGMEXEC_TASK_SIZE;
92956+#endif
92957+
92958 if (newflags == oldflags) {
92959 *pprev = vma;
92960 return 0;
92961 }
92962
92963+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
92964+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
92965+
92966+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
92967+ return -ENOMEM;
92968+
92969+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
92970+ return -ENOMEM;
92971+ }
92972+
92973 /*
92974 * If we make a private mapping writable we increase our commit;
92975 * but (without finer accounting) cannot reduce our commit if we
92976@@ -255,6 +323,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
92977 }
92978 }
92979
92980+#ifdef CONFIG_PAX_SEGMEXEC
92981+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
92982+ if (start != vma->vm_start) {
92983+ error = split_vma(mm, vma, start, 1);
92984+ if (error)
92985+ goto fail;
92986+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
92987+ *pprev = (*pprev)->vm_next;
92988+ }
92989+
92990+ if (end != vma->vm_end) {
92991+ error = split_vma(mm, vma, end, 0);
92992+ if (error)
92993+ goto fail;
92994+ }
92995+
92996+ if (pax_find_mirror_vma(vma)) {
92997+ error = __do_munmap(mm, start_m, end_m - start_m);
92998+ if (error)
92999+ goto fail;
93000+ } else {
93001+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93002+ if (!vma_m) {
93003+ error = -ENOMEM;
93004+ goto fail;
93005+ }
93006+ vma->vm_flags = newflags;
93007+ error = pax_mirror_vma(vma_m, vma);
93008+ if (error) {
93009+ vma->vm_flags = oldflags;
93010+ goto fail;
93011+ }
93012+ }
93013+ }
93014+#endif
93015+
93016 /*
93017 * First try to merge with previous and/or next vma.
93018 */
93019@@ -285,9 +389,21 @@ success:
93020 * vm_flags and vm_page_prot are protected by the mmap_sem
93021 * held in write mode.
93022 */
93023+
93024+#ifdef CONFIG_PAX_SEGMEXEC
93025+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
93026+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
93027+#endif
93028+
93029 vma->vm_flags = newflags;
93030+
93031+#ifdef CONFIG_PAX_MPROTECT
93032+ if (mm->binfmt && mm->binfmt->handle_mprotect)
93033+ mm->binfmt->handle_mprotect(vma, newflags);
93034+#endif
93035+
93036 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
93037- vm_get_page_prot(newflags));
93038+ vm_get_page_prot(vma->vm_flags));
93039
93040 if (vma_wants_writenotify(vma)) {
93041 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
93042@@ -326,6 +442,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
93043 end = start + len;
93044 if (end <= start)
93045 return -ENOMEM;
93046+
93047+#ifdef CONFIG_PAX_SEGMEXEC
93048+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
93049+ if (end > SEGMEXEC_TASK_SIZE)
93050+ return -EINVAL;
93051+ } else
93052+#endif
93053+
93054+ if (end > TASK_SIZE)
93055+ return -EINVAL;
93056+
93057 if (!arch_validate_prot(prot))
93058 return -EINVAL;
93059
93060@@ -333,7 +460,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
93061 /*
93062 * Does the application expect PROT_READ to imply PROT_EXEC:
93063 */
93064- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
93065+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
93066 prot |= PROT_EXEC;
93067
93068 vm_flags = calc_vm_prot_bits(prot);
93069@@ -365,6 +492,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
93070 if (start > vma->vm_start)
93071 prev = vma;
93072
93073+#ifdef CONFIG_PAX_MPROTECT
93074+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
93075+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
93076+#endif
93077+
93078 for (nstart = start ; ; ) {
93079 unsigned long newflags;
93080
93081@@ -375,6 +507,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
93082
93083 /* newflags >> 4 shift VM_MAY% in place of VM_% */
93084 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
93085+ if (prot & (PROT_WRITE | PROT_EXEC))
93086+ gr_log_rwxmprotect(vma);
93087+
93088+ error = -EACCES;
93089+ goto out;
93090+ }
93091+
93092+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
93093 error = -EACCES;
93094 goto out;
93095 }
93096@@ -389,6 +529,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
93097 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
93098 if (error)
93099 goto out;
93100+
93101+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
93102+
93103 nstart = tmp;
93104
93105 if (nstart < prev->vm_end)
93106diff --git a/mm/mremap.c b/mm/mremap.c
93107index 0843feb..4f5b2e6 100644
93108--- a/mm/mremap.c
93109+++ b/mm/mremap.c
93110@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
93111 continue;
93112 pte = ptep_get_and_clear(mm, old_addr, old_pte);
93113 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
93114+
93115+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
93116+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
93117+ pte = pte_exprotect(pte);
93118+#endif
93119+
93120 pte = move_soft_dirty_pte(pte);
93121 set_pte_at(mm, new_addr, new_pte, pte);
93122 }
93123@@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
93124 if (is_vm_hugetlb_page(vma))
93125 goto Einval;
93126
93127+#ifdef CONFIG_PAX_SEGMEXEC
93128+ if (pax_find_mirror_vma(vma))
93129+ goto Einval;
93130+#endif
93131+
93132 /* We can't remap across vm area boundaries */
93133 if (old_len > vma->vm_end - addr)
93134 goto Efault;
93135@@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
93136 unsigned long ret = -EINVAL;
93137 unsigned long charged = 0;
93138 unsigned long map_flags;
93139+ unsigned long pax_task_size = TASK_SIZE;
93140
93141 if (new_addr & ~PAGE_MASK)
93142 goto out;
93143
93144- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
93145+#ifdef CONFIG_PAX_SEGMEXEC
93146+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
93147+ pax_task_size = SEGMEXEC_TASK_SIZE;
93148+#endif
93149+
93150+ pax_task_size -= PAGE_SIZE;
93151+
93152+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
93153 goto out;
93154
93155 /* Check if the location we're moving into overlaps the
93156 * old location at all, and fail if it does.
93157 */
93158- if ((new_addr <= addr) && (new_addr+new_len) > addr)
93159- goto out;
93160-
93161- if ((addr <= new_addr) && (addr+old_len) > new_addr)
93162+ if (addr + old_len > new_addr && new_addr + new_len > addr)
93163 goto out;
93164
93165 ret = do_munmap(mm, new_addr, new_len);
93166@@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
93167 unsigned long ret = -EINVAL;
93168 unsigned long charged = 0;
93169 bool locked = false;
93170+ unsigned long pax_task_size = TASK_SIZE;
93171
93172 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
93173 return ret;
93174@@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
93175 if (!new_len)
93176 return ret;
93177
93178+#ifdef CONFIG_PAX_SEGMEXEC
93179+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
93180+ pax_task_size = SEGMEXEC_TASK_SIZE;
93181+#endif
93182+
93183+ pax_task_size -= PAGE_SIZE;
93184+
93185+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
93186+ old_len > pax_task_size || addr > pax_task_size-old_len)
93187+ return ret;
93188+
93189 down_write(&current->mm->mmap_sem);
93190
93191 if (flags & MREMAP_FIXED) {
93192@@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
93193 new_addr = addr;
93194 }
93195 ret = addr;
93196+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
93197 goto out;
93198 }
93199 }
93200@@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
93201 goto out;
93202 }
93203
93204+ map_flags = vma->vm_flags;
93205 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
93206+ if (!(ret & ~PAGE_MASK)) {
93207+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
93208+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
93209+ }
93210 }
93211 out:
93212 if (ret & ~PAGE_MASK)
93213diff --git a/mm/nommu.c b/mm/nommu.c
93214index fec093a..8162f74 100644
93215--- a/mm/nommu.c
93216+++ b/mm/nommu.c
93217@@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
93218 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
93219 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
93220 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
93221-int heap_stack_gap = 0;
93222
93223 atomic_long_t mmap_pages_allocated;
93224
93225@@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
93226 EXPORT_SYMBOL(find_vma);
93227
93228 /*
93229- * find a VMA
93230- * - we don't extend stack VMAs under NOMMU conditions
93231- */
93232-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
93233-{
93234- return find_vma(mm, addr);
93235-}
93236-
93237-/*
93238 * expand a stack to a given address
93239 * - not supported under NOMMU conditions
93240 */
93241@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93242
93243 /* most fields are the same, copy all, and then fixup */
93244 *new = *vma;
93245+ INIT_LIST_HEAD(&new->anon_vma_chain);
93246 *region = *vma->vm_region;
93247 new->vm_region = region;
93248
93249@@ -1992,8 +1983,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
93250 }
93251 EXPORT_SYMBOL(generic_file_remap_pages);
93252
93253-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93254- unsigned long addr, void *buf, int len, int write)
93255+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93256+ unsigned long addr, void *buf, size_t len, int write)
93257 {
93258 struct vm_area_struct *vma;
93259
93260@@ -2034,8 +2025,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93261 *
93262 * The caller must hold a reference on @mm.
93263 */
93264-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93265- void *buf, int len, int write)
93266+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
93267+ void *buf, size_t len, int write)
93268 {
93269 return __access_remote_vm(NULL, mm, addr, buf, len, write);
93270 }
93271@@ -2044,7 +2035,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93272 * Access another process' address space.
93273 * - source/target buffer must be kernel space
93274 */
93275-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
93276+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
93277 {
93278 struct mm_struct *mm;
93279
93280diff --git a/mm/page-writeback.c b/mm/page-writeback.c
93281index 6380758..4064aec 100644
93282--- a/mm/page-writeback.c
93283+++ b/mm/page-writeback.c
93284@@ -690,7 +690,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
93285 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
93286 * - the bdi dirty thresh drops quickly due to change of JBOD workload
93287 */
93288-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
93289+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
93290 unsigned long thresh,
93291 unsigned long bg_thresh,
93292 unsigned long dirty,
93293diff --git a/mm/page_alloc.c b/mm/page_alloc.c
93294index 5248fe0..0f693aa 100644
93295--- a/mm/page_alloc.c
93296+++ b/mm/page_alloc.c
93297@@ -61,6 +61,7 @@
93298 #include <linux/page-debug-flags.h>
93299 #include <linux/hugetlb.h>
93300 #include <linux/sched/rt.h>
93301+#include <linux/random.h>
93302
93303 #include <asm/sections.h>
93304 #include <asm/tlbflush.h>
93305@@ -354,7 +355,7 @@ out:
93306 * This usage means that zero-order pages may not be compound.
93307 */
93308
93309-static void free_compound_page(struct page *page)
93310+void free_compound_page(struct page *page)
93311 {
93312 __free_pages_ok(page, compound_order(page));
93313 }
93314@@ -712,6 +713,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
93315 int i;
93316 int bad = 0;
93317
93318+#ifdef CONFIG_PAX_MEMORY_SANITIZE
93319+ unsigned long index = 1UL << order;
93320+#endif
93321+
93322 trace_mm_page_free(page, order);
93323 kmemcheck_free_shadow(page, order);
93324
93325@@ -728,6 +733,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
93326 debug_check_no_obj_freed(page_address(page),
93327 PAGE_SIZE << order);
93328 }
93329+
93330+#ifdef CONFIG_PAX_MEMORY_SANITIZE
93331+ for (; index; --index)
93332+ sanitize_highpage(page + index - 1);
93333+#endif
93334+
93335 arch_free_page(page, order);
93336 kernel_map_pages(page, 1 << order, 0);
93337
93338@@ -750,6 +761,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
93339 local_irq_restore(flags);
93340 }
93341
93342+#ifdef CONFIG_PAX_LATENT_ENTROPY
93343+bool __meminitdata extra_latent_entropy;
93344+
93345+static int __init setup_pax_extra_latent_entropy(char *str)
93346+{
93347+ extra_latent_entropy = true;
93348+ return 0;
93349+}
93350+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
93351+
93352+volatile u64 latent_entropy __latent_entropy;
93353+EXPORT_SYMBOL(latent_entropy);
93354+#endif
93355+
93356 void __init __free_pages_bootmem(struct page *page, unsigned int order)
93357 {
93358 unsigned int nr_pages = 1 << order;
93359@@ -765,6 +790,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
93360 __ClearPageReserved(p);
93361 set_page_count(p, 0);
93362
93363+#ifdef CONFIG_PAX_LATENT_ENTROPY
93364+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
93365+ u64 hash = 0;
93366+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
93367+ const u64 *data = lowmem_page_address(page);
93368+
93369+ for (index = 0; index < end; index++)
93370+ hash ^= hash + data[index];
93371+ latent_entropy ^= hash;
93372+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
93373+ }
93374+#endif
93375+
93376 page_zone(page)->managed_pages += nr_pages;
93377 set_page_refcounted(page);
93378 __free_pages(page, order);
93379@@ -870,8 +908,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
93380 arch_alloc_page(page, order);
93381 kernel_map_pages(page, 1 << order, 1);
93382
93383+#ifndef CONFIG_PAX_MEMORY_SANITIZE
93384 if (gfp_flags & __GFP_ZERO)
93385 prep_zero_page(page, order, gfp_flags);
93386+#endif
93387
93388 if (order && (gfp_flags & __GFP_COMP))
93389 prep_compound_page(page, order);
93390diff --git a/mm/page_io.c b/mm/page_io.c
93391index 8c79a47..a689e0d 100644
93392--- a/mm/page_io.c
93393+++ b/mm/page_io.c
93394@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
93395 struct file *swap_file = sis->swap_file;
93396 struct address_space *mapping = swap_file->f_mapping;
93397 struct iovec iov = {
93398- .iov_base = kmap(page),
93399+ .iov_base = (void __force_user *)kmap(page),
93400 .iov_len = PAGE_SIZE,
93401 };
93402
93403diff --git a/mm/percpu.c b/mm/percpu.c
93404index 0d10def..6dc822d 100644
93405--- a/mm/percpu.c
93406+++ b/mm/percpu.c
93407@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
93408 static unsigned int pcpu_high_unit_cpu __read_mostly;
93409
93410 /* the address of the first chunk which starts with the kernel static area */
93411-void *pcpu_base_addr __read_mostly;
93412+void *pcpu_base_addr __read_only;
93413 EXPORT_SYMBOL_GPL(pcpu_base_addr);
93414
93415 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
93416diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
93417index fd26d04..0cea1b0 100644
93418--- a/mm/process_vm_access.c
93419+++ b/mm/process_vm_access.c
93420@@ -13,6 +13,7 @@
93421 #include <linux/uio.h>
93422 #include <linux/sched.h>
93423 #include <linux/highmem.h>
93424+#include <linux/security.h>
93425 #include <linux/ptrace.h>
93426 #include <linux/slab.h>
93427 #include <linux/syscalls.h>
93428@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
93429 size_t iov_l_curr_offset = 0;
93430 ssize_t iov_len;
93431
93432+ return -ENOSYS; // PaX: until properly audited
93433+
93434 /*
93435 * Work out how many pages of struct pages we're going to need
93436 * when eventually calling get_user_pages
93437 */
93438 for (i = 0; i < riovcnt; i++) {
93439 iov_len = rvec[i].iov_len;
93440- if (iov_len > 0) {
93441- nr_pages_iov = ((unsigned long)rvec[i].iov_base
93442- + iov_len)
93443- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
93444- / PAGE_SIZE + 1;
93445- nr_pages = max(nr_pages, nr_pages_iov);
93446- }
93447+ if (iov_len <= 0)
93448+ continue;
93449+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
93450+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
93451+ nr_pages = max(nr_pages, nr_pages_iov);
93452 }
93453
93454 if (nr_pages == 0)
93455@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
93456 goto free_proc_pages;
93457 }
93458
93459+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
93460+ rc = -EPERM;
93461+ goto put_task_struct;
93462+ }
93463+
93464 mm = mm_access(task, PTRACE_MODE_ATTACH);
93465 if (!mm || IS_ERR(mm)) {
93466 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
93467diff --git a/mm/rmap.c b/mm/rmap.c
93468index 068522d..f539f21 100644
93469--- a/mm/rmap.c
93470+++ b/mm/rmap.c
93471@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93472 struct anon_vma *anon_vma = vma->anon_vma;
93473 struct anon_vma_chain *avc;
93474
93475+#ifdef CONFIG_PAX_SEGMEXEC
93476+ struct anon_vma_chain *avc_m = NULL;
93477+#endif
93478+
93479 might_sleep();
93480 if (unlikely(!anon_vma)) {
93481 struct mm_struct *mm = vma->vm_mm;
93482@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93483 if (!avc)
93484 goto out_enomem;
93485
93486+#ifdef CONFIG_PAX_SEGMEXEC
93487+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
93488+ if (!avc_m)
93489+ goto out_enomem_free_avc;
93490+#endif
93491+
93492 anon_vma = find_mergeable_anon_vma(vma);
93493 allocated = NULL;
93494 if (!anon_vma) {
93495@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93496 /* page_table_lock to protect against threads */
93497 spin_lock(&mm->page_table_lock);
93498 if (likely(!vma->anon_vma)) {
93499+
93500+#ifdef CONFIG_PAX_SEGMEXEC
93501+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
93502+
93503+ if (vma_m) {
93504+ BUG_ON(vma_m->anon_vma);
93505+ vma_m->anon_vma = anon_vma;
93506+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
93507+ avc_m = NULL;
93508+ }
93509+#endif
93510+
93511 vma->anon_vma = anon_vma;
93512 anon_vma_chain_link(vma, avc, anon_vma);
93513 allocated = NULL;
93514@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93515
93516 if (unlikely(allocated))
93517 put_anon_vma(allocated);
93518+
93519+#ifdef CONFIG_PAX_SEGMEXEC
93520+ if (unlikely(avc_m))
93521+ anon_vma_chain_free(avc_m);
93522+#endif
93523+
93524 if (unlikely(avc))
93525 anon_vma_chain_free(avc);
93526 }
93527 return 0;
93528
93529 out_enomem_free_avc:
93530+
93531+#ifdef CONFIG_PAX_SEGMEXEC
93532+ if (avc_m)
93533+ anon_vma_chain_free(avc_m);
93534+#endif
93535+
93536 anon_vma_chain_free(avc);
93537 out_enomem:
93538 return -ENOMEM;
93539@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
93540 * Attach the anon_vmas from src to dst.
93541 * Returns 0 on success, -ENOMEM on failure.
93542 */
93543-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
93544+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
93545 {
93546 struct anon_vma_chain *avc, *pavc;
93547 struct anon_vma *root = NULL;
93548@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
93549 * the corresponding VMA in the parent process is attached to.
93550 * Returns 0 on success, non-zero on failure.
93551 */
93552-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
93553+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
93554 {
93555 struct anon_vma_chain *avc;
93556 struct anon_vma *anon_vma;
93557@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
93558 void __init anon_vma_init(void)
93559 {
93560 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
93561- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
93562- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
93563+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
93564+ anon_vma_ctor);
93565+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
93566+ SLAB_PANIC|SLAB_NO_SANITIZE);
93567 }
93568
93569 /*
93570diff --git a/mm/shmem.c b/mm/shmem.c
93571index 902a148..58f9d59 100644
93572--- a/mm/shmem.c
93573+++ b/mm/shmem.c
93574@@ -33,7 +33,7 @@
93575 #include <linux/swap.h>
93576 #include <linux/aio.h>
93577
93578-static struct vfsmount *shm_mnt;
93579+struct vfsmount *shm_mnt;
93580
93581 #ifdef CONFIG_SHMEM
93582 /*
93583@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
93584 #define BOGO_DIRENT_SIZE 20
93585
93586 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
93587-#define SHORT_SYMLINK_LEN 128
93588+#define SHORT_SYMLINK_LEN 64
93589
93590 /*
93591 * shmem_fallocate and shmem_writepage communicate via inode->i_private
93592@@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
93593 static int shmem_xattr_validate(const char *name)
93594 {
93595 struct { const char *prefix; size_t len; } arr[] = {
93596+
93597+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
93598+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
93599+#endif
93600+
93601 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
93602 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
93603 };
93604@@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
93605 if (err)
93606 return err;
93607
93608+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
93609+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
93610+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
93611+ return -EOPNOTSUPP;
93612+ if (size > 8)
93613+ return -EINVAL;
93614+ }
93615+#endif
93616+
93617 return simple_xattr_set(&info->xattrs, name, value, size, flags);
93618 }
93619
93620@@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
93621 int err = -ENOMEM;
93622
93623 /* Round up to L1_CACHE_BYTES to resist false sharing */
93624- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
93625- L1_CACHE_BYTES), GFP_KERNEL);
93626+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
93627 if (!sbinfo)
93628 return -ENOMEM;
93629
93630diff --git a/mm/slab.c b/mm/slab.c
93631index eb043bf..d82f5a8 100644
93632--- a/mm/slab.c
93633+++ b/mm/slab.c
93634@@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
93635 if ((x)->max_freeable < i) \
93636 (x)->max_freeable = i; \
93637 } while (0)
93638-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
93639-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
93640-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
93641-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
93642+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
93643+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
93644+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
93645+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
93646+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
93647+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
93648 #else
93649 #define STATS_INC_ACTIVE(x) do { } while (0)
93650 #define STATS_DEC_ACTIVE(x) do { } while (0)
93651@@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
93652 #define STATS_INC_ALLOCMISS(x) do { } while (0)
93653 #define STATS_INC_FREEHIT(x) do { } while (0)
93654 #define STATS_INC_FREEMISS(x) do { } while (0)
93655+#define STATS_INC_SANITIZED(x) do { } while (0)
93656+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
93657 #endif
93658
93659 #if DEBUG
93660@@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
93661 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
93662 */
93663 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
93664- const struct page *page, void *obj)
93665+ const struct page *page, const void *obj)
93666 {
93667 u32 offset = (obj - page->s_mem);
93668 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
93669@@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
93670 */
93671
93672 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
93673- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
93674+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
93675
93676 if (INDEX_AC != INDEX_NODE)
93677 kmalloc_caches[INDEX_NODE] =
93678 create_kmalloc_cache("kmalloc-node",
93679- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
93680+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
93681
93682 slab_early_init = 0;
93683
93684@@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
93685 struct array_cache *ac = cpu_cache_get(cachep);
93686
93687 check_irq_off();
93688+
93689+#ifdef CONFIG_PAX_MEMORY_SANITIZE
93690+ if (pax_sanitize_slab) {
93691+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
93692+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
93693+
93694+ if (cachep->ctor)
93695+ cachep->ctor(objp);
93696+
93697+ STATS_INC_SANITIZED(cachep);
93698+ } else
93699+ STATS_INC_NOT_SANITIZED(cachep);
93700+ }
93701+#endif
93702+
93703 kmemleak_free_recursive(objp, cachep->flags);
93704 objp = cache_free_debugcheck(cachep, objp, caller);
93705
93706@@ -3656,6 +3675,7 @@ void kfree(const void *objp)
93707
93708 if (unlikely(ZERO_OR_NULL_PTR(objp)))
93709 return;
93710+ VM_BUG_ON(!virt_addr_valid(objp));
93711 local_irq_save(flags);
93712 kfree_debugcheck(objp);
93713 c = virt_to_cache(objp);
93714@@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
93715 }
93716 /* cpu stats */
93717 {
93718- unsigned long allochit = atomic_read(&cachep->allochit);
93719- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
93720- unsigned long freehit = atomic_read(&cachep->freehit);
93721- unsigned long freemiss = atomic_read(&cachep->freemiss);
93722+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
93723+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
93724+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
93725+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
93726
93727 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
93728 allochit, allocmiss, freehit, freemiss);
93729 }
93730+#ifdef CONFIG_PAX_MEMORY_SANITIZE
93731+ {
93732+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
93733+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
93734+
93735+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
93736+ }
93737+#endif
93738 #endif
93739 }
93740
93741@@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
93742 static int __init slab_proc_init(void)
93743 {
93744 #ifdef CONFIG_DEBUG_SLAB_LEAK
93745- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
93746+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
93747 #endif
93748 return 0;
93749 }
93750 module_init(slab_proc_init);
93751 #endif
93752
93753+bool is_usercopy_object(const void *ptr)
93754+{
93755+ struct page *page;
93756+ struct kmem_cache *cachep;
93757+
93758+ if (ZERO_OR_NULL_PTR(ptr))
93759+ return false;
93760+
93761+ if (!slab_is_available())
93762+ return false;
93763+
93764+ if (!virt_addr_valid(ptr))
93765+ return false;
93766+
93767+ page = virt_to_head_page(ptr);
93768+
93769+ if (!PageSlab(page))
93770+ return false;
93771+
93772+ cachep = page->slab_cache;
93773+ return cachep->flags & SLAB_USERCOPY;
93774+}
93775+
93776+#ifdef CONFIG_PAX_USERCOPY
93777+const char *check_heap_object(const void *ptr, unsigned long n)
93778+{
93779+ struct page *page;
93780+ struct kmem_cache *cachep;
93781+ unsigned int objnr;
93782+ unsigned long offset;
93783+
93784+ if (ZERO_OR_NULL_PTR(ptr))
93785+ return "<null>";
93786+
93787+ if (!virt_addr_valid(ptr))
93788+ return NULL;
93789+
93790+ page = virt_to_head_page(ptr);
93791+
93792+ if (!PageSlab(page))
93793+ return NULL;
93794+
93795+ cachep = page->slab_cache;
93796+ if (!(cachep->flags & SLAB_USERCOPY))
93797+ return cachep->name;
93798+
93799+ objnr = obj_to_index(cachep, page, ptr);
93800+ BUG_ON(objnr >= cachep->num);
93801+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
93802+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
93803+ return NULL;
93804+
93805+ return cachep->name;
93806+}
93807+#endif
93808+
93809 /**
93810 * ksize - get the actual amount of memory allocated for a given object
93811 * @objp: Pointer to the object
93812diff --git a/mm/slab.h b/mm/slab.h
93813index 0859c42..2f7b737 100644
93814--- a/mm/slab.h
93815+++ b/mm/slab.h
93816@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
93817 /* The slab cache that manages slab cache information */
93818 extern struct kmem_cache *kmem_cache;
93819
93820+#ifdef CONFIG_PAX_MEMORY_SANITIZE
93821+#ifdef CONFIG_X86_64
93822+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
93823+#else
93824+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
93825+#endif
93826+extern bool pax_sanitize_slab;
93827+#endif
93828+
93829 unsigned long calculate_alignment(unsigned long flags,
93830 unsigned long align, unsigned long size);
93831
93832@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
93833
93834 /* Legal flag mask for kmem_cache_create(), for various configurations */
93835 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
93836- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
93837+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
93838+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
93839
93840 #if defined(CONFIG_DEBUG_SLAB)
93841 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
93842@@ -233,6 +243,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
93843 return s;
93844
93845 page = virt_to_head_page(x);
93846+
93847+ BUG_ON(!PageSlab(page));
93848+
93849 cachep = page->slab_cache;
93850 if (slab_equal_or_root(cachep, s))
93851 return cachep;
93852diff --git a/mm/slab_common.c b/mm/slab_common.c
93853index 0b7bb39..334c328 100644
93854--- a/mm/slab_common.c
93855+++ b/mm/slab_common.c
93856@@ -23,11 +23,22 @@
93857
93858 #include "slab.h"
93859
93860-enum slab_state slab_state;
93861+enum slab_state slab_state __read_only;
93862 LIST_HEAD(slab_caches);
93863 DEFINE_MUTEX(slab_mutex);
93864 struct kmem_cache *kmem_cache;
93865
93866+#ifdef CONFIG_PAX_MEMORY_SANITIZE
93867+bool pax_sanitize_slab __read_only = true;
93868+static int __init pax_sanitize_slab_setup(char *str)
93869+{
93870+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
93871+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
93872+ return 1;
93873+}
93874+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
93875+#endif
93876+
93877 #ifdef CONFIG_DEBUG_VM
93878 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
93879 size_t size)
93880@@ -212,7 +223,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
93881
93882 err = __kmem_cache_create(s, flags);
93883 if (!err) {
93884- s->refcount = 1;
93885+ atomic_set(&s->refcount, 1);
93886 list_add(&s->list, &slab_caches);
93887 memcg_cache_list_add(memcg, s);
93888 } else {
93889@@ -258,8 +269,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
93890
93891 get_online_cpus();
93892 mutex_lock(&slab_mutex);
93893- s->refcount--;
93894- if (!s->refcount) {
93895+ if (atomic_dec_and_test(&s->refcount)) {
93896 list_del(&s->list);
93897
93898 if (!__kmem_cache_shutdown(s)) {
93899@@ -305,7 +315,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
93900 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
93901 name, size, err);
93902
93903- s->refcount = -1; /* Exempt from merging for now */
93904+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
93905 }
93906
93907 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
93908@@ -318,7 +328,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
93909
93910 create_boot_cache(s, name, size, flags);
93911 list_add(&s->list, &slab_caches);
93912- s->refcount = 1;
93913+ atomic_set(&s->refcount, 1);
93914 return s;
93915 }
93916
93917@@ -330,6 +340,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
93918 EXPORT_SYMBOL(kmalloc_dma_caches);
93919 #endif
93920
93921+#ifdef CONFIG_PAX_USERCOPY_SLABS
93922+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
93923+EXPORT_SYMBOL(kmalloc_usercopy_caches);
93924+#endif
93925+
93926 /*
93927 * Conversion table for small slabs sizes / 8 to the index in the
93928 * kmalloc array. This is necessary for slabs < 192 since we have non power
93929@@ -394,6 +409,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
93930 return kmalloc_dma_caches[index];
93931
93932 #endif
93933+
93934+#ifdef CONFIG_PAX_USERCOPY_SLABS
93935+ if (unlikely((flags & GFP_USERCOPY)))
93936+ return kmalloc_usercopy_caches[index];
93937+
93938+#endif
93939+
93940 return kmalloc_caches[index];
93941 }
93942
93943@@ -450,7 +472,7 @@ void __init create_kmalloc_caches(unsigned long flags)
93944 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
93945 if (!kmalloc_caches[i]) {
93946 kmalloc_caches[i] = create_kmalloc_cache(NULL,
93947- 1 << i, flags);
93948+ 1 << i, SLAB_USERCOPY | flags);
93949 }
93950
93951 /*
93952@@ -459,10 +481,10 @@ void __init create_kmalloc_caches(unsigned long flags)
93953 * earlier power of two caches
93954 */
93955 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
93956- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
93957+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
93958
93959 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
93960- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
93961+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
93962 }
93963
93964 /* Kmalloc array is now usable */
93965@@ -495,6 +517,23 @@ void __init create_kmalloc_caches(unsigned long flags)
93966 }
93967 }
93968 #endif
93969+
93970+#ifdef CONFIG_PAX_USERCOPY_SLABS
93971+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
93972+ struct kmem_cache *s = kmalloc_caches[i];
93973+
93974+ if (s) {
93975+ int size = kmalloc_size(i);
93976+ char *n = kasprintf(GFP_NOWAIT,
93977+ "usercopy-kmalloc-%d", size);
93978+
93979+ BUG_ON(!n);
93980+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
93981+ size, SLAB_USERCOPY | flags);
93982+ }
93983+ }
93984+#endif
93985+
93986 }
93987 #endif /* !CONFIG_SLOB */
93988
93989@@ -535,6 +574,9 @@ void print_slabinfo_header(struct seq_file *m)
93990 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
93991 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
93992 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
93993+#ifdef CONFIG_PAX_MEMORY_SANITIZE
93994+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
93995+#endif
93996 #endif
93997 seq_putc(m, '\n');
93998 }
93999diff --git a/mm/slob.c b/mm/slob.c
94000index 4bf8809..98a6914 100644
94001--- a/mm/slob.c
94002+++ b/mm/slob.c
94003@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
94004 /*
94005 * Return the size of a slob block.
94006 */
94007-static slobidx_t slob_units(slob_t *s)
94008+static slobidx_t slob_units(const slob_t *s)
94009 {
94010 if (s->units > 0)
94011 return s->units;
94012@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
94013 /*
94014 * Return the next free slob block pointer after this one.
94015 */
94016-static slob_t *slob_next(slob_t *s)
94017+static slob_t *slob_next(const slob_t *s)
94018 {
94019 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
94020 slobidx_t next;
94021@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
94022 /*
94023 * Returns true if s is the last free block in its page.
94024 */
94025-static int slob_last(slob_t *s)
94026+static int slob_last(const slob_t *s)
94027 {
94028 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
94029 }
94030
94031-static void *slob_new_pages(gfp_t gfp, int order, int node)
94032+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
94033 {
94034- void *page;
94035+ struct page *page;
94036
94037 #ifdef CONFIG_NUMA
94038 if (node != NUMA_NO_NODE)
94039@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
94040 if (!page)
94041 return NULL;
94042
94043- return page_address(page);
94044+ __SetPageSlab(page);
94045+ return page;
94046 }
94047
94048-static void slob_free_pages(void *b, int order)
94049+static void slob_free_pages(struct page *sp, int order)
94050 {
94051 if (current->reclaim_state)
94052 current->reclaim_state->reclaimed_slab += 1 << order;
94053- free_pages((unsigned long)b, order);
94054+ __ClearPageSlab(sp);
94055+ page_mapcount_reset(sp);
94056+ sp->private = 0;
94057+ __free_pages(sp, order);
94058 }
94059
94060 /*
94061@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
94062
94063 /* Not enough space: must allocate a new page */
94064 if (!b) {
94065- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
94066- if (!b)
94067+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
94068+ if (!sp)
94069 return NULL;
94070- sp = virt_to_page(b);
94071- __SetPageSlab(sp);
94072+ b = page_address(sp);
94073
94074 spin_lock_irqsave(&slob_lock, flags);
94075 sp->units = SLOB_UNITS(PAGE_SIZE);
94076 sp->freelist = b;
94077+ sp->private = 0;
94078 INIT_LIST_HEAD(&sp->list);
94079 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
94080 set_slob_page_free(sp, slob_list);
94081@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
94082 if (slob_page_free(sp))
94083 clear_slob_page_free(sp);
94084 spin_unlock_irqrestore(&slob_lock, flags);
94085- __ClearPageSlab(sp);
94086- page_mapcount_reset(sp);
94087- slob_free_pages(b, 0);
94088+ slob_free_pages(sp, 0);
94089 return;
94090 }
94091
94092+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94093+ if (pax_sanitize_slab)
94094+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
94095+#endif
94096+
94097 if (!slob_page_free(sp)) {
94098 /* This slob page is about to become partially free. Easy! */
94099 sp->units = units;
94100@@ -424,11 +431,10 @@ out:
94101 */
94102
94103 static __always_inline void *
94104-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
94105+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
94106 {
94107- unsigned int *m;
94108- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
94109- void *ret;
94110+ slob_t *m;
94111+ void *ret = NULL;
94112
94113 gfp &= gfp_allowed_mask;
94114
94115@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
94116
94117 if (!m)
94118 return NULL;
94119- *m = size;
94120+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
94121+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
94122+ m[0].units = size;
94123+ m[1].units = align;
94124 ret = (void *)m + align;
94125
94126 trace_kmalloc_node(caller, ret,
94127 size, size + align, gfp, node);
94128 } else {
94129 unsigned int order = get_order(size);
94130+ struct page *page;
94131
94132 if (likely(order))
94133 gfp |= __GFP_COMP;
94134- ret = slob_new_pages(gfp, order, node);
94135+ page = slob_new_pages(gfp, order, node);
94136+ if (page) {
94137+ ret = page_address(page);
94138+ page->private = size;
94139+ }
94140
94141 trace_kmalloc_node(caller, ret,
94142 size, PAGE_SIZE << order, gfp, node);
94143 }
94144
94145- kmemleak_alloc(ret, size, 1, gfp);
94146+ return ret;
94147+}
94148+
94149+static __always_inline void *
94150+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
94151+{
94152+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
94153+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
94154+
94155+ if (!ZERO_OR_NULL_PTR(ret))
94156+ kmemleak_alloc(ret, size, 1, gfp);
94157 return ret;
94158 }
94159
94160@@ -493,34 +517,112 @@ void kfree(const void *block)
94161 return;
94162 kmemleak_free(block);
94163
94164+ VM_BUG_ON(!virt_addr_valid(block));
94165 sp = virt_to_page(block);
94166- if (PageSlab(sp)) {
94167+ VM_BUG_ON(!PageSlab(sp));
94168+ if (!sp->private) {
94169 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
94170- unsigned int *m = (unsigned int *)(block - align);
94171- slob_free(m, *m + align);
94172- } else
94173+ slob_t *m = (slob_t *)(block - align);
94174+ slob_free(m, m[0].units + align);
94175+ } else {
94176+ __ClearPageSlab(sp);
94177+ page_mapcount_reset(sp);
94178+ sp->private = 0;
94179 __free_pages(sp, compound_order(sp));
94180+ }
94181 }
94182 EXPORT_SYMBOL(kfree);
94183
94184+bool is_usercopy_object(const void *ptr)
94185+{
94186+ if (!slab_is_available())
94187+ return false;
94188+
94189+ // PAX: TODO
94190+
94191+ return false;
94192+}
94193+
94194+#ifdef CONFIG_PAX_USERCOPY
94195+const char *check_heap_object(const void *ptr, unsigned long n)
94196+{
94197+ struct page *page;
94198+ const slob_t *free;
94199+ const void *base;
94200+ unsigned long flags;
94201+
94202+ if (ZERO_OR_NULL_PTR(ptr))
94203+ return "<null>";
94204+
94205+ if (!virt_addr_valid(ptr))
94206+ return NULL;
94207+
94208+ page = virt_to_head_page(ptr);
94209+ if (!PageSlab(page))
94210+ return NULL;
94211+
94212+ if (page->private) {
94213+ base = page;
94214+ if (base <= ptr && n <= page->private - (ptr - base))
94215+ return NULL;
94216+ return "<slob>";
94217+ }
94218+
94219+ /* some tricky double walking to find the chunk */
94220+ spin_lock_irqsave(&slob_lock, flags);
94221+ base = (void *)((unsigned long)ptr & PAGE_MASK);
94222+ free = page->freelist;
94223+
94224+ while (!slob_last(free) && (void *)free <= ptr) {
94225+ base = free + slob_units(free);
94226+ free = slob_next(free);
94227+ }
94228+
94229+ while (base < (void *)free) {
94230+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
94231+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
94232+ int offset;
94233+
94234+ if (ptr < base + align)
94235+ break;
94236+
94237+ offset = ptr - base - align;
94238+ if (offset >= m) {
94239+ base += size;
94240+ continue;
94241+ }
94242+
94243+ if (n > m - offset)
94244+ break;
94245+
94246+ spin_unlock_irqrestore(&slob_lock, flags);
94247+ return NULL;
94248+ }
94249+
94250+ spin_unlock_irqrestore(&slob_lock, flags);
94251+ return "<slob>";
94252+}
94253+#endif
94254+
94255 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
94256 size_t ksize(const void *block)
94257 {
94258 struct page *sp;
94259 int align;
94260- unsigned int *m;
94261+ slob_t *m;
94262
94263 BUG_ON(!block);
94264 if (unlikely(block == ZERO_SIZE_PTR))
94265 return 0;
94266
94267 sp = virt_to_page(block);
94268- if (unlikely(!PageSlab(sp)))
94269- return PAGE_SIZE << compound_order(sp);
94270+ VM_BUG_ON(!PageSlab(sp));
94271+ if (sp->private)
94272+ return sp->private;
94273
94274 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
94275- m = (unsigned int *)(block - align);
94276- return SLOB_UNITS(*m) * SLOB_UNIT;
94277+ m = (slob_t *)(block - align);
94278+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
94279 }
94280 EXPORT_SYMBOL(ksize);
94281
94282@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
94283
94284 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
94285 {
94286- void *b;
94287+ void *b = NULL;
94288
94289 flags &= gfp_allowed_mask;
94290
94291 lockdep_trace_alloc(flags);
94292
94293+#ifdef CONFIG_PAX_USERCOPY_SLABS
94294+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
94295+#else
94296 if (c->size < PAGE_SIZE) {
94297 b = slob_alloc(c->size, flags, c->align, node);
94298 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
94299 SLOB_UNITS(c->size) * SLOB_UNIT,
94300 flags, node);
94301 } else {
94302- b = slob_new_pages(flags, get_order(c->size), node);
94303+ struct page *sp;
94304+
94305+ sp = slob_new_pages(flags, get_order(c->size), node);
94306+ if (sp) {
94307+ b = page_address(sp);
94308+ sp->private = c->size;
94309+ }
94310 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
94311 PAGE_SIZE << get_order(c->size),
94312 flags, node);
94313 }
94314+#endif
94315
94316 if (b && c->ctor)
94317 c->ctor(b);
94318@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
94319
94320 static void __kmem_cache_free(void *b, int size)
94321 {
94322- if (size < PAGE_SIZE)
94323+ struct page *sp;
94324+
94325+ sp = virt_to_page(b);
94326+ BUG_ON(!PageSlab(sp));
94327+ if (!sp->private)
94328 slob_free(b, size);
94329 else
94330- slob_free_pages(b, get_order(size));
94331+ slob_free_pages(sp, get_order(size));
94332 }
94333
94334 static void kmem_rcu_free(struct rcu_head *head)
94335@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
94336
94337 void kmem_cache_free(struct kmem_cache *c, void *b)
94338 {
94339+ int size = c->size;
94340+
94341+#ifdef CONFIG_PAX_USERCOPY_SLABS
94342+ if (size + c->align < PAGE_SIZE) {
94343+ size += c->align;
94344+ b -= c->align;
94345+ }
94346+#endif
94347+
94348 kmemleak_free_recursive(b, c->flags);
94349 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
94350 struct slob_rcu *slob_rcu;
94351- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
94352- slob_rcu->size = c->size;
94353+ slob_rcu = b + (size - sizeof(struct slob_rcu));
94354+ slob_rcu->size = size;
94355 call_rcu(&slob_rcu->head, kmem_rcu_free);
94356 } else {
94357- __kmem_cache_free(b, c->size);
94358+ __kmem_cache_free(b, size);
94359 }
94360
94361+#ifdef CONFIG_PAX_USERCOPY_SLABS
94362+ trace_kfree(_RET_IP_, b);
94363+#else
94364 trace_kmem_cache_free(_RET_IP_, b);
94365+#endif
94366+
94367 }
94368 EXPORT_SYMBOL(kmem_cache_free);
94369
94370diff --git a/mm/slub.c b/mm/slub.c
94371index 545a170..a086226 100644
94372--- a/mm/slub.c
94373+++ b/mm/slub.c
94374@@ -207,7 +207,7 @@ struct track {
94375
94376 enum track_item { TRACK_ALLOC, TRACK_FREE };
94377
94378-#ifdef CONFIG_SYSFS
94379+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94380 static int sysfs_slab_add(struct kmem_cache *);
94381 static int sysfs_slab_alias(struct kmem_cache *, const char *);
94382 static void sysfs_slab_remove(struct kmem_cache *);
94383@@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
94384 if (!t->addr)
94385 return;
94386
94387- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
94388+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
94389 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
94390 #ifdef CONFIG_STACKTRACE
94391 {
94392@@ -2643,6 +2643,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
94393
94394 slab_free_hook(s, x);
94395
94396+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94397+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
94398+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
94399+ if (s->ctor)
94400+ s->ctor(x);
94401+ }
94402+#endif
94403+
94404 redo:
94405 /*
94406 * Determine the currently cpus per cpu slab.
94407@@ -2710,7 +2718,7 @@ static int slub_min_objects;
94408 * Merge control. If this is set then no merging of slab caches will occur.
94409 * (Could be removed. This was introduced to pacify the merge skeptics.)
94410 */
94411-static int slub_nomerge;
94412+static int slub_nomerge = 1;
94413
94414 /*
94415 * Calculate the order of allocation given an slab object size.
94416@@ -2987,6 +2995,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
94417 s->inuse = size;
94418
94419 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
94420+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94421+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
94422+#endif
94423 s->ctor)) {
94424 /*
94425 * Relocate free pointer after the object if it is not
94426@@ -3332,6 +3343,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
94427 EXPORT_SYMBOL(__kmalloc_node);
94428 #endif
94429
94430+bool is_usercopy_object(const void *ptr)
94431+{
94432+ struct page *page;
94433+ struct kmem_cache *s;
94434+
94435+ if (ZERO_OR_NULL_PTR(ptr))
94436+ return false;
94437+
94438+ if (!slab_is_available())
94439+ return false;
94440+
94441+ if (!virt_addr_valid(ptr))
94442+ return false;
94443+
94444+ page = virt_to_head_page(ptr);
94445+
94446+ if (!PageSlab(page))
94447+ return false;
94448+
94449+ s = page->slab_cache;
94450+ return s->flags & SLAB_USERCOPY;
94451+}
94452+
94453+#ifdef CONFIG_PAX_USERCOPY
94454+const char *check_heap_object(const void *ptr, unsigned long n)
94455+{
94456+ struct page *page;
94457+ struct kmem_cache *s;
94458+ unsigned long offset;
94459+
94460+ if (ZERO_OR_NULL_PTR(ptr))
94461+ return "<null>";
94462+
94463+ if (!virt_addr_valid(ptr))
94464+ return NULL;
94465+
94466+ page = virt_to_head_page(ptr);
94467+
94468+ if (!PageSlab(page))
94469+ return NULL;
94470+
94471+ s = page->slab_cache;
94472+ if (!(s->flags & SLAB_USERCOPY))
94473+ return s->name;
94474+
94475+ offset = (ptr - page_address(page)) % s->size;
94476+ if (offset <= s->object_size && n <= s->object_size - offset)
94477+ return NULL;
94478+
94479+ return s->name;
94480+}
94481+#endif
94482+
94483 size_t ksize(const void *object)
94484 {
94485 struct page *page;
94486@@ -3360,6 +3424,7 @@ void kfree(const void *x)
94487 if (unlikely(ZERO_OR_NULL_PTR(x)))
94488 return;
94489
94490+ VM_BUG_ON(!virt_addr_valid(x));
94491 page = virt_to_head_page(x);
94492 if (unlikely(!PageSlab(page))) {
94493 BUG_ON(!PageCompound(page));
94494@@ -3665,7 +3730,7 @@ static int slab_unmergeable(struct kmem_cache *s)
94495 /*
94496 * We may have set a slab to be unmergeable during bootstrap.
94497 */
94498- if (s->refcount < 0)
94499+ if (atomic_read(&s->refcount) < 0)
94500 return 1;
94501
94502 return 0;
94503@@ -3723,7 +3788,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
94504
94505 s = find_mergeable(memcg, size, align, flags, name, ctor);
94506 if (s) {
94507- s->refcount++;
94508+ atomic_inc(&s->refcount);
94509 /*
94510 * Adjust the object sizes so that we clear
94511 * the complete object on kzalloc.
94512@@ -3732,7 +3797,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
94513 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
94514
94515 if (sysfs_slab_alias(s, name)) {
94516- s->refcount--;
94517+ atomic_dec(&s->refcount);
94518 s = NULL;
94519 }
94520 }
94521@@ -3852,7 +3917,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
94522 }
94523 #endif
94524
94525-#ifdef CONFIG_SYSFS
94526+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94527 static int count_inuse(struct page *page)
94528 {
94529 return page->inuse;
94530@@ -4241,12 +4306,12 @@ static void resiliency_test(void)
94531 validate_slab_cache(kmalloc_caches[9]);
94532 }
94533 #else
94534-#ifdef CONFIG_SYSFS
94535+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94536 static void resiliency_test(void) {};
94537 #endif
94538 #endif
94539
94540-#ifdef CONFIG_SYSFS
94541+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94542 enum slab_stat_type {
94543 SL_ALL, /* All slabs */
94544 SL_PARTIAL, /* Only partially allocated slabs */
94545@@ -4486,7 +4551,7 @@ SLAB_ATTR_RO(ctor);
94546
94547 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
94548 {
94549- return sprintf(buf, "%d\n", s->refcount - 1);
94550+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
94551 }
94552 SLAB_ATTR_RO(aliases);
94553
94554@@ -4574,6 +4639,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
94555 SLAB_ATTR_RO(cache_dma);
94556 #endif
94557
94558+#ifdef CONFIG_PAX_USERCOPY_SLABS
94559+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
94560+{
94561+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
94562+}
94563+SLAB_ATTR_RO(usercopy);
94564+#endif
94565+
94566 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
94567 {
94568 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
94569@@ -4908,6 +4981,9 @@ static struct attribute *slab_attrs[] = {
94570 #ifdef CONFIG_ZONE_DMA
94571 &cache_dma_attr.attr,
94572 #endif
94573+#ifdef CONFIG_PAX_USERCOPY_SLABS
94574+ &usercopy_attr.attr,
94575+#endif
94576 #ifdef CONFIG_NUMA
94577 &remote_node_defrag_ratio_attr.attr,
94578 #endif
94579@@ -5140,6 +5216,7 @@ static char *create_unique_id(struct kmem_cache *s)
94580 return name;
94581 }
94582
94583+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94584 static int sysfs_slab_add(struct kmem_cache *s)
94585 {
94586 int err;
94587@@ -5163,7 +5240,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
94588 }
94589
94590 s->kobj.kset = slab_kset;
94591- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
94592+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
94593 if (err) {
94594 kobject_put(&s->kobj);
94595 return err;
94596@@ -5197,6 +5274,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
94597 kobject_del(&s->kobj);
94598 kobject_put(&s->kobj);
94599 }
94600+#endif
94601
94602 /*
94603 * Need to buffer aliases during bootup until sysfs becomes
94604@@ -5210,6 +5288,7 @@ struct saved_alias {
94605
94606 static struct saved_alias *alias_list;
94607
94608+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94609 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
94610 {
94611 struct saved_alias *al;
94612@@ -5232,6 +5311,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
94613 alias_list = al;
94614 return 0;
94615 }
94616+#endif
94617
94618 static int __init slab_sysfs_init(void)
94619 {
94620diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
94621index 27eeab3..7c3f7f2 100644
94622--- a/mm/sparse-vmemmap.c
94623+++ b/mm/sparse-vmemmap.c
94624@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
94625 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
94626 if (!p)
94627 return NULL;
94628- pud_populate(&init_mm, pud, p);
94629+ pud_populate_kernel(&init_mm, pud, p);
94630 }
94631 return pud;
94632 }
94633@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
94634 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
94635 if (!p)
94636 return NULL;
94637- pgd_populate(&init_mm, pgd, p);
94638+ pgd_populate_kernel(&init_mm, pgd, p);
94639 }
94640 return pgd;
94641 }
94642diff --git a/mm/sparse.c b/mm/sparse.c
94643index 8cc7be0..d0f7d7a 100644
94644--- a/mm/sparse.c
94645+++ b/mm/sparse.c
94646@@ -745,7 +745,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
94647
94648 for (i = 0; i < PAGES_PER_SECTION; i++) {
94649 if (PageHWPoison(&memmap[i])) {
94650- atomic_long_sub(1, &num_poisoned_pages);
94651+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
94652 ClearPageHWPoison(&memmap[i]);
94653 }
94654 }
94655diff --git a/mm/swap.c b/mm/swap.c
94656index 84b26aa..ce39899 100644
94657--- a/mm/swap.c
94658+++ b/mm/swap.c
94659@@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
94660
94661 __page_cache_release(page);
94662 dtor = get_compound_page_dtor(page);
94663+ if (!PageHuge(page))
94664+ BUG_ON(dtor != free_compound_page);
94665 (*dtor)(page);
94666 }
94667
94668diff --git a/mm/swapfile.c b/mm/swapfile.c
94669index 612a7c9..66b0f5a 100644
94670--- a/mm/swapfile.c
94671+++ b/mm/swapfile.c
94672@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
94673
94674 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
94675 /* Activity counter to indicate that a swapon or swapoff has occurred */
94676-static atomic_t proc_poll_event = ATOMIC_INIT(0);
94677+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
94678
94679 static inline unsigned char swap_count(unsigned char ent)
94680 {
94681@@ -1949,7 +1949,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
94682 }
94683 filp_close(swap_file, NULL);
94684 err = 0;
94685- atomic_inc(&proc_poll_event);
94686+ atomic_inc_unchecked(&proc_poll_event);
94687 wake_up_interruptible(&proc_poll_wait);
94688
94689 out_dput:
94690@@ -1966,8 +1966,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
94691
94692 poll_wait(file, &proc_poll_wait, wait);
94693
94694- if (seq->poll_event != atomic_read(&proc_poll_event)) {
94695- seq->poll_event = atomic_read(&proc_poll_event);
94696+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
94697+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
94698 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
94699 }
94700
94701@@ -2065,7 +2065,7 @@ static int swaps_open(struct inode *inode, struct file *file)
94702 return ret;
94703
94704 seq = file->private_data;
94705- seq->poll_event = atomic_read(&proc_poll_event);
94706+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
94707 return 0;
94708 }
94709
94710@@ -2524,7 +2524,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
94711 (frontswap_map) ? "FS" : "");
94712
94713 mutex_unlock(&swapon_mutex);
94714- atomic_inc(&proc_poll_event);
94715+ atomic_inc_unchecked(&proc_poll_event);
94716 wake_up_interruptible(&proc_poll_wait);
94717
94718 if (S_ISREG(inode->i_mode))
94719diff --git a/mm/util.c b/mm/util.c
94720index 808f375..e4764b5 100644
94721--- a/mm/util.c
94722+++ b/mm/util.c
94723@@ -297,6 +297,12 @@ done:
94724 void arch_pick_mmap_layout(struct mm_struct *mm)
94725 {
94726 mm->mmap_base = TASK_UNMAPPED_BASE;
94727+
94728+#ifdef CONFIG_PAX_RANDMMAP
94729+ if (mm->pax_flags & MF_PAX_RANDMMAP)
94730+ mm->mmap_base += mm->delta_mmap;
94731+#endif
94732+
94733 mm->get_unmapped_area = arch_get_unmapped_area;
94734 }
94735 #endif
94736diff --git a/mm/vmalloc.c b/mm/vmalloc.c
94737index 0fdf968..d6686e8 100644
94738--- a/mm/vmalloc.c
94739+++ b/mm/vmalloc.c
94740@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
94741
94742 pte = pte_offset_kernel(pmd, addr);
94743 do {
94744- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
94745- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
94746+
94747+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
94748+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
94749+ BUG_ON(!pte_exec(*pte));
94750+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
94751+ continue;
94752+ }
94753+#endif
94754+
94755+ {
94756+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
94757+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
94758+ }
94759 } while (pte++, addr += PAGE_SIZE, addr != end);
94760 }
94761
94762@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
94763 pte = pte_alloc_kernel(pmd, addr);
94764 if (!pte)
94765 return -ENOMEM;
94766+
94767+ pax_open_kernel();
94768 do {
94769 struct page *page = pages[*nr];
94770
94771- if (WARN_ON(!pte_none(*pte)))
94772+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
94773+ if (pgprot_val(prot) & _PAGE_NX)
94774+#endif
94775+
94776+ if (!pte_none(*pte)) {
94777+ pax_close_kernel();
94778+ WARN_ON(1);
94779 return -EBUSY;
94780- if (WARN_ON(!page))
94781+ }
94782+ if (!page) {
94783+ pax_close_kernel();
94784+ WARN_ON(1);
94785 return -ENOMEM;
94786+ }
94787 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
94788 (*nr)++;
94789 } while (pte++, addr += PAGE_SIZE, addr != end);
94790+ pax_close_kernel();
94791 return 0;
94792 }
94793
94794@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
94795 pmd_t *pmd;
94796 unsigned long next;
94797
94798- pmd = pmd_alloc(&init_mm, pud, addr);
94799+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
94800 if (!pmd)
94801 return -ENOMEM;
94802 do {
94803@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
94804 pud_t *pud;
94805 unsigned long next;
94806
94807- pud = pud_alloc(&init_mm, pgd, addr);
94808+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
94809 if (!pud)
94810 return -ENOMEM;
94811 do {
94812@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
94813 if (addr >= MODULES_VADDR && addr < MODULES_END)
94814 return 1;
94815 #endif
94816+
94817+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
94818+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
94819+ return 1;
94820+#endif
94821+
94822 return is_vmalloc_addr(x);
94823 }
94824
94825@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
94826
94827 if (!pgd_none(*pgd)) {
94828 pud_t *pud = pud_offset(pgd, addr);
94829+#ifdef CONFIG_X86
94830+ if (!pud_large(*pud))
94831+#endif
94832 if (!pud_none(*pud)) {
94833 pmd_t *pmd = pmd_offset(pud, addr);
94834+#ifdef CONFIG_X86
94835+ if (!pmd_large(*pmd))
94836+#endif
94837 if (!pmd_none(*pmd)) {
94838 pte_t *ptep, pte;
94839
94840@@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
94841 struct vm_struct *area;
94842
94843 BUG_ON(in_interrupt());
94844+
94845+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
94846+ if (flags & VM_KERNEXEC) {
94847+ if (start != VMALLOC_START || end != VMALLOC_END)
94848+ return NULL;
94849+ start = (unsigned long)MODULES_EXEC_VADDR;
94850+ end = (unsigned long)MODULES_EXEC_END;
94851+ }
94852+#endif
94853+
94854 if (flags & VM_IOREMAP)
94855 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
94856
94857@@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
94858 if (count > totalram_pages)
94859 return NULL;
94860
94861+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
94862+ if (!(pgprot_val(prot) & _PAGE_NX))
94863+ flags |= VM_KERNEXEC;
94864+#endif
94865+
94866 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
94867 __builtin_return_address(0));
94868 if (!area)
94869@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
94870 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
94871 goto fail;
94872
94873+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
94874+ if (!(pgprot_val(prot) & _PAGE_NX))
94875+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
94876+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
94877+ else
94878+#endif
94879+
94880 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
94881 start, end, node, gfp_mask, caller);
94882 if (!area)
94883@@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
94884 * For tight control over page level allocator and protection flags
94885 * use __vmalloc() instead.
94886 */
94887-
94888 void *vmalloc_exec(unsigned long size)
94889 {
94890- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
94891+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
94892 NUMA_NO_NODE, __builtin_return_address(0));
94893 }
94894
94895@@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
94896 {
94897 struct vm_struct *area;
94898
94899+ BUG_ON(vma->vm_mirror);
94900+
94901 size = PAGE_ALIGN(size);
94902
94903 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
94904@@ -2602,7 +2661,11 @@ static int s_show(struct seq_file *m, void *p)
94905 v->addr, v->addr + v->size, v->size);
94906
94907 if (v->caller)
94908+#ifdef CONFIG_GRKERNSEC_HIDESYM
94909+ seq_printf(m, " %pK", v->caller);
94910+#else
94911 seq_printf(m, " %pS", v->caller);
94912+#endif
94913
94914 if (v->nr_pages)
94915 seq_printf(m, " pages=%d", v->nr_pages);
94916diff --git a/mm/vmstat.c b/mm/vmstat.c
94917index 7249614..2639fc7 100644
94918--- a/mm/vmstat.c
94919+++ b/mm/vmstat.c
94920@@ -20,6 +20,7 @@
94921 #include <linux/writeback.h>
94922 #include <linux/compaction.h>
94923 #include <linux/mm_inline.h>
94924+#include <linux/grsecurity.h>
94925
94926 #include "internal.h"
94927
94928@@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
94929 *
94930 * vm_stat contains the global counters
94931 */
94932-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
94933+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
94934 EXPORT_SYMBOL(vm_stat);
94935
94936 #ifdef CONFIG_SMP
94937@@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
94938
94939 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
94940 if (diff[i])
94941- atomic_long_add(diff[i], &vm_stat[i]);
94942+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
94943 }
94944
94945 /*
94946@@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
94947 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
94948 if (v) {
94949
94950- atomic_long_add(v, &zone->vm_stat[i]);
94951+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
94952 global_diff[i] += v;
94953 #ifdef CONFIG_NUMA
94954 /* 3 seconds idle till flush */
94955@@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
94956
94957 v = p->vm_stat_diff[i];
94958 p->vm_stat_diff[i] = 0;
94959- atomic_long_add(v, &zone->vm_stat[i]);
94960+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
94961 global_diff[i] += v;
94962 }
94963 }
94964@@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
94965 if (pset->vm_stat_diff[i]) {
94966 int v = pset->vm_stat_diff[i];
94967 pset->vm_stat_diff[i] = 0;
94968- atomic_long_add(v, &zone->vm_stat[i]);
94969- atomic_long_add(v, &vm_stat[i]);
94970+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
94971+ atomic_long_add_unchecked(v, &vm_stat[i]);
94972 }
94973 }
94974 #endif
94975@@ -1148,10 +1149,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
94976 stat_items_size += sizeof(struct vm_event_state);
94977 #endif
94978
94979- v = kmalloc(stat_items_size, GFP_KERNEL);
94980+ v = kzalloc(stat_items_size, GFP_KERNEL);
94981 m->private = v;
94982 if (!v)
94983 return ERR_PTR(-ENOMEM);
94984+
94985+#ifdef CONFIG_GRKERNSEC_PROC_ADD
94986+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
94987+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
94988+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
94989+ && !in_group_p(grsec_proc_gid)
94990+#endif
94991+ )
94992+ return (unsigned long *)m->private + *pos;
94993+#endif
94994+#endif
94995+
94996 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
94997 v[i] = global_page_state(i);
94998 v += NR_VM_ZONE_STAT_ITEMS;
94999@@ -1300,10 +1313,16 @@ static int __init setup_vmstat(void)
95000 put_online_cpus();
95001 #endif
95002 #ifdef CONFIG_PROC_FS
95003- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
95004- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
95005- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
95006- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
95007+ {
95008+ mode_t gr_mode = S_IRUGO;
95009+#ifdef CONFIG_GRKERNSEC_PROC_ADD
95010+ gr_mode = S_IRUSR;
95011+#endif
95012+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
95013+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
95014+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
95015+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
95016+ }
95017 #endif
95018 return 0;
95019 }
95020diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
95021index b3d17d1..e8e4cdd 100644
95022--- a/net/8021q/vlan.c
95023+++ b/net/8021q/vlan.c
95024@@ -472,7 +472,7 @@ out:
95025 return NOTIFY_DONE;
95026 }
95027
95028-static struct notifier_block vlan_notifier_block __read_mostly = {
95029+static struct notifier_block vlan_notifier_block = {
95030 .notifier_call = vlan_device_event,
95031 };
95032
95033@@ -547,8 +547,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
95034 err = -EPERM;
95035 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
95036 break;
95037- if ((args.u.name_type >= 0) &&
95038- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
95039+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
95040 struct vlan_net *vn;
95041
95042 vn = net_generic(net, vlan_net_id);
95043diff --git a/net/9p/client.c b/net/9p/client.c
95044index ee8fd6b..0469d50 100644
95045--- a/net/9p/client.c
95046+++ b/net/9p/client.c
95047@@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
95048 len - inline_len);
95049 } else {
95050 err = copy_from_user(ename + inline_len,
95051- uidata, len - inline_len);
95052+ (char __force_user *)uidata, len - inline_len);
95053 if (err) {
95054 err = -EFAULT;
95055 goto out_err;
95056@@ -1563,7 +1563,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
95057 kernel_buf = 1;
95058 indata = data;
95059 } else
95060- indata = (__force char *)udata;
95061+ indata = (__force_kernel char *)udata;
95062 /*
95063 * response header len is 11
95064 * PDU Header(7) + IO Size (4)
95065@@ -1638,7 +1638,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
95066 kernel_buf = 1;
95067 odata = data;
95068 } else
95069- odata = (char *)udata;
95070+ odata = (char __force_kernel *)udata;
95071 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
95072 P9_ZC_HDR_SZ, kernel_buf, "dqd",
95073 fid->fid, offset, rsize);
95074diff --git a/net/9p/mod.c b/net/9p/mod.c
95075index 6ab36ae..6f1841b 100644
95076--- a/net/9p/mod.c
95077+++ b/net/9p/mod.c
95078@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
95079 void v9fs_register_trans(struct p9_trans_module *m)
95080 {
95081 spin_lock(&v9fs_trans_lock);
95082- list_add_tail(&m->list, &v9fs_trans_list);
95083+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
95084 spin_unlock(&v9fs_trans_lock);
95085 }
95086 EXPORT_SYMBOL(v9fs_register_trans);
95087@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
95088 void v9fs_unregister_trans(struct p9_trans_module *m)
95089 {
95090 spin_lock(&v9fs_trans_lock);
95091- list_del_init(&m->list);
95092+ pax_list_del_init((struct list_head *)&m->list);
95093 spin_unlock(&v9fs_trans_lock);
95094 }
95095 EXPORT_SYMBOL(v9fs_unregister_trans);
95096diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
95097index 9321a77..ed2f256 100644
95098--- a/net/9p/trans_fd.c
95099+++ b/net/9p/trans_fd.c
95100@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
95101 oldfs = get_fs();
95102 set_fs(get_ds());
95103 /* The cast to a user pointer is valid due to the set_fs() */
95104- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
95105+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
95106 set_fs(oldfs);
95107
95108 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
95109diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
95110index 876fbe8..8bbea9f 100644
95111--- a/net/atm/atm_misc.c
95112+++ b/net/atm/atm_misc.c
95113@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
95114 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
95115 return 1;
95116 atm_return(vcc, truesize);
95117- atomic_inc(&vcc->stats->rx_drop);
95118+ atomic_inc_unchecked(&vcc->stats->rx_drop);
95119 return 0;
95120 }
95121 EXPORT_SYMBOL(atm_charge);
95122@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
95123 }
95124 }
95125 atm_return(vcc, guess);
95126- atomic_inc(&vcc->stats->rx_drop);
95127+ atomic_inc_unchecked(&vcc->stats->rx_drop);
95128 return NULL;
95129 }
95130 EXPORT_SYMBOL(atm_alloc_charge);
95131@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
95132
95133 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
95134 {
95135-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
95136+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
95137 __SONET_ITEMS
95138 #undef __HANDLE_ITEM
95139 }
95140@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
95141
95142 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
95143 {
95144-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
95145+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
95146 __SONET_ITEMS
95147 #undef __HANDLE_ITEM
95148 }
95149diff --git a/net/atm/lec.c b/net/atm/lec.c
95150index f23916b..dd4d26b 100644
95151--- a/net/atm/lec.c
95152+++ b/net/atm/lec.c
95153@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
95154 }
95155
95156 static struct lane2_ops lane2_ops = {
95157- lane2_resolve, /* resolve, spec 3.1.3 */
95158- lane2_associate_req, /* associate_req, spec 3.1.4 */
95159- NULL /* associate indicator, spec 3.1.5 */
95160+ .resolve = lane2_resolve,
95161+ .associate_req = lane2_associate_req,
95162+ .associate_indicator = NULL
95163 };
95164
95165 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
95166diff --git a/net/atm/lec.h b/net/atm/lec.h
95167index 4149db1..f2ab682 100644
95168--- a/net/atm/lec.h
95169+++ b/net/atm/lec.h
95170@@ -48,7 +48,7 @@ struct lane2_ops {
95171 const u8 *tlvs, u32 sizeoftlvs);
95172 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
95173 const u8 *tlvs, u32 sizeoftlvs);
95174-};
95175+} __no_const;
95176
95177 /*
95178 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
95179diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
95180index d1b2d9a..d549f7f 100644
95181--- a/net/atm/mpoa_caches.c
95182+++ b/net/atm/mpoa_caches.c
95183@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
95184
95185
95186 static struct in_cache_ops ingress_ops = {
95187- in_cache_add_entry, /* add_entry */
95188- in_cache_get, /* get */
95189- in_cache_get_with_mask, /* get_with_mask */
95190- in_cache_get_by_vcc, /* get_by_vcc */
95191- in_cache_put, /* put */
95192- in_cache_remove_entry, /* remove_entry */
95193- cache_hit, /* cache_hit */
95194- clear_count_and_expired, /* clear_count */
95195- check_resolving_entries, /* check_resolving */
95196- refresh_entries, /* refresh */
95197- in_destroy_cache /* destroy_cache */
95198+ .add_entry = in_cache_add_entry,
95199+ .get = in_cache_get,
95200+ .get_with_mask = in_cache_get_with_mask,
95201+ .get_by_vcc = in_cache_get_by_vcc,
95202+ .put = in_cache_put,
95203+ .remove_entry = in_cache_remove_entry,
95204+ .cache_hit = cache_hit,
95205+ .clear_count = clear_count_and_expired,
95206+ .check_resolving = check_resolving_entries,
95207+ .refresh = refresh_entries,
95208+ .destroy_cache = in_destroy_cache
95209 };
95210
95211 static struct eg_cache_ops egress_ops = {
95212- eg_cache_add_entry, /* add_entry */
95213- eg_cache_get_by_cache_id, /* get_by_cache_id */
95214- eg_cache_get_by_tag, /* get_by_tag */
95215- eg_cache_get_by_vcc, /* get_by_vcc */
95216- eg_cache_get_by_src_ip, /* get_by_src_ip */
95217- eg_cache_put, /* put */
95218- eg_cache_remove_entry, /* remove_entry */
95219- update_eg_cache_entry, /* update */
95220- clear_expired, /* clear_expired */
95221- eg_destroy_cache /* destroy_cache */
95222+ .add_entry = eg_cache_add_entry,
95223+ .get_by_cache_id = eg_cache_get_by_cache_id,
95224+ .get_by_tag = eg_cache_get_by_tag,
95225+ .get_by_vcc = eg_cache_get_by_vcc,
95226+ .get_by_src_ip = eg_cache_get_by_src_ip,
95227+ .put = eg_cache_put,
95228+ .remove_entry = eg_cache_remove_entry,
95229+ .update = update_eg_cache_entry,
95230+ .clear_expired = clear_expired,
95231+ .destroy_cache = eg_destroy_cache
95232 };
95233
95234
95235diff --git a/net/atm/proc.c b/net/atm/proc.c
95236index bbb6461..cf04016 100644
95237--- a/net/atm/proc.c
95238+++ b/net/atm/proc.c
95239@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
95240 const struct k_atm_aal_stats *stats)
95241 {
95242 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
95243- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
95244- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
95245- atomic_read(&stats->rx_drop));
95246+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
95247+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
95248+ atomic_read_unchecked(&stats->rx_drop));
95249 }
95250
95251 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
95252diff --git a/net/atm/resources.c b/net/atm/resources.c
95253index 0447d5d..3cf4728 100644
95254--- a/net/atm/resources.c
95255+++ b/net/atm/resources.c
95256@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
95257 static void copy_aal_stats(struct k_atm_aal_stats *from,
95258 struct atm_aal_stats *to)
95259 {
95260-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
95261+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
95262 __AAL_STAT_ITEMS
95263 #undef __HANDLE_ITEM
95264 }
95265@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
95266 static void subtract_aal_stats(struct k_atm_aal_stats *from,
95267 struct atm_aal_stats *to)
95268 {
95269-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
95270+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
95271 __AAL_STAT_ITEMS
95272 #undef __HANDLE_ITEM
95273 }
95274diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
95275index 919a5ce..cc6b444 100644
95276--- a/net/ax25/sysctl_net_ax25.c
95277+++ b/net/ax25/sysctl_net_ax25.c
95278@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
95279 {
95280 char path[sizeof("net/ax25/") + IFNAMSIZ];
95281 int k;
95282- struct ctl_table *table;
95283+ ctl_table_no_const *table;
95284
95285 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
95286 if (!table)
95287diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
95288index b9c8a6e..ed0f711 100644
95289--- a/net/batman-adv/bat_iv_ogm.c
95290+++ b/net/batman-adv/bat_iv_ogm.c
95291@@ -297,7 +297,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
95292
95293 /* randomize initial seqno to avoid collision */
95294 get_random_bytes(&random_seqno, sizeof(random_seqno));
95295- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
95296+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
95297
95298 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
95299 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
95300@@ -884,9 +884,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
95301 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
95302
95303 /* change sequence number to network order */
95304- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
95305+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
95306 batadv_ogm_packet->seqno = htonl(seqno);
95307- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
95308+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
95309
95310 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
95311 batadv_iv_ogm_queue_add(bat_priv, hard_iface->bat_iv.ogm_buff,
95312@@ -1251,7 +1251,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
95313 return;
95314
95315 /* could be changed by schedule_own_packet() */
95316- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
95317+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
95318
95319 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
95320 has_directlink_flag = 1;
95321diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
95322index 6ddb614..ca7e886 100644
95323--- a/net/batman-adv/fragmentation.c
95324+++ b/net/batman-adv/fragmentation.c
95325@@ -447,7 +447,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
95326 frag_header.packet_type = BATADV_UNICAST_FRAG;
95327 frag_header.version = BATADV_COMPAT_VERSION;
95328 frag_header.ttl = BATADV_TTL;
95329- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
95330+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
95331 frag_header.reserved = 0;
95332 frag_header.no = 0;
95333 frag_header.total_size = htons(skb->len);
95334diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
95335index a8f99d1..11797ef 100644
95336--- a/net/batman-adv/soft-interface.c
95337+++ b/net/batman-adv/soft-interface.c
95338@@ -278,7 +278,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
95339 primary_if->net_dev->dev_addr, ETH_ALEN);
95340
95341 /* set broadcast sequence number */
95342- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
95343+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
95344 bcast_packet->seqno = htonl(seqno);
95345
95346 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
95347@@ -688,7 +688,7 @@ static int batadv_softif_init_late(struct net_device *dev)
95348 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
95349
95350 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
95351- atomic_set(&bat_priv->bcast_seqno, 1);
95352+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
95353 atomic_set(&bat_priv->tt.vn, 0);
95354 atomic_set(&bat_priv->tt.local_changes, 0);
95355 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
95356@@ -700,7 +700,7 @@ static int batadv_softif_init_late(struct net_device *dev)
95357
95358 /* randomize initial seqno to avoid collision */
95359 get_random_bytes(&random_seqno, sizeof(random_seqno));
95360- atomic_set(&bat_priv->frag_seqno, random_seqno);
95361+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
95362
95363 bat_priv->primary_if = NULL;
95364 bat_priv->num_ifaces = 0;
95365diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
95366index 91dd369..9c25750 100644
95367--- a/net/batman-adv/types.h
95368+++ b/net/batman-adv/types.h
95369@@ -56,7 +56,7 @@
95370 struct batadv_hard_iface_bat_iv {
95371 unsigned char *ogm_buff;
95372 int ogm_buff_len;
95373- atomic_t ogm_seqno;
95374+ atomic_unchecked_t ogm_seqno;
95375 };
95376
95377 /**
95378@@ -673,7 +673,7 @@ struct batadv_priv {
95379 atomic_t bonding;
95380 atomic_t fragmentation;
95381 atomic_t packet_size_max;
95382- atomic_t frag_seqno;
95383+ atomic_unchecked_t frag_seqno;
95384 #ifdef CONFIG_BATMAN_ADV_BLA
95385 atomic_t bridge_loop_avoidance;
95386 #endif
95387@@ -687,7 +687,7 @@ struct batadv_priv {
95388 #ifdef CONFIG_BATMAN_ADV_DEBUG
95389 atomic_t log_level;
95390 #endif
95391- atomic_t bcast_seqno;
95392+ atomic_unchecked_t bcast_seqno;
95393 atomic_t bcast_queue_left;
95394 atomic_t batman_queue_left;
95395 char num_ifaces;
95396diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
95397index 7552f9e..074ce29 100644
95398--- a/net/bluetooth/hci_sock.c
95399+++ b/net/bluetooth/hci_sock.c
95400@@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
95401 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
95402 }
95403
95404- len = min_t(unsigned int, len, sizeof(uf));
95405+ len = min((size_t)len, sizeof(uf));
95406 if (copy_from_user(&uf, optval, len)) {
95407 err = -EFAULT;
95408 break;
95409diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
95410index 4af3821..f2ba46c 100644
95411--- a/net/bluetooth/l2cap_core.c
95412+++ b/net/bluetooth/l2cap_core.c
95413@@ -3500,8 +3500,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
95414 break;
95415
95416 case L2CAP_CONF_RFC:
95417- if (olen == sizeof(rfc))
95418- memcpy(&rfc, (void *)val, olen);
95419+ if (olen != sizeof(rfc))
95420+ break;
95421+
95422+ memcpy(&rfc, (void *)val, olen);
95423
95424 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
95425 rfc.mode != chan->mode)
95426diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
95427index 7cc24d2..e83f531 100644
95428--- a/net/bluetooth/l2cap_sock.c
95429+++ b/net/bluetooth/l2cap_sock.c
95430@@ -545,7 +545,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
95431 struct sock *sk = sock->sk;
95432 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
95433 struct l2cap_options opts;
95434- int len, err = 0;
95435+ int err = 0;
95436+ size_t len = optlen;
95437 u32 opt;
95438
95439 BT_DBG("sk %p", sk);
95440@@ -567,7 +568,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
95441 opts.max_tx = chan->max_tx;
95442 opts.txwin_size = chan->tx_win;
95443
95444- len = min_t(unsigned int, sizeof(opts), optlen);
95445+ len = min(sizeof(opts), len);
95446 if (copy_from_user((char *) &opts, optval, len)) {
95447 err = -EFAULT;
95448 break;
95449@@ -647,7 +648,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
95450 struct bt_security sec;
95451 struct bt_power pwr;
95452 struct l2cap_conn *conn;
95453- int len, err = 0;
95454+ int err = 0;
95455+ size_t len = optlen;
95456 u32 opt;
95457
95458 BT_DBG("sk %p", sk);
95459@@ -670,7 +672,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
95460
95461 sec.level = BT_SECURITY_LOW;
95462
95463- len = min_t(unsigned int, sizeof(sec), optlen);
95464+ len = min(sizeof(sec), len);
95465 if (copy_from_user((char *) &sec, optval, len)) {
95466 err = -EFAULT;
95467 break;
95468@@ -770,7 +772,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
95469
95470 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
95471
95472- len = min_t(unsigned int, sizeof(pwr), optlen);
95473+ len = min(sizeof(pwr), len);
95474 if (copy_from_user((char *) &pwr, optval, len)) {
95475 err = -EFAULT;
95476 break;
95477diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
95478index 3c2d3e4..884855a 100644
95479--- a/net/bluetooth/rfcomm/sock.c
95480+++ b/net/bluetooth/rfcomm/sock.c
95481@@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
95482 struct sock *sk = sock->sk;
95483 struct bt_security sec;
95484 int err = 0;
95485- size_t len;
95486+ size_t len = optlen;
95487 u32 opt;
95488
95489 BT_DBG("sk %p", sk);
95490@@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
95491
95492 sec.level = BT_SECURITY_LOW;
95493
95494- len = min_t(unsigned int, sizeof(sec), optlen);
95495+ len = min(sizeof(sec), len);
95496 if (copy_from_user((char *) &sec, optval, len)) {
95497 err = -EFAULT;
95498 break;
95499diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
95500index 84fcf9f..e389b27 100644
95501--- a/net/bluetooth/rfcomm/tty.c
95502+++ b/net/bluetooth/rfcomm/tty.c
95503@@ -684,7 +684,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
95504 BT_DBG("tty %p id %d", tty, tty->index);
95505
95506 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
95507- dev->channel, dev->port.count);
95508+ dev->channel, atomic_read(&dev->port.count));
95509
95510 err = tty_port_open(&dev->port, tty, filp);
95511 if (err)
95512@@ -707,7 +707,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
95513 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
95514
95515 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
95516- dev->port.count);
95517+ atomic_read(&dev->port.count));
95518
95519 tty_port_close(&dev->port, tty, filp);
95520 }
95521diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
95522index ac78024..161a80c 100644
95523--- a/net/bridge/netfilter/ebtables.c
95524+++ b/net/bridge/netfilter/ebtables.c
95525@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
95526 tmp.valid_hooks = t->table->valid_hooks;
95527 }
95528 mutex_unlock(&ebt_mutex);
95529- if (copy_to_user(user, &tmp, *len) != 0){
95530+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
95531 BUGPRINT("c2u Didn't work\n");
95532 ret = -EFAULT;
95533 break;
95534@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
95535 goto out;
95536 tmp.valid_hooks = t->valid_hooks;
95537
95538- if (copy_to_user(user, &tmp, *len) != 0) {
95539+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
95540 ret = -EFAULT;
95541 break;
95542 }
95543@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
95544 tmp.entries_size = t->table->entries_size;
95545 tmp.valid_hooks = t->table->valid_hooks;
95546
95547- if (copy_to_user(user, &tmp, *len) != 0) {
95548+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
95549 ret = -EFAULT;
95550 break;
95551 }
95552diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
95553index 0f45522..dab651f 100644
95554--- a/net/caif/cfctrl.c
95555+++ b/net/caif/cfctrl.c
95556@@ -10,6 +10,7 @@
95557 #include <linux/spinlock.h>
95558 #include <linux/slab.h>
95559 #include <linux/pkt_sched.h>
95560+#include <linux/sched.h>
95561 #include <net/caif/caif_layer.h>
95562 #include <net/caif/cfpkt.h>
95563 #include <net/caif/cfctrl.h>
95564@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
95565 memset(&dev_info, 0, sizeof(dev_info));
95566 dev_info.id = 0xff;
95567 cfsrvl_init(&this->serv, 0, &dev_info, false);
95568- atomic_set(&this->req_seq_no, 1);
95569- atomic_set(&this->rsp_seq_no, 1);
95570+ atomic_set_unchecked(&this->req_seq_no, 1);
95571+ atomic_set_unchecked(&this->rsp_seq_no, 1);
95572 this->serv.layer.receive = cfctrl_recv;
95573 sprintf(this->serv.layer.name, "ctrl");
95574 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
95575@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
95576 struct cfctrl_request_info *req)
95577 {
95578 spin_lock_bh(&ctrl->info_list_lock);
95579- atomic_inc(&ctrl->req_seq_no);
95580- req->sequence_no = atomic_read(&ctrl->req_seq_no);
95581+ atomic_inc_unchecked(&ctrl->req_seq_no);
95582+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
95583 list_add_tail(&req->list, &ctrl->list);
95584 spin_unlock_bh(&ctrl->info_list_lock);
95585 }
95586@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
95587 if (p != first)
95588 pr_warn("Requests are not received in order\n");
95589
95590- atomic_set(&ctrl->rsp_seq_no,
95591+ atomic_set_unchecked(&ctrl->rsp_seq_no,
95592 p->sequence_no);
95593 list_del(&p->list);
95594 goto out;
95595diff --git a/net/can/af_can.c b/net/can/af_can.c
95596index d249874..99e197b 100644
95597--- a/net/can/af_can.c
95598+++ b/net/can/af_can.c
95599@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
95600 };
95601
95602 /* notifier block for netdevice event */
95603-static struct notifier_block can_netdev_notifier __read_mostly = {
95604+static struct notifier_block can_netdev_notifier = {
95605 .notifier_call = can_notifier,
95606 };
95607
95608diff --git a/net/can/gw.c b/net/can/gw.c
95609index 3f9b0f3..fc6d4fa 100644
95610--- a/net/can/gw.c
95611+++ b/net/can/gw.c
95612@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
95613 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
95614
95615 static HLIST_HEAD(cgw_list);
95616-static struct notifier_block notifier;
95617
95618 static struct kmem_cache *cgw_cache __read_mostly;
95619
95620@@ -954,6 +953,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
95621 return err;
95622 }
95623
95624+static struct notifier_block notifier = {
95625+ .notifier_call = cgw_notifier
95626+};
95627+
95628 static __init int cgw_module_init(void)
95629 {
95630 /* sanitize given module parameter */
95631@@ -969,7 +972,6 @@ static __init int cgw_module_init(void)
95632 return -ENOMEM;
95633
95634 /* set notifier */
95635- notifier.notifier_call = cgw_notifier;
95636 register_netdevice_notifier(&notifier);
95637
95638 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
95639diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
95640index 4a5df7b..9ad1f1d 100644
95641--- a/net/ceph/messenger.c
95642+++ b/net/ceph/messenger.c
95643@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
95644 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
95645
95646 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
95647-static atomic_t addr_str_seq = ATOMIC_INIT(0);
95648+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
95649
95650 static struct page *zero_page; /* used in certain error cases */
95651
95652@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
95653 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
95654 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
95655
95656- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
95657+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
95658 s = addr_str[i];
95659
95660 switch (ss->ss_family) {
95661diff --git a/net/compat.c b/net/compat.c
95662index f50161f..94fa415 100644
95663--- a/net/compat.c
95664+++ b/net/compat.c
95665@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
95666 return -EFAULT;
95667 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
95668 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
95669- kmsg->msg_name = compat_ptr(tmp1);
95670- kmsg->msg_iov = compat_ptr(tmp2);
95671- kmsg->msg_control = compat_ptr(tmp3);
95672+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
95673+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
95674+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
95675 return 0;
95676 }
95677
95678@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
95679
95680 if (kern_msg->msg_namelen) {
95681 if (mode == VERIFY_READ) {
95682- int err = move_addr_to_kernel(kern_msg->msg_name,
95683+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
95684 kern_msg->msg_namelen,
95685 kern_address);
95686 if (err < 0)
95687@@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
95688 kern_msg->msg_name = NULL;
95689
95690 tot_len = iov_from_user_compat_to_kern(kern_iov,
95691- (struct compat_iovec __user *)kern_msg->msg_iov,
95692+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
95693 kern_msg->msg_iovlen);
95694 if (tot_len >= 0)
95695 kern_msg->msg_iov = kern_iov;
95696@@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
95697
95698 #define CMSG_COMPAT_FIRSTHDR(msg) \
95699 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
95700- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
95701+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
95702 (struct compat_cmsghdr __user *)NULL)
95703
95704 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
95705 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
95706 (ucmlen) <= (unsigned long) \
95707 ((mhdr)->msg_controllen - \
95708- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
95709+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
95710
95711 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
95712 struct compat_cmsghdr __user *cmsg, int cmsg_len)
95713 {
95714 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
95715- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
95716+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
95717 msg->msg_controllen)
95718 return NULL;
95719 return (struct compat_cmsghdr __user *)ptr;
95720@@ -222,7 +222,7 @@ Efault:
95721
95722 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
95723 {
95724- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
95725+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
95726 struct compat_cmsghdr cmhdr;
95727 struct compat_timeval ctv;
95728 struct compat_timespec cts[3];
95729@@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
95730
95731 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
95732 {
95733- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
95734+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
95735 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
95736 int fdnum = scm->fp->count;
95737 struct file **fp = scm->fp->fp;
95738@@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
95739 return -EFAULT;
95740 old_fs = get_fs();
95741 set_fs(KERNEL_DS);
95742- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
95743+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
95744 set_fs(old_fs);
95745
95746 return err;
95747@@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
95748 len = sizeof(ktime);
95749 old_fs = get_fs();
95750 set_fs(KERNEL_DS);
95751- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
95752+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
95753 set_fs(old_fs);
95754
95755 if (!err) {
95756@@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
95757 case MCAST_JOIN_GROUP:
95758 case MCAST_LEAVE_GROUP:
95759 {
95760- struct compat_group_req __user *gr32 = (void *)optval;
95761+ struct compat_group_req __user *gr32 = (void __user *)optval;
95762 struct group_req __user *kgr =
95763 compat_alloc_user_space(sizeof(struct group_req));
95764 u32 interface;
95765@@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
95766 case MCAST_BLOCK_SOURCE:
95767 case MCAST_UNBLOCK_SOURCE:
95768 {
95769- struct compat_group_source_req __user *gsr32 = (void *)optval;
95770+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
95771 struct group_source_req __user *kgsr = compat_alloc_user_space(
95772 sizeof(struct group_source_req));
95773 u32 interface;
95774@@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
95775 }
95776 case MCAST_MSFILTER:
95777 {
95778- struct compat_group_filter __user *gf32 = (void *)optval;
95779+ struct compat_group_filter __user *gf32 = (void __user *)optval;
95780 struct group_filter __user *kgf;
95781 u32 interface, fmode, numsrc;
95782
95783@@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
95784 char __user *optval, int __user *optlen,
95785 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
95786 {
95787- struct compat_group_filter __user *gf32 = (void *)optval;
95788+ struct compat_group_filter __user *gf32 = (void __user *)optval;
95789 struct group_filter __user *kgf;
95790 int __user *koptlen;
95791 u32 interface, fmode, numsrc;
95792@@ -803,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
95793
95794 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
95795 return -EINVAL;
95796- if (copy_from_user(a, args, nas[call]))
95797+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
95798 return -EFAULT;
95799 a0 = a[0];
95800 a1 = a[1];
95801diff --git a/net/core/datagram.c b/net/core/datagram.c
95802index a16ed7b..eb44d17 100644
95803--- a/net/core/datagram.c
95804+++ b/net/core/datagram.c
95805@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
95806 }
95807
95808 kfree_skb(skb);
95809- atomic_inc(&sk->sk_drops);
95810+ atomic_inc_unchecked(&sk->sk_drops);
95811 sk_mem_reclaim_partial(sk);
95812
95813 return err;
95814diff --git a/net/core/dev.c b/net/core/dev.c
95815index 0ce469e..dfb53d2 100644
95816--- a/net/core/dev.c
95817+++ b/net/core/dev.c
95818@@ -1684,14 +1684,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
95819 {
95820 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
95821 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
95822- atomic_long_inc(&dev->rx_dropped);
95823+ atomic_long_inc_unchecked(&dev->rx_dropped);
95824 kfree_skb(skb);
95825 return NET_RX_DROP;
95826 }
95827 }
95828
95829 if (unlikely(!is_skb_forwardable(dev, skb))) {
95830- atomic_long_inc(&dev->rx_dropped);
95831+ atomic_long_inc_unchecked(&dev->rx_dropped);
95832 kfree_skb(skb);
95833 return NET_RX_DROP;
95834 }
95835@@ -2434,7 +2434,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
95836
95837 struct dev_gso_cb {
95838 void (*destructor)(struct sk_buff *skb);
95839-};
95840+} __no_const;
95841
95842 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
95843
95844@@ -3222,7 +3222,7 @@ enqueue:
95845
95846 local_irq_restore(flags);
95847
95848- atomic_long_inc(&skb->dev->rx_dropped);
95849+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
95850 kfree_skb(skb);
95851 return NET_RX_DROP;
95852 }
95853@@ -3294,7 +3294,7 @@ int netif_rx_ni(struct sk_buff *skb)
95854 }
95855 EXPORT_SYMBOL(netif_rx_ni);
95856
95857-static void net_tx_action(struct softirq_action *h)
95858+static __latent_entropy void net_tx_action(void)
95859 {
95860 struct softnet_data *sd = &__get_cpu_var(softnet_data);
95861
95862@@ -3628,7 +3628,7 @@ ncls:
95863 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
95864 } else {
95865 drop:
95866- atomic_long_inc(&skb->dev->rx_dropped);
95867+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
95868 kfree_skb(skb);
95869 /* Jamal, now you will not able to escape explaining
95870 * me how you were going to use this. :-)
95871@@ -4288,7 +4288,7 @@ void netif_napi_del(struct napi_struct *napi)
95872 }
95873 EXPORT_SYMBOL(netif_napi_del);
95874
95875-static void net_rx_action(struct softirq_action *h)
95876+static __latent_entropy void net_rx_action(void)
95877 {
95878 struct softnet_data *sd = &__get_cpu_var(softnet_data);
95879 unsigned long time_limit = jiffies + 2;
95880@@ -6177,7 +6177,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
95881 } else {
95882 netdev_stats_to_stats64(storage, &dev->stats);
95883 }
95884- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
95885+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
95886 return storage;
95887 }
95888 EXPORT_SYMBOL(dev_get_stats);
95889diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
95890index 5b7d0e1..cb960fc 100644
95891--- a/net/core/dev_ioctl.c
95892+++ b/net/core/dev_ioctl.c
95893@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
95894 if (no_module && capable(CAP_NET_ADMIN))
95895 no_module = request_module("netdev-%s", name);
95896 if (no_module && capable(CAP_SYS_MODULE)) {
95897+#ifdef CONFIG_GRKERNSEC_MODHARDEN
95898+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
95899+#else
95900 if (!request_module("%s", name))
95901 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
95902 name);
95903+#endif
95904 }
95905 }
95906 EXPORT_SYMBOL(dev_load);
95907diff --git a/net/core/filter.c b/net/core/filter.c
95908index ad30d62..c2757df 100644
95909--- a/net/core/filter.c
95910+++ b/net/core/filter.c
95911@@ -679,7 +679,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
95912 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
95913 if (!fp)
95914 return -ENOMEM;
95915- memcpy(fp->insns, fprog->filter, fsize);
95916+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
95917
95918 atomic_set(&fp->refcnt, 1);
95919 fp->len = fprog->len;
95920diff --git a/net/core/flow.c b/net/core/flow.c
95921index dfa602c..3103d88 100644
95922--- a/net/core/flow.c
95923+++ b/net/core/flow.c
95924@@ -61,7 +61,7 @@ struct flow_cache {
95925 struct timer_list rnd_timer;
95926 };
95927
95928-atomic_t flow_cache_genid = ATOMIC_INIT(0);
95929+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
95930 EXPORT_SYMBOL(flow_cache_genid);
95931 static struct flow_cache flow_cache_global;
95932 static struct kmem_cache *flow_cachep __read_mostly;
95933@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
95934
95935 static int flow_entry_valid(struct flow_cache_entry *fle)
95936 {
95937- if (atomic_read(&flow_cache_genid) != fle->genid)
95938+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
95939 return 0;
95940 if (fle->object && !fle->object->ops->check(fle->object))
95941 return 0;
95942@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
95943 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
95944 fcp->hash_count++;
95945 }
95946- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
95947+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
95948 flo = fle->object;
95949 if (!flo)
95950 goto ret_object;
95951@@ -279,7 +279,7 @@ nocache:
95952 }
95953 flo = resolver(net, key, family, dir, flo, ctx);
95954 if (fle) {
95955- fle->genid = atomic_read(&flow_cache_genid);
95956+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
95957 if (!IS_ERR(flo))
95958 fle->object = flo;
95959 else
95960diff --git a/net/core/iovec.c b/net/core/iovec.c
95961index b618694..192bbba 100644
95962--- a/net/core/iovec.c
95963+++ b/net/core/iovec.c
95964@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
95965 if (m->msg_namelen) {
95966 if (mode == VERIFY_READ) {
95967 void __user *namep;
95968- namep = (void __user __force *) m->msg_name;
95969+ namep = (void __force_user *) m->msg_name;
95970 err = move_addr_to_kernel(namep, m->msg_namelen,
95971 address);
95972 if (err < 0)
95973@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
95974 }
95975
95976 size = m->msg_iovlen * sizeof(struct iovec);
95977- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
95978+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
95979 return -EFAULT;
95980
95981 m->msg_iov = iov;
95982diff --git a/net/core/neighbour.c b/net/core/neighbour.c
95983index 932c6d7..7c7aa10 100644
95984--- a/net/core/neighbour.c
95985+++ b/net/core/neighbour.c
95986@@ -2775,7 +2775,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
95987 void __user *buffer, size_t *lenp, loff_t *ppos)
95988 {
95989 int size, ret;
95990- struct ctl_table tmp = *ctl;
95991+ ctl_table_no_const tmp = *ctl;
95992
95993 tmp.extra1 = &zero;
95994 tmp.extra2 = &unres_qlen_max;
95995diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
95996index 2bf8329..7960607 100644
95997--- a/net/core/net-procfs.c
95998+++ b/net/core/net-procfs.c
95999@@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
96000 else
96001 seq_printf(seq, "%04x", ntohs(pt->type));
96002
96003+#ifdef CONFIG_GRKERNSEC_HIDESYM
96004+ seq_printf(seq, " %-8s %pf\n",
96005+ pt->dev ? pt->dev->name : "", NULL);
96006+#else
96007 seq_printf(seq, " %-8s %pf\n",
96008 pt->dev ? pt->dev->name : "", pt->func);
96009+#endif
96010 }
96011
96012 return 0;
96013diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
96014index f3edf96..3cd8b40 100644
96015--- a/net/core/net-sysfs.c
96016+++ b/net/core/net-sysfs.c
96017@@ -1358,7 +1358,7 @@ void netdev_class_remove_file_ns(struct class_attribute *class_attr,
96018 }
96019 EXPORT_SYMBOL(netdev_class_remove_file_ns);
96020
96021-int netdev_kobject_init(void)
96022+int __init netdev_kobject_init(void)
96023 {
96024 kobj_ns_type_register(&net_ns_type_operations);
96025 return class_register(&net_class);
96026diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
96027index 81d3a9a..a0bd7a8 100644
96028--- a/net/core/net_namespace.c
96029+++ b/net/core/net_namespace.c
96030@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
96031 int error;
96032 LIST_HEAD(net_exit_list);
96033
96034- list_add_tail(&ops->list, list);
96035+ pax_list_add_tail((struct list_head *)&ops->list, list);
96036 if (ops->init || (ops->id && ops->size)) {
96037 for_each_net(net) {
96038 error = ops_init(ops, net);
96039@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
96040
96041 out_undo:
96042 /* If I have an error cleanup all namespaces I initialized */
96043- list_del(&ops->list);
96044+ pax_list_del((struct list_head *)&ops->list);
96045 ops_exit_list(ops, &net_exit_list);
96046 ops_free_list(ops, &net_exit_list);
96047 return error;
96048@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
96049 struct net *net;
96050 LIST_HEAD(net_exit_list);
96051
96052- list_del(&ops->list);
96053+ pax_list_del((struct list_head *)&ops->list);
96054 for_each_net(net)
96055 list_add_tail(&net->exit_list, &net_exit_list);
96056 ops_exit_list(ops, &net_exit_list);
96057@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
96058 mutex_lock(&net_mutex);
96059 error = register_pernet_operations(&pernet_list, ops);
96060 if (!error && (first_device == &pernet_list))
96061- first_device = &ops->list;
96062+ first_device = (struct list_head *)&ops->list;
96063 mutex_unlock(&net_mutex);
96064 return error;
96065 }
96066diff --git a/net/core/netpoll.c b/net/core/netpoll.c
96067index 19fe9c7..b6bb620 100644
96068--- a/net/core/netpoll.c
96069+++ b/net/core/netpoll.c
96070@@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
96071 struct udphdr *udph;
96072 struct iphdr *iph;
96073 struct ethhdr *eth;
96074- static atomic_t ip_ident;
96075+ static atomic_unchecked_t ip_ident;
96076 struct ipv6hdr *ip6h;
96077
96078 udp_len = len + sizeof(*udph);
96079@@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
96080 put_unaligned(0x45, (unsigned char *)iph);
96081 iph->tos = 0;
96082 put_unaligned(htons(ip_len), &(iph->tot_len));
96083- iph->id = htons(atomic_inc_return(&ip_ident));
96084+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
96085 iph->frag_off = 0;
96086 iph->ttl = 64;
96087 iph->protocol = IPPROTO_UDP;
96088diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
96089index cf67144..12bf94c 100644
96090--- a/net/core/rtnetlink.c
96091+++ b/net/core/rtnetlink.c
96092@@ -58,7 +58,7 @@ struct rtnl_link {
96093 rtnl_doit_func doit;
96094 rtnl_dumpit_func dumpit;
96095 rtnl_calcit_func calcit;
96096-};
96097+} __no_const;
96098
96099 static DEFINE_MUTEX(rtnl_mutex);
96100
96101@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
96102 if (rtnl_link_ops_get(ops->kind))
96103 return -EEXIST;
96104
96105- if (!ops->dellink)
96106- ops->dellink = unregister_netdevice_queue;
96107+ if (!ops->dellink) {
96108+ pax_open_kernel();
96109+ *(void **)&ops->dellink = unregister_netdevice_queue;
96110+ pax_close_kernel();
96111+ }
96112
96113- list_add_tail(&ops->list, &link_ops);
96114+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
96115 return 0;
96116 }
96117 EXPORT_SYMBOL_GPL(__rtnl_link_register);
96118@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
96119 for_each_net(net) {
96120 __rtnl_kill_links(net, ops);
96121 }
96122- list_del(&ops->list);
96123+ pax_list_del((struct list_head *)&ops->list);
96124 }
96125 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
96126
96127diff --git a/net/core/scm.c b/net/core/scm.c
96128index b442e7e..6f5b5a2 100644
96129--- a/net/core/scm.c
96130+++ b/net/core/scm.c
96131@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
96132 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
96133 {
96134 struct cmsghdr __user *cm
96135- = (__force struct cmsghdr __user *)msg->msg_control;
96136+ = (struct cmsghdr __force_user *)msg->msg_control;
96137 struct cmsghdr cmhdr;
96138 int cmlen = CMSG_LEN(len);
96139 int err;
96140@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
96141 err = -EFAULT;
96142 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
96143 goto out;
96144- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
96145+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
96146 goto out;
96147 cmlen = CMSG_SPACE(len);
96148 if (msg->msg_controllen < cmlen)
96149@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
96150 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
96151 {
96152 struct cmsghdr __user *cm
96153- = (__force struct cmsghdr __user*)msg->msg_control;
96154+ = (struct cmsghdr __force_user *)msg->msg_control;
96155
96156 int fdmax = 0;
96157 int fdnum = scm->fp->count;
96158@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
96159 if (fdnum < fdmax)
96160 fdmax = fdnum;
96161
96162- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
96163+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
96164 i++, cmfptr++)
96165 {
96166 struct socket *sock;
96167diff --git a/net/core/skbuff.c b/net/core/skbuff.c
96168index 06e72d3..19dfa7b 100644
96169--- a/net/core/skbuff.c
96170+++ b/net/core/skbuff.c
96171@@ -2034,7 +2034,7 @@ EXPORT_SYMBOL(__skb_checksum);
96172 __wsum skb_checksum(const struct sk_buff *skb, int offset,
96173 int len, __wsum csum)
96174 {
96175- const struct skb_checksum_ops ops = {
96176+ static const struct skb_checksum_ops ops = {
96177 .update = csum_partial_ext,
96178 .combine = csum_block_add_ext,
96179 };
96180@@ -3147,13 +3147,15 @@ void __init skb_init(void)
96181 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
96182 sizeof(struct sk_buff),
96183 0,
96184- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
96185+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
96186+ SLAB_NO_SANITIZE,
96187 NULL);
96188 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
96189 (2*sizeof(struct sk_buff)) +
96190 sizeof(atomic_t),
96191 0,
96192- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
96193+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
96194+ SLAB_NO_SANITIZE,
96195 NULL);
96196 }
96197
96198diff --git a/net/core/sock.c b/net/core/sock.c
96199index 5393b4b..997c88b 100644
96200--- a/net/core/sock.c
96201+++ b/net/core/sock.c
96202@@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
96203 struct sk_buff_head *list = &sk->sk_receive_queue;
96204
96205 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
96206- atomic_inc(&sk->sk_drops);
96207+ atomic_inc_unchecked(&sk->sk_drops);
96208 trace_sock_rcvqueue_full(sk, skb);
96209 return -ENOMEM;
96210 }
96211@@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
96212 return err;
96213
96214 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
96215- atomic_inc(&sk->sk_drops);
96216+ atomic_inc_unchecked(&sk->sk_drops);
96217 return -ENOBUFS;
96218 }
96219
96220@@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
96221 skb_dst_force(skb);
96222
96223 spin_lock_irqsave(&list->lock, flags);
96224- skb->dropcount = atomic_read(&sk->sk_drops);
96225+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
96226 __skb_queue_tail(list, skb);
96227 spin_unlock_irqrestore(&list->lock, flags);
96228
96229@@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
96230 skb->dev = NULL;
96231
96232 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
96233- atomic_inc(&sk->sk_drops);
96234+ atomic_inc_unchecked(&sk->sk_drops);
96235 goto discard_and_relse;
96236 }
96237 if (nested)
96238@@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
96239 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
96240 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
96241 bh_unlock_sock(sk);
96242- atomic_inc(&sk->sk_drops);
96243+ atomic_inc_unchecked(&sk->sk_drops);
96244 goto discard_and_relse;
96245 }
96246
96247@@ -950,12 +950,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
96248 struct timeval tm;
96249 } v;
96250
96251- int lv = sizeof(int);
96252- int len;
96253+ unsigned int lv = sizeof(int);
96254+ unsigned int len;
96255
96256 if (get_user(len, optlen))
96257 return -EFAULT;
96258- if (len < 0)
96259+ if (len > INT_MAX)
96260 return -EINVAL;
96261
96262 memset(&v, 0, sizeof(v));
96263@@ -1107,11 +1107,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
96264
96265 case SO_PEERNAME:
96266 {
96267- char address[128];
96268+ char address[_K_SS_MAXSIZE];
96269
96270 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
96271 return -ENOTCONN;
96272- if (lv < len)
96273+ if (lv < len || sizeof address < len)
96274 return -EINVAL;
96275 if (copy_to_user(optval, address, len))
96276 return -EFAULT;
96277@@ -1188,7 +1188,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
96278
96279 if (len > lv)
96280 len = lv;
96281- if (copy_to_user(optval, &v, len))
96282+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
96283 return -EFAULT;
96284 lenout:
96285 if (put_user(len, optlen))
96286@@ -2351,7 +2351,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
96287 */
96288 smp_wmb();
96289 atomic_set(&sk->sk_refcnt, 1);
96290- atomic_set(&sk->sk_drops, 0);
96291+ atomic_set_unchecked(&sk->sk_drops, 0);
96292 }
96293 EXPORT_SYMBOL(sock_init_data);
96294
96295@@ -2476,6 +2476,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
96296 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
96297 int level, int type)
96298 {
96299+ struct sock_extended_err ee;
96300 struct sock_exterr_skb *serr;
96301 struct sk_buff *skb, *skb2;
96302 int copied, err;
96303@@ -2497,7 +2498,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
96304 sock_recv_timestamp(msg, sk, skb);
96305
96306 serr = SKB_EXT_ERR(skb);
96307- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
96308+ ee = serr->ee;
96309+ put_cmsg(msg, level, type, sizeof ee, &ee);
96310
96311 msg->msg_flags |= MSG_ERRQUEUE;
96312 err = copied;
96313diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
96314index a0e9cf6..ef7f9ed 100644
96315--- a/net/core/sock_diag.c
96316+++ b/net/core/sock_diag.c
96317@@ -9,26 +9,33 @@
96318 #include <linux/inet_diag.h>
96319 #include <linux/sock_diag.h>
96320
96321-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
96322+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
96323 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
96324 static DEFINE_MUTEX(sock_diag_table_mutex);
96325
96326 int sock_diag_check_cookie(void *sk, __u32 *cookie)
96327 {
96328+#ifndef CONFIG_GRKERNSEC_HIDESYM
96329 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
96330 cookie[1] != INET_DIAG_NOCOOKIE) &&
96331 ((u32)(unsigned long)sk != cookie[0] ||
96332 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
96333 return -ESTALE;
96334 else
96335+#endif
96336 return 0;
96337 }
96338 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
96339
96340 void sock_diag_save_cookie(void *sk, __u32 *cookie)
96341 {
96342+#ifdef CONFIG_GRKERNSEC_HIDESYM
96343+ cookie[0] = 0;
96344+ cookie[1] = 0;
96345+#else
96346 cookie[0] = (u32)(unsigned long)sk;
96347 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
96348+#endif
96349 }
96350 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
96351
96352@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
96353 mutex_lock(&sock_diag_table_mutex);
96354 if (sock_diag_handlers[hndl->family])
96355 err = -EBUSY;
96356- else
96357+ else {
96358+ pax_open_kernel();
96359 sock_diag_handlers[hndl->family] = hndl;
96360+ pax_close_kernel();
96361+ }
96362 mutex_unlock(&sock_diag_table_mutex);
96363
96364 return err;
96365@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
96366
96367 mutex_lock(&sock_diag_table_mutex);
96368 BUG_ON(sock_diag_handlers[family] != hnld);
96369+ pax_open_kernel();
96370 sock_diag_handlers[family] = NULL;
96371+ pax_close_kernel();
96372 mutex_unlock(&sock_diag_table_mutex);
96373 }
96374 EXPORT_SYMBOL_GPL(sock_diag_unregister);
96375diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
96376index cca4441..5e616de 100644
96377--- a/net/core/sysctl_net_core.c
96378+++ b/net/core/sysctl_net_core.c
96379@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
96380 {
96381 unsigned int orig_size, size;
96382 int ret, i;
96383- struct ctl_table tmp = {
96384+ ctl_table_no_const tmp = {
96385 .data = &size,
96386 .maxlen = sizeof(size),
96387 .mode = table->mode
96388@@ -199,7 +199,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
96389 void __user *buffer, size_t *lenp, loff_t *ppos)
96390 {
96391 char id[IFNAMSIZ];
96392- struct ctl_table tbl = {
96393+ ctl_table_no_const tbl = {
96394 .data = id,
96395 .maxlen = IFNAMSIZ,
96396 };
96397@@ -378,13 +378,12 @@ static struct ctl_table netns_core_table[] = {
96398
96399 static __net_init int sysctl_core_net_init(struct net *net)
96400 {
96401- struct ctl_table *tbl;
96402+ ctl_table_no_const *tbl = NULL;
96403
96404 net->core.sysctl_somaxconn = SOMAXCONN;
96405
96406- tbl = netns_core_table;
96407 if (!net_eq(net, &init_net)) {
96408- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
96409+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
96410 if (tbl == NULL)
96411 goto err_dup;
96412
96413@@ -394,17 +393,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
96414 if (net->user_ns != &init_user_ns) {
96415 tbl[0].procname = NULL;
96416 }
96417- }
96418-
96419- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
96420+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
96421+ } else
96422+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
96423 if (net->core.sysctl_hdr == NULL)
96424 goto err_reg;
96425
96426 return 0;
96427
96428 err_reg:
96429- if (tbl != netns_core_table)
96430- kfree(tbl);
96431+ kfree(tbl);
96432 err_dup:
96433 return -ENOMEM;
96434 }
96435@@ -419,7 +417,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
96436 kfree(tbl);
96437 }
96438
96439-static __net_initdata struct pernet_operations sysctl_core_ops = {
96440+static __net_initconst struct pernet_operations sysctl_core_ops = {
96441 .init = sysctl_core_net_init,
96442 .exit = sysctl_core_net_exit,
96443 };
96444diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
96445index dd4d506..fb2fb87 100644
96446--- a/net/decnet/af_decnet.c
96447+++ b/net/decnet/af_decnet.c
96448@@ -465,6 +465,7 @@ static struct proto dn_proto = {
96449 .sysctl_rmem = sysctl_decnet_rmem,
96450 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
96451 .obj_size = sizeof(struct dn_sock),
96452+ .slab_flags = SLAB_USERCOPY,
96453 };
96454
96455 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
96456diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
96457index dd0dfb2..fdbc764 100644
96458--- a/net/decnet/dn_dev.c
96459+++ b/net/decnet/dn_dev.c
96460@@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
96461 .extra1 = &min_t3,
96462 .extra2 = &max_t3
96463 },
96464- {0}
96465+ { }
96466 },
96467 };
96468
96469diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
96470index 5325b54..a0d4d69 100644
96471--- a/net/decnet/sysctl_net_decnet.c
96472+++ b/net/decnet/sysctl_net_decnet.c
96473@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
96474
96475 if (len > *lenp) len = *lenp;
96476
96477- if (copy_to_user(buffer, addr, len))
96478+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
96479 return -EFAULT;
96480
96481 *lenp = len;
96482@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
96483
96484 if (len > *lenp) len = *lenp;
96485
96486- if (copy_to_user(buffer, devname, len))
96487+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
96488 return -EFAULT;
96489
96490 *lenp = len;
96491diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
96492index 1865fdf..581a595 100644
96493--- a/net/ieee802154/dgram.c
96494+++ b/net/ieee802154/dgram.c
96495@@ -315,8 +315,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
96496 if (saddr) {
96497 saddr->family = AF_IEEE802154;
96498 saddr->addr = mac_cb(skb)->sa;
96499+ }
96500+ if (addr_len)
96501 *addr_len = sizeof(*saddr);
96502- }
96503
96504 if (flags & MSG_TRUNC)
96505 copied = skb->len;
96506diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
96507index 70011e0..454ca6a 100644
96508--- a/net/ipv4/af_inet.c
96509+++ b/net/ipv4/af_inet.c
96510@@ -1683,13 +1683,9 @@ static int __init inet_init(void)
96511
96512 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
96513
96514- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
96515- if (!sysctl_local_reserved_ports)
96516- goto out;
96517-
96518 rc = proto_register(&tcp_prot, 1);
96519 if (rc)
96520- goto out_free_reserved_ports;
96521+ goto out;
96522
96523 rc = proto_register(&udp_prot, 1);
96524 if (rc)
96525@@ -1796,8 +1792,6 @@ out_unregister_udp_proto:
96526 proto_unregister(&udp_prot);
96527 out_unregister_tcp_proto:
96528 proto_unregister(&tcp_prot);
96529-out_free_reserved_ports:
96530- kfree(sysctl_local_reserved_ports);
96531 goto out;
96532 }
96533
96534diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
96535index a1b5bcb..62ec5c6 100644
96536--- a/net/ipv4/devinet.c
96537+++ b/net/ipv4/devinet.c
96538@@ -1533,7 +1533,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
96539 idx = 0;
96540 head = &net->dev_index_head[h];
96541 rcu_read_lock();
96542- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
96543+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
96544 net->dev_base_seq;
96545 hlist_for_each_entry_rcu(dev, head, index_hlist) {
96546 if (idx < s_idx)
96547@@ -1844,7 +1844,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
96548 idx = 0;
96549 head = &net->dev_index_head[h];
96550 rcu_read_lock();
96551- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
96552+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
96553 net->dev_base_seq;
96554 hlist_for_each_entry_rcu(dev, head, index_hlist) {
96555 if (idx < s_idx)
96556@@ -2069,7 +2069,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
96557 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
96558 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
96559
96560-static struct devinet_sysctl_table {
96561+static const struct devinet_sysctl_table {
96562 struct ctl_table_header *sysctl_header;
96563 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
96564 } devinet_sysctl = {
96565@@ -2191,7 +2191,7 @@ static __net_init int devinet_init_net(struct net *net)
96566 int err;
96567 struct ipv4_devconf *all, *dflt;
96568 #ifdef CONFIG_SYSCTL
96569- struct ctl_table *tbl = ctl_forward_entry;
96570+ ctl_table_no_const *tbl = NULL;
96571 struct ctl_table_header *forw_hdr;
96572 #endif
96573
96574@@ -2209,7 +2209,7 @@ static __net_init int devinet_init_net(struct net *net)
96575 goto err_alloc_dflt;
96576
96577 #ifdef CONFIG_SYSCTL
96578- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
96579+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
96580 if (tbl == NULL)
96581 goto err_alloc_ctl;
96582
96583@@ -2229,7 +2229,10 @@ static __net_init int devinet_init_net(struct net *net)
96584 goto err_reg_dflt;
96585
96586 err = -ENOMEM;
96587- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
96588+ if (!net_eq(net, &init_net))
96589+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
96590+ else
96591+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
96592 if (forw_hdr == NULL)
96593 goto err_reg_ctl;
96594 net->ipv4.forw_hdr = forw_hdr;
96595@@ -2245,8 +2248,7 @@ err_reg_ctl:
96596 err_reg_dflt:
96597 __devinet_sysctl_unregister(all);
96598 err_reg_all:
96599- if (tbl != ctl_forward_entry)
96600- kfree(tbl);
96601+ kfree(tbl);
96602 err_alloc_ctl:
96603 #endif
96604 if (dflt != &ipv4_devconf_dflt)
96605diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
96606index c7539e2..b455e51 100644
96607--- a/net/ipv4/fib_frontend.c
96608+++ b/net/ipv4/fib_frontend.c
96609@@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
96610 #ifdef CONFIG_IP_ROUTE_MULTIPATH
96611 fib_sync_up(dev);
96612 #endif
96613- atomic_inc(&net->ipv4.dev_addr_genid);
96614+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
96615 rt_cache_flush(dev_net(dev));
96616 break;
96617 case NETDEV_DOWN:
96618 fib_del_ifaddr(ifa, NULL);
96619- atomic_inc(&net->ipv4.dev_addr_genid);
96620+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
96621 if (ifa->ifa_dev->ifa_list == NULL) {
96622 /* Last address was deleted from this interface.
96623 * Disable IP.
96624@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
96625 #ifdef CONFIG_IP_ROUTE_MULTIPATH
96626 fib_sync_up(dev);
96627 #endif
96628- atomic_inc(&net->ipv4.dev_addr_genid);
96629+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
96630 rt_cache_flush(net);
96631 break;
96632 case NETDEV_DOWN:
96633diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
96634index e63f47a..e5c531d 100644
96635--- a/net/ipv4/fib_semantics.c
96636+++ b/net/ipv4/fib_semantics.c
96637@@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
96638 nh->nh_saddr = inet_select_addr(nh->nh_dev,
96639 nh->nh_gw,
96640 nh->nh_parent->fib_scope);
96641- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
96642+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
96643
96644 return nh->nh_saddr;
96645 }
96646diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
96647index fc0e649..febfa65 100644
96648--- a/net/ipv4/inet_connection_sock.c
96649+++ b/net/ipv4/inet_connection_sock.c
96650@@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
96651 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
96652 #endif
96653
96654-unsigned long *sysctl_local_reserved_ports;
96655+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
96656 EXPORT_SYMBOL(sysctl_local_reserved_ports);
96657
96658 void inet_get_local_port_range(struct net *net, int *low, int *high)
96659diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
96660index 8b9cf27..0d8d592 100644
96661--- a/net/ipv4/inet_hashtables.c
96662+++ b/net/ipv4/inet_hashtables.c
96663@@ -18,6 +18,7 @@
96664 #include <linux/sched.h>
96665 #include <linux/slab.h>
96666 #include <linux/wait.h>
96667+#include <linux/security.h>
96668
96669 #include <net/inet_connection_sock.h>
96670 #include <net/inet_hashtables.h>
96671@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
96672 return inet_ehashfn(net, laddr, lport, faddr, fport);
96673 }
96674
96675+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
96676+
96677 /*
96678 * Allocate and initialize a new local port bind bucket.
96679 * The bindhash mutex for snum's hash chain must be held here.
96680@@ -554,6 +557,8 @@ ok:
96681 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
96682 spin_unlock(&head->lock);
96683
96684+ gr_update_task_in_ip_table(current, inet_sk(sk));
96685+
96686 if (tw) {
96687 inet_twsk_deschedule(tw, death_row);
96688 while (twrefcnt) {
96689diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
96690index 33d5537..da337a4 100644
96691--- a/net/ipv4/inetpeer.c
96692+++ b/net/ipv4/inetpeer.c
96693@@ -503,8 +503,8 @@ relookup:
96694 if (p) {
96695 p->daddr = *daddr;
96696 atomic_set(&p->refcnt, 1);
96697- atomic_set(&p->rid, 0);
96698- atomic_set(&p->ip_id_count,
96699+ atomic_set_unchecked(&p->rid, 0);
96700+ atomic_set_unchecked(&p->ip_id_count,
96701 (daddr->family == AF_INET) ?
96702 secure_ip_id(daddr->addr.a4) :
96703 secure_ipv6_id(daddr->addr.a6));
96704diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
96705index 2481993..2d9a7a7 100644
96706--- a/net/ipv4/ip_fragment.c
96707+++ b/net/ipv4/ip_fragment.c
96708@@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
96709 return 0;
96710
96711 start = qp->rid;
96712- end = atomic_inc_return(&peer->rid);
96713+ end = atomic_inc_return_unchecked(&peer->rid);
96714 qp->rid = end;
96715
96716 rc = qp->q.fragments && (end - start) > max;
96717@@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
96718
96719 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
96720 {
96721- struct ctl_table *table;
96722+ ctl_table_no_const *table = NULL;
96723 struct ctl_table_header *hdr;
96724
96725- table = ip4_frags_ns_ctl_table;
96726 if (!net_eq(net, &init_net)) {
96727- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
96728+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
96729 if (table == NULL)
96730 goto err_alloc;
96731
96732@@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
96733 /* Don't export sysctls to unprivileged users */
96734 if (net->user_ns != &init_user_ns)
96735 table[0].procname = NULL;
96736- }
96737+ hdr = register_net_sysctl(net, "net/ipv4", table);
96738+ } else
96739+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
96740
96741- hdr = register_net_sysctl(net, "net/ipv4", table);
96742 if (hdr == NULL)
96743 goto err_reg;
96744
96745@@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
96746 return 0;
96747
96748 err_reg:
96749- if (!net_eq(net, &init_net))
96750- kfree(table);
96751+ kfree(table);
96752 err_alloc:
96753 return -ENOMEM;
96754 }
96755diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
96756index d306360..1c1a1f1 100644
96757--- a/net/ipv4/ip_gre.c
96758+++ b/net/ipv4/ip_gre.c
96759@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
96760 module_param(log_ecn_error, bool, 0644);
96761 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
96762
96763-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
96764+static struct rtnl_link_ops ipgre_link_ops;
96765 static int ipgre_tunnel_init(struct net_device *dev);
96766
96767 static int ipgre_net_id __read_mostly;
96768@@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
96769 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
96770 };
96771
96772-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
96773+static struct rtnl_link_ops ipgre_link_ops = {
96774 .kind = "gre",
96775 .maxtype = IFLA_GRE_MAX,
96776 .policy = ipgre_policy,
96777@@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
96778 .fill_info = ipgre_fill_info,
96779 };
96780
96781-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
96782+static struct rtnl_link_ops ipgre_tap_ops = {
96783 .kind = "gretap",
96784 .maxtype = IFLA_GRE_MAX,
96785 .policy = ipgre_policy,
96786diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
96787index ddf32a6..3fdeea9 100644
96788--- a/net/ipv4/ip_sockglue.c
96789+++ b/net/ipv4/ip_sockglue.c
96790@@ -1172,7 +1172,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
96791 len = min_t(unsigned int, len, opt->optlen);
96792 if (put_user(len, optlen))
96793 return -EFAULT;
96794- if (copy_to_user(optval, opt->__data, len))
96795+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
96796+ copy_to_user(optval, opt->__data, len))
96797 return -EFAULT;
96798 return 0;
96799 }
96800@@ -1303,7 +1304,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
96801 if (sk->sk_type != SOCK_STREAM)
96802 return -ENOPROTOOPT;
96803
96804- msg.msg_control = optval;
96805+ msg.msg_control = (void __force_kernel *)optval;
96806 msg.msg_controllen = len;
96807 msg.msg_flags = flags;
96808
96809diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
96810index 52b802a..b725179 100644
96811--- a/net/ipv4/ip_vti.c
96812+++ b/net/ipv4/ip_vti.c
96813@@ -44,7 +44,7 @@
96814 #include <net/net_namespace.h>
96815 #include <net/netns/generic.h>
96816
96817-static struct rtnl_link_ops vti_link_ops __read_mostly;
96818+static struct rtnl_link_ops vti_link_ops;
96819
96820 static int vti_net_id __read_mostly;
96821 static int vti_tunnel_init(struct net_device *dev);
96822@@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
96823 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
96824 };
96825
96826-static struct rtnl_link_ops vti_link_ops __read_mostly = {
96827+static struct rtnl_link_ops vti_link_ops = {
96828 .kind = "vti",
96829 .maxtype = IFLA_VTI_MAX,
96830 .policy = vti_policy,
96831diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
96832index efa1138..20dbba0 100644
96833--- a/net/ipv4/ipconfig.c
96834+++ b/net/ipv4/ipconfig.c
96835@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
96836
96837 mm_segment_t oldfs = get_fs();
96838 set_fs(get_ds());
96839- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
96840+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
96841 set_fs(oldfs);
96842 return res;
96843 }
96844@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
96845
96846 mm_segment_t oldfs = get_fs();
96847 set_fs(get_ds());
96848- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
96849+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
96850 set_fs(oldfs);
96851 return res;
96852 }
96853@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
96854
96855 mm_segment_t oldfs = get_fs();
96856 set_fs(get_ds());
96857- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
96858+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
96859 set_fs(oldfs);
96860 return res;
96861 }
96862diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
96863index fe3e9f7..4956990 100644
96864--- a/net/ipv4/ipip.c
96865+++ b/net/ipv4/ipip.c
96866@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
96867 static int ipip_net_id __read_mostly;
96868
96869 static int ipip_tunnel_init(struct net_device *dev);
96870-static struct rtnl_link_ops ipip_link_ops __read_mostly;
96871+static struct rtnl_link_ops ipip_link_ops;
96872
96873 static int ipip_err(struct sk_buff *skb, u32 info)
96874 {
96875@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
96876 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
96877 };
96878
96879-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
96880+static struct rtnl_link_ops ipip_link_ops = {
96881 .kind = "ipip",
96882 .maxtype = IFLA_IPTUN_MAX,
96883 .policy = ipip_policy,
96884diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
96885index 59da7cd..e318de1 100644
96886--- a/net/ipv4/netfilter/arp_tables.c
96887+++ b/net/ipv4/netfilter/arp_tables.c
96888@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
96889 #endif
96890
96891 static int get_info(struct net *net, void __user *user,
96892- const int *len, int compat)
96893+ int len, int compat)
96894 {
96895 char name[XT_TABLE_MAXNAMELEN];
96896 struct xt_table *t;
96897 int ret;
96898
96899- if (*len != sizeof(struct arpt_getinfo)) {
96900- duprintf("length %u != %Zu\n", *len,
96901+ if (len != sizeof(struct arpt_getinfo)) {
96902+ duprintf("length %u != %Zu\n", len,
96903 sizeof(struct arpt_getinfo));
96904 return -EINVAL;
96905 }
96906@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
96907 info.size = private->size;
96908 strcpy(info.name, name);
96909
96910- if (copy_to_user(user, &info, *len) != 0)
96911+ if (copy_to_user(user, &info, len) != 0)
96912 ret = -EFAULT;
96913 else
96914 ret = 0;
96915@@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
96916
96917 switch (cmd) {
96918 case ARPT_SO_GET_INFO:
96919- ret = get_info(sock_net(sk), user, len, 1);
96920+ ret = get_info(sock_net(sk), user, *len, 1);
96921 break;
96922 case ARPT_SO_GET_ENTRIES:
96923 ret = compat_get_entries(sock_net(sk), user, len);
96924@@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
96925
96926 switch (cmd) {
96927 case ARPT_SO_GET_INFO:
96928- ret = get_info(sock_net(sk), user, len, 0);
96929+ ret = get_info(sock_net(sk), user, *len, 0);
96930 break;
96931
96932 case ARPT_SO_GET_ENTRIES:
96933diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
96934index 718dfbd..cef4152 100644
96935--- a/net/ipv4/netfilter/ip_tables.c
96936+++ b/net/ipv4/netfilter/ip_tables.c
96937@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
96938 #endif
96939
96940 static int get_info(struct net *net, void __user *user,
96941- const int *len, int compat)
96942+ int len, int compat)
96943 {
96944 char name[XT_TABLE_MAXNAMELEN];
96945 struct xt_table *t;
96946 int ret;
96947
96948- if (*len != sizeof(struct ipt_getinfo)) {
96949- duprintf("length %u != %zu\n", *len,
96950+ if (len != sizeof(struct ipt_getinfo)) {
96951+ duprintf("length %u != %zu\n", len,
96952 sizeof(struct ipt_getinfo));
96953 return -EINVAL;
96954 }
96955@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
96956 info.size = private->size;
96957 strcpy(info.name, name);
96958
96959- if (copy_to_user(user, &info, *len) != 0)
96960+ if (copy_to_user(user, &info, len) != 0)
96961 ret = -EFAULT;
96962 else
96963 ret = 0;
96964@@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96965
96966 switch (cmd) {
96967 case IPT_SO_GET_INFO:
96968- ret = get_info(sock_net(sk), user, len, 1);
96969+ ret = get_info(sock_net(sk), user, *len, 1);
96970 break;
96971 case IPT_SO_GET_ENTRIES:
96972 ret = compat_get_entries(sock_net(sk), user, len);
96973@@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96974
96975 switch (cmd) {
96976 case IPT_SO_GET_INFO:
96977- ret = get_info(sock_net(sk), user, len, 0);
96978+ ret = get_info(sock_net(sk), user, *len, 0);
96979 break;
96980
96981 case IPT_SO_GET_ENTRIES:
96982diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
96983index 242e7f4..a084e95 100644
96984--- a/net/ipv4/ping.c
96985+++ b/net/ipv4/ping.c
96986@@ -55,7 +55,7 @@
96987
96988
96989 struct ping_table ping_table;
96990-struct pingv6_ops pingv6_ops;
96991+struct pingv6_ops *pingv6_ops;
96992 EXPORT_SYMBOL_GPL(pingv6_ops);
96993
96994 static u16 ping_port_rover;
96995@@ -334,7 +334,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
96996 return -ENODEV;
96997 }
96998 }
96999- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
97000+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
97001 scoped);
97002 rcu_read_unlock();
97003
97004@@ -542,7 +542,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
97005 }
97006 #if IS_ENABLED(CONFIG_IPV6)
97007 } else if (skb->protocol == htons(ETH_P_IPV6)) {
97008- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
97009+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
97010 #endif
97011 }
97012
97013@@ -560,7 +560,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
97014 info, (u8 *)icmph);
97015 #if IS_ENABLED(CONFIG_IPV6)
97016 } else if (family == AF_INET6) {
97017- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
97018+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
97019 info, (u8 *)icmph);
97020 #endif
97021 }
97022@@ -830,6 +830,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97023 {
97024 struct inet_sock *isk = inet_sk(sk);
97025 int family = sk->sk_family;
97026+ struct sockaddr_in *sin;
97027+ struct sockaddr_in6 *sin6;
97028 struct sk_buff *skb;
97029 int copied, err;
97030
97031@@ -839,12 +841,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97032 if (flags & MSG_OOB)
97033 goto out;
97034
97035+ if (addr_len) {
97036+ if (family == AF_INET)
97037+ *addr_len = sizeof(*sin);
97038+ else if (family == AF_INET6 && addr_len)
97039+ *addr_len = sizeof(*sin6);
97040+ }
97041+
97042 if (flags & MSG_ERRQUEUE) {
97043 if (family == AF_INET) {
97044 return ip_recv_error(sk, msg, len, addr_len);
97045 #if IS_ENABLED(CONFIG_IPV6)
97046 } else if (family == AF_INET6) {
97047- return pingv6_ops.ipv6_recv_error(sk, msg, len,
97048+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
97049 addr_len);
97050 #endif
97051 }
97052@@ -876,7 +885,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97053 sin->sin_port = 0 /* skb->h.uh->source */;
97054 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
97055 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
97056- *addr_len = sizeof(*sin);
97057 }
97058
97059 if (isk->cmsg_flags)
97060@@ -899,11 +907,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97061 sin6->sin6_scope_id =
97062 ipv6_iface_scope_id(&sin6->sin6_addr,
97063 IP6CB(skb)->iif);
97064- *addr_len = sizeof(*sin6);
97065 }
97066
97067 if (inet6_sk(sk)->rxopt.all)
97068- pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
97069+ pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
97070 #endif
97071 } else {
97072 BUG();
97073@@ -1093,7 +1100,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
97074 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
97075 0, sock_i_ino(sp),
97076 atomic_read(&sp->sk_refcnt), sp,
97077- atomic_read(&sp->sk_drops));
97078+ atomic_read_unchecked(&sp->sk_drops));
97079 }
97080
97081 static int ping_v4_seq_show(struct seq_file *seq, void *v)
97082diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
97083index 23c3e5b..cdb8b36 100644
97084--- a/net/ipv4/raw.c
97085+++ b/net/ipv4/raw.c
97086@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
97087 int raw_rcv(struct sock *sk, struct sk_buff *skb)
97088 {
97089 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
97090- atomic_inc(&sk->sk_drops);
97091+ atomic_inc_unchecked(&sk->sk_drops);
97092 kfree_skb(skb);
97093 return NET_RX_DROP;
97094 }
97095@@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97096 if (flags & MSG_OOB)
97097 goto out;
97098
97099+ if (addr_len)
97100+ *addr_len = sizeof(*sin);
97101+
97102 if (flags & MSG_ERRQUEUE) {
97103 err = ip_recv_error(sk, msg, len, addr_len);
97104 goto out;
97105@@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97106 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
97107 sin->sin_port = 0;
97108 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
97109- *addr_len = sizeof(*sin);
97110 }
97111 if (inet->cmsg_flags)
97112 ip_cmsg_recv(msg, skb);
97113@@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
97114
97115 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
97116 {
97117+ struct icmp_filter filter;
97118+
97119 if (optlen > sizeof(struct icmp_filter))
97120 optlen = sizeof(struct icmp_filter);
97121- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
97122+ if (copy_from_user(&filter, optval, optlen))
97123 return -EFAULT;
97124+ raw_sk(sk)->filter = filter;
97125 return 0;
97126 }
97127
97128 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
97129 {
97130 int len, ret = -EFAULT;
97131+ struct icmp_filter filter;
97132
97133 if (get_user(len, optlen))
97134 goto out;
97135@@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
97136 if (len > sizeof(struct icmp_filter))
97137 len = sizeof(struct icmp_filter);
97138 ret = -EFAULT;
97139- if (put_user(len, optlen) ||
97140- copy_to_user(optval, &raw_sk(sk)->filter, len))
97141+ filter = raw_sk(sk)->filter;
97142+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
97143 goto out;
97144 ret = 0;
97145 out: return ret;
97146@@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
97147 0, 0L, 0,
97148 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
97149 0, sock_i_ino(sp),
97150- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
97151+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
97152 }
97153
97154 static int raw_seq_show(struct seq_file *seq, void *v)
97155diff --git a/net/ipv4/route.c b/net/ipv4/route.c
97156index f8da282..133a1c7 100644
97157--- a/net/ipv4/route.c
97158+++ b/net/ipv4/route.c
97159@@ -2621,34 +2621,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
97160 .maxlen = sizeof(int),
97161 .mode = 0200,
97162 .proc_handler = ipv4_sysctl_rtcache_flush,
97163+ .extra1 = &init_net,
97164 },
97165 { },
97166 };
97167
97168 static __net_init int sysctl_route_net_init(struct net *net)
97169 {
97170- struct ctl_table *tbl;
97171+ ctl_table_no_const *tbl = NULL;
97172
97173- tbl = ipv4_route_flush_table;
97174 if (!net_eq(net, &init_net)) {
97175- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
97176+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
97177 if (tbl == NULL)
97178 goto err_dup;
97179
97180 /* Don't export sysctls to unprivileged users */
97181 if (net->user_ns != &init_user_ns)
97182 tbl[0].procname = NULL;
97183- }
97184- tbl[0].extra1 = net;
97185+ tbl[0].extra1 = net;
97186+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
97187+ } else
97188+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
97189
97190- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
97191 if (net->ipv4.route_hdr == NULL)
97192 goto err_reg;
97193 return 0;
97194
97195 err_reg:
97196- if (tbl != ipv4_route_flush_table)
97197- kfree(tbl);
97198+ kfree(tbl);
97199 err_dup:
97200 return -ENOMEM;
97201 }
97202@@ -2671,8 +2671,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
97203
97204 static __net_init int rt_genid_init(struct net *net)
97205 {
97206- atomic_set(&net->ipv4.rt_genid, 0);
97207- atomic_set(&net->fnhe_genid, 0);
97208+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
97209+ atomic_set_unchecked(&net->fnhe_genid, 0);
97210 get_random_bytes(&net->ipv4.dev_addr_genid,
97211 sizeof(net->ipv4.dev_addr_genid));
97212 return 0;
97213diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
97214index 3d69ec8..57207b4 100644
97215--- a/net/ipv4/sysctl_net_ipv4.c
97216+++ b/net/ipv4/sysctl_net_ipv4.c
97217@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
97218 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
97219 int ret;
97220 int range[2];
97221- struct ctl_table tmp = {
97222+ ctl_table_no_const tmp = {
97223 .data = &range,
97224 .maxlen = sizeof(range),
97225 .mode = table->mode,
97226@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
97227 int ret;
97228 gid_t urange[2];
97229 kgid_t low, high;
97230- struct ctl_table tmp = {
97231+ ctl_table_no_const tmp = {
97232 .data = &urange,
97233 .maxlen = sizeof(urange),
97234 .mode = table->mode,
97235@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
97236 void __user *buffer, size_t *lenp, loff_t *ppos)
97237 {
97238 char val[TCP_CA_NAME_MAX];
97239- struct ctl_table tbl = {
97240+ ctl_table_no_const tbl = {
97241 .data = val,
97242 .maxlen = TCP_CA_NAME_MAX,
97243 };
97244@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
97245 void __user *buffer, size_t *lenp,
97246 loff_t *ppos)
97247 {
97248- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
97249+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
97250 int ret;
97251
97252 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
97253@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
97254 void __user *buffer, size_t *lenp,
97255 loff_t *ppos)
97256 {
97257- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
97258+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
97259 int ret;
97260
97261 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
97262@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
97263 void __user *buffer, size_t *lenp,
97264 loff_t *ppos)
97265 {
97266- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
97267+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
97268 struct tcp_fastopen_context *ctxt;
97269 int ret;
97270 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
97271@@ -445,7 +445,7 @@ static struct ctl_table ipv4_table[] = {
97272 },
97273 {
97274 .procname = "ip_local_reserved_ports",
97275- .data = NULL, /* initialized in sysctl_ipv4_init */
97276+ .data = sysctl_local_reserved_ports,
97277 .maxlen = 65536,
97278 .mode = 0644,
97279 .proc_handler = proc_do_large_bitmap,
97280@@ -827,13 +827,12 @@ static struct ctl_table ipv4_net_table[] = {
97281
97282 static __net_init int ipv4_sysctl_init_net(struct net *net)
97283 {
97284- struct ctl_table *table;
97285+ ctl_table_no_const *table = NULL;
97286
97287- table = ipv4_net_table;
97288 if (!net_eq(net, &init_net)) {
97289 int i;
97290
97291- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
97292+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
97293 if (table == NULL)
97294 goto err_alloc;
97295
97296@@ -856,15 +855,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
97297 net->ipv4.sysctl_local_ports.range[0] = 32768;
97298 net->ipv4.sysctl_local_ports.range[1] = 61000;
97299
97300- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
97301+ if (!net_eq(net, &init_net))
97302+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
97303+ else
97304+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
97305 if (net->ipv4.ipv4_hdr == NULL)
97306 goto err_reg;
97307
97308 return 0;
97309
97310 err_reg:
97311- if (!net_eq(net, &init_net))
97312- kfree(table);
97313+ kfree(table);
97314 err_alloc:
97315 return -ENOMEM;
97316 }
97317@@ -886,16 +887,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
97318 static __init int sysctl_ipv4_init(void)
97319 {
97320 struct ctl_table_header *hdr;
97321- struct ctl_table *i;
97322-
97323- for (i = ipv4_table; i->procname; i++) {
97324- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
97325- i->data = sysctl_local_reserved_ports;
97326- break;
97327- }
97328- }
97329- if (!i->procname)
97330- return -EINVAL;
97331
97332 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
97333 if (hdr == NULL)
97334diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
97335index c53b7f3..a89aadd 100644
97336--- a/net/ipv4/tcp_input.c
97337+++ b/net/ipv4/tcp_input.c
97338@@ -759,7 +759,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
97339 * without any lock. We want to make sure compiler wont store
97340 * intermediate values in this location.
97341 */
97342- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
97343+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
97344 sk->sk_max_pacing_rate);
97345 }
97346
97347@@ -4482,7 +4482,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
97348 * simplifies code)
97349 */
97350 static void
97351-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
97352+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
97353 struct sk_buff *head, struct sk_buff *tail,
97354 u32 start, u32 end)
97355 {
97356@@ -5559,6 +5559,7 @@ discard:
97357 tcp_paws_reject(&tp->rx_opt, 0))
97358 goto discard_and_undo;
97359
97360+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
97361 if (th->syn) {
97362 /* We see SYN without ACK. It is attempt of
97363 * simultaneous connect with crossed SYNs.
97364@@ -5609,6 +5610,7 @@ discard:
97365 goto discard;
97366 #endif
97367 }
97368+#endif
97369 /* "fifth, if neither of the SYN or RST bits is set then
97370 * drop the segment and return."
97371 */
97372@@ -5655,7 +5657,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
97373 goto discard;
97374
97375 if (th->syn) {
97376- if (th->fin)
97377+ if (th->fin || th->urg || th->psh)
97378 goto discard;
97379 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
97380 return 1;
97381diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
97382index 0672139..cacc17d 100644
97383--- a/net/ipv4/tcp_ipv4.c
97384+++ b/net/ipv4/tcp_ipv4.c
97385@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
97386 EXPORT_SYMBOL(sysctl_tcp_low_latency);
97387
97388
97389+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97390+extern int grsec_enable_blackhole;
97391+#endif
97392+
97393 #ifdef CONFIG_TCP_MD5SIG
97394 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
97395 __be32 daddr, __be32 saddr, const struct tcphdr *th);
97396@@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
97397 return 0;
97398
97399 reset:
97400+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97401+ if (!grsec_enable_blackhole)
97402+#endif
97403 tcp_v4_send_reset(rsk, skb);
97404 discard:
97405 kfree_skb(skb);
97406@@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
97407 TCP_SKB_CB(skb)->sacked = 0;
97408
97409 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
97410- if (!sk)
97411+ if (!sk) {
97412+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97413+ ret = 1;
97414+#endif
97415 goto no_tcp_socket;
97416-
97417+ }
97418 process:
97419- if (sk->sk_state == TCP_TIME_WAIT)
97420+ if (sk->sk_state == TCP_TIME_WAIT) {
97421+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97422+ ret = 2;
97423+#endif
97424 goto do_time_wait;
97425+ }
97426
97427 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
97428 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
97429@@ -2034,6 +2048,10 @@ csum_error:
97430 bad_packet:
97431 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
97432 } else {
97433+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97434+ if (!grsec_enable_blackhole || (ret == 1 &&
97435+ (skb->dev->flags & IFF_LOOPBACK)))
97436+#endif
97437 tcp_v4_send_reset(NULL, skb);
97438 }
97439
97440diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
97441index 97b6841..0893357 100644
97442--- a/net/ipv4/tcp_minisocks.c
97443+++ b/net/ipv4/tcp_minisocks.c
97444@@ -27,6 +27,10 @@
97445 #include <net/inet_common.h>
97446 #include <net/xfrm.h>
97447
97448+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97449+extern int grsec_enable_blackhole;
97450+#endif
97451+
97452 int sysctl_tcp_syncookies __read_mostly = 1;
97453 EXPORT_SYMBOL(sysctl_tcp_syncookies);
97454
97455@@ -708,7 +712,10 @@ embryonic_reset:
97456 * avoid becoming vulnerable to outside attack aiming at
97457 * resetting legit local connections.
97458 */
97459- req->rsk_ops->send_reset(sk, skb);
97460+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97461+ if (!grsec_enable_blackhole)
97462+#endif
97463+ req->rsk_ops->send_reset(sk, skb);
97464 } else if (fastopen) { /* received a valid RST pkt */
97465 reqsk_fastopen_remove(sk, req, true);
97466 tcp_reset(sk);
97467diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
97468index 8b97d71..9d7ccf5 100644
97469--- a/net/ipv4/tcp_probe.c
97470+++ b/net/ipv4/tcp_probe.c
97471@@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
97472 if (cnt + width >= len)
97473 break;
97474
97475- if (copy_to_user(buf + cnt, tbuf, width))
97476+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
97477 return -EFAULT;
97478 cnt += width;
97479 }
97480diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
97481index 64f0354..a81b39d 100644
97482--- a/net/ipv4/tcp_timer.c
97483+++ b/net/ipv4/tcp_timer.c
97484@@ -22,6 +22,10 @@
97485 #include <linux/gfp.h>
97486 #include <net/tcp.h>
97487
97488+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97489+extern int grsec_lastack_retries;
97490+#endif
97491+
97492 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
97493 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
97494 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
97495@@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
97496 }
97497 }
97498
97499+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97500+ if ((sk->sk_state == TCP_LAST_ACK) &&
97501+ (grsec_lastack_retries > 0) &&
97502+ (grsec_lastack_retries < retry_until))
97503+ retry_until = grsec_lastack_retries;
97504+#endif
97505+
97506 if (retransmits_timed_out(sk, retry_until,
97507 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
97508 /* Has it gone just too far? */
97509diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
97510index a7e4729..2758946 100644
97511--- a/net/ipv4/udp.c
97512+++ b/net/ipv4/udp.c
97513@@ -87,6 +87,7 @@
97514 #include <linux/types.h>
97515 #include <linux/fcntl.h>
97516 #include <linux/module.h>
97517+#include <linux/security.h>
97518 #include <linux/socket.h>
97519 #include <linux/sockios.h>
97520 #include <linux/igmp.h>
97521@@ -113,6 +114,10 @@
97522 #include <net/busy_poll.h>
97523 #include "udp_impl.h"
97524
97525+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97526+extern int grsec_enable_blackhole;
97527+#endif
97528+
97529 struct udp_table udp_table __read_mostly;
97530 EXPORT_SYMBOL(udp_table);
97531
97532@@ -615,6 +620,9 @@ found:
97533 return s;
97534 }
97535
97536+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
97537+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
97538+
97539 /*
97540 * This routine is called by the ICMP module when it gets some
97541 * sort of error condition. If err < 0 then the socket should
97542@@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97543 dport = usin->sin_port;
97544 if (dport == 0)
97545 return -EINVAL;
97546+
97547+ err = gr_search_udp_sendmsg(sk, usin);
97548+ if (err)
97549+ return err;
97550 } else {
97551 if (sk->sk_state != TCP_ESTABLISHED)
97552 return -EDESTADDRREQ;
97553+
97554+ err = gr_search_udp_sendmsg(sk, NULL);
97555+ if (err)
97556+ return err;
97557+
97558 daddr = inet->inet_daddr;
97559 dport = inet->inet_dport;
97560 /* Open fast path for connected socket.
97561@@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
97562 IS_UDPLITE(sk));
97563 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
97564 IS_UDPLITE(sk));
97565- atomic_inc(&sk->sk_drops);
97566+ atomic_inc_unchecked(&sk->sk_drops);
97567 __skb_unlink(skb, rcvq);
97568 __skb_queue_tail(&list_kill, skb);
97569 }
97570@@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97571 int is_udplite = IS_UDPLITE(sk);
97572 bool slow;
97573
97574+ /*
97575+ * Check any passed addresses
97576+ */
97577+ if (addr_len)
97578+ *addr_len = sizeof(*sin);
97579+
97580 if (flags & MSG_ERRQUEUE)
97581 return ip_recv_error(sk, msg, len, addr_len);
97582
97583@@ -1243,6 +1266,10 @@ try_again:
97584 if (!skb)
97585 goto out;
97586
97587+ err = gr_search_udp_recvmsg(sk, skb);
97588+ if (err)
97589+ goto out_free;
97590+
97591 ulen = skb->len - sizeof(struct udphdr);
97592 copied = len;
97593 if (copied > ulen)
97594@@ -1276,7 +1303,7 @@ try_again:
97595 if (unlikely(err)) {
97596 trace_kfree_skb(skb, udp_recvmsg);
97597 if (!peeked) {
97598- atomic_inc(&sk->sk_drops);
97599+ atomic_inc_unchecked(&sk->sk_drops);
97600 UDP_INC_STATS_USER(sock_net(sk),
97601 UDP_MIB_INERRORS, is_udplite);
97602 }
97603@@ -1295,7 +1322,6 @@ try_again:
97604 sin->sin_port = udp_hdr(skb)->source;
97605 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
97606 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
97607- *addr_len = sizeof(*sin);
97608 }
97609 if (inet->cmsg_flags)
97610 ip_cmsg_recv(msg, skb);
97611@@ -1566,7 +1592,7 @@ csum_error:
97612 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
97613 drop:
97614 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
97615- atomic_inc(&sk->sk_drops);
97616+ atomic_inc_unchecked(&sk->sk_drops);
97617 kfree_skb(skb);
97618 return -1;
97619 }
97620@@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
97621 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
97622
97623 if (!skb1) {
97624- atomic_inc(&sk->sk_drops);
97625+ atomic_inc_unchecked(&sk->sk_drops);
97626 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
97627 IS_UDPLITE(sk));
97628 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
97629@@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
97630 goto csum_error;
97631
97632 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
97633+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97634+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
97635+#endif
97636 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
97637
97638 /*
97639@@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
97640 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
97641 0, sock_i_ino(sp),
97642 atomic_read(&sp->sk_refcnt), sp,
97643- atomic_read(&sp->sk_drops));
97644+ atomic_read_unchecked(&sp->sk_drops));
97645 }
97646
97647 int udp4_seq_show(struct seq_file *seq, void *v)
97648diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
97649index e1a6393..f634ce5 100644
97650--- a/net/ipv4/xfrm4_policy.c
97651+++ b/net/ipv4/xfrm4_policy.c
97652@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
97653 fl4->flowi4_tos = iph->tos;
97654 }
97655
97656-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
97657+static int xfrm4_garbage_collect(struct dst_ops *ops)
97658 {
97659 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
97660
97661- xfrm4_policy_afinfo.garbage_collect(net);
97662+ xfrm_garbage_collect_deferred(net);
97663 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
97664 }
97665
97666@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
97667
97668 static int __net_init xfrm4_net_init(struct net *net)
97669 {
97670- struct ctl_table *table;
97671+ ctl_table_no_const *table = NULL;
97672 struct ctl_table_header *hdr;
97673
97674- table = xfrm4_policy_table;
97675 if (!net_eq(net, &init_net)) {
97676- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
97677+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
97678 if (!table)
97679 goto err_alloc;
97680
97681 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
97682- }
97683-
97684- hdr = register_net_sysctl(net, "net/ipv4", table);
97685+ hdr = register_net_sysctl(net, "net/ipv4", table);
97686+ } else
97687+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
97688 if (!hdr)
97689 goto err_reg;
97690
97691@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
97692 return 0;
97693
97694 err_reg:
97695- if (!net_eq(net, &init_net))
97696- kfree(table);
97697+ kfree(table);
97698 err_alloc:
97699 return -ENOMEM;
97700 }
97701diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
97702index 4b6b720..272c0c5 100644
97703--- a/net/ipv6/addrconf.c
97704+++ b/net/ipv6/addrconf.c
97705@@ -589,7 +589,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
97706 idx = 0;
97707 head = &net->dev_index_head[h];
97708 rcu_read_lock();
97709- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
97710+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
97711 net->dev_base_seq;
97712 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97713 if (idx < s_idx)
97714@@ -2334,7 +2334,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
97715 p.iph.ihl = 5;
97716 p.iph.protocol = IPPROTO_IPV6;
97717 p.iph.ttl = 64;
97718- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
97719+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
97720
97721 if (ops->ndo_do_ioctl) {
97722 mm_segment_t oldfs = get_fs();
97723@@ -3962,7 +3962,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
97724 s_ip_idx = ip_idx = cb->args[2];
97725
97726 rcu_read_lock();
97727- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
97728+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
97729 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
97730 idx = 0;
97731 head = &net->dev_index_head[h];
97732@@ -4569,7 +4569,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
97733 dst_free(&ifp->rt->dst);
97734 break;
97735 }
97736- atomic_inc(&net->ipv6.dev_addr_genid);
97737+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
97738 rt_genid_bump_ipv6(net);
97739 }
97740
97741@@ -4590,7 +4590,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
97742 int *valp = ctl->data;
97743 int val = *valp;
97744 loff_t pos = *ppos;
97745- struct ctl_table lctl;
97746+ ctl_table_no_const lctl;
97747 int ret;
97748
97749 /*
97750@@ -4675,7 +4675,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
97751 int *valp = ctl->data;
97752 int val = *valp;
97753 loff_t pos = *ppos;
97754- struct ctl_table lctl;
97755+ ctl_table_no_const lctl;
97756 int ret;
97757
97758 /*
97759diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
97760index 4fbdb70..f6411f2 100644
97761--- a/net/ipv6/af_inet6.c
97762+++ b/net/ipv6/af_inet6.c
97763@@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
97764
97765 net->ipv6.sysctl.bindv6only = 0;
97766 net->ipv6.sysctl.icmpv6_time = 1*HZ;
97767- atomic_set(&net->ipv6.rt_genid, 0);
97768+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
97769
97770 err = ipv6_init_mibs(net);
97771 if (err)
97772diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
97773index 93b1aa3..e902855 100644
97774--- a/net/ipv6/datagram.c
97775+++ b/net/ipv6/datagram.c
97776@@ -906,5 +906,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
97777 0,
97778 sock_i_ino(sp),
97779 atomic_read(&sp->sk_refcnt), sp,
97780- atomic_read(&sp->sk_drops));
97781+ atomic_read_unchecked(&sp->sk_drops));
97782 }
97783diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
97784index eef8d94..cfa1852 100644
97785--- a/net/ipv6/icmp.c
97786+++ b/net/ipv6/icmp.c
97787@@ -997,7 +997,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
97788
97789 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
97790 {
97791- struct ctl_table *table;
97792+ ctl_table_no_const *table;
97793
97794 table = kmemdup(ipv6_icmp_table_template,
97795 sizeof(ipv6_icmp_table_template),
97796diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
97797index 8acb286..840dd06 100644
97798--- a/net/ipv6/ip6_gre.c
97799+++ b/net/ipv6/ip6_gre.c
97800@@ -74,7 +74,7 @@ struct ip6gre_net {
97801 struct net_device *fb_tunnel_dev;
97802 };
97803
97804-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
97805+static struct rtnl_link_ops ip6gre_link_ops;
97806 static int ip6gre_tunnel_init(struct net_device *dev);
97807 static void ip6gre_tunnel_setup(struct net_device *dev);
97808 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
97809@@ -1294,7 +1294,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
97810 }
97811
97812
97813-static struct inet6_protocol ip6gre_protocol __read_mostly = {
97814+static struct inet6_protocol ip6gre_protocol = {
97815 .handler = ip6gre_rcv,
97816 .err_handler = ip6gre_err,
97817 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
97818@@ -1637,7 +1637,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
97819 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
97820 };
97821
97822-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
97823+static struct rtnl_link_ops ip6gre_link_ops = {
97824 .kind = "ip6gre",
97825 .maxtype = IFLA_GRE_MAX,
97826 .policy = ip6gre_policy,
97827@@ -1650,7 +1650,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
97828 .fill_info = ip6gre_fill_info,
97829 };
97830
97831-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
97832+static struct rtnl_link_ops ip6gre_tap_ops = {
97833 .kind = "ip6gretap",
97834 .maxtype = IFLA_GRE_MAX,
97835 .policy = ip6gre_policy,
97836diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
97837index 7881965..9cf62c4 100644
97838--- a/net/ipv6/ip6_tunnel.c
97839+++ b/net/ipv6/ip6_tunnel.c
97840@@ -89,7 +89,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
97841
97842 static int ip6_tnl_dev_init(struct net_device *dev);
97843 static void ip6_tnl_dev_setup(struct net_device *dev);
97844-static struct rtnl_link_ops ip6_link_ops __read_mostly;
97845+static struct rtnl_link_ops ip6_link_ops;
97846
97847 static int ip6_tnl_net_id __read_mostly;
97848 struct ip6_tnl_net {
97849@@ -1717,7 +1717,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
97850 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
97851 };
97852
97853-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
97854+static struct rtnl_link_ops ip6_link_ops = {
97855 .kind = "ip6tnl",
97856 .maxtype = IFLA_IPTUN_MAX,
97857 .policy = ip6_tnl_policy,
97858diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
97859index 7b42d5e..1eff693 100644
97860--- a/net/ipv6/ip6_vti.c
97861+++ b/net/ipv6/ip6_vti.c
97862@@ -63,7 +63,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
97863
97864 static int vti6_dev_init(struct net_device *dev);
97865 static void vti6_dev_setup(struct net_device *dev);
97866-static struct rtnl_link_ops vti6_link_ops __read_mostly;
97867+static struct rtnl_link_ops vti6_link_ops;
97868
97869 static int vti6_net_id __read_mostly;
97870 struct vti6_net {
97871@@ -902,7 +902,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
97872 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
97873 };
97874
97875-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
97876+static struct rtnl_link_ops vti6_link_ops = {
97877 .kind = "vti6",
97878 .maxtype = IFLA_VTI_MAX,
97879 .policy = vti6_policy,
97880diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
97881index 1c6ce31..299e566 100644
97882--- a/net/ipv6/ipv6_sockglue.c
97883+++ b/net/ipv6/ipv6_sockglue.c
97884@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
97885 if (sk->sk_type != SOCK_STREAM)
97886 return -ENOPROTOOPT;
97887
97888- msg.msg_control = optval;
97889+ msg.msg_control = (void __force_kernel *)optval;
97890 msg.msg_controllen = len;
97891 msg.msg_flags = flags;
97892
97893diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
97894index 710238f..0fd1816 100644
97895--- a/net/ipv6/netfilter/ip6_tables.c
97896+++ b/net/ipv6/netfilter/ip6_tables.c
97897@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
97898 #endif
97899
97900 static int get_info(struct net *net, void __user *user,
97901- const int *len, int compat)
97902+ int len, int compat)
97903 {
97904 char name[XT_TABLE_MAXNAMELEN];
97905 struct xt_table *t;
97906 int ret;
97907
97908- if (*len != sizeof(struct ip6t_getinfo)) {
97909- duprintf("length %u != %zu\n", *len,
97910+ if (len != sizeof(struct ip6t_getinfo)) {
97911+ duprintf("length %u != %zu\n", len,
97912 sizeof(struct ip6t_getinfo));
97913 return -EINVAL;
97914 }
97915@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
97916 info.size = private->size;
97917 strcpy(info.name, name);
97918
97919- if (copy_to_user(user, &info, *len) != 0)
97920+ if (copy_to_user(user, &info, len) != 0)
97921 ret = -EFAULT;
97922 else
97923 ret = 0;
97924@@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97925
97926 switch (cmd) {
97927 case IP6T_SO_GET_INFO:
97928- ret = get_info(sock_net(sk), user, len, 1);
97929+ ret = get_info(sock_net(sk), user, *len, 1);
97930 break;
97931 case IP6T_SO_GET_ENTRIES:
97932 ret = compat_get_entries(sock_net(sk), user, len);
97933@@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97934
97935 switch (cmd) {
97936 case IP6T_SO_GET_INFO:
97937- ret = get_info(sock_net(sk), user, len, 0);
97938+ ret = get_info(sock_net(sk), user, *len, 0);
97939 break;
97940
97941 case IP6T_SO_GET_ENTRIES:
97942diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
97943index 767ab8d..c5ec70a 100644
97944--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
97945+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
97946@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
97947
97948 static int nf_ct_frag6_sysctl_register(struct net *net)
97949 {
97950- struct ctl_table *table;
97951+ ctl_table_no_const *table = NULL;
97952 struct ctl_table_header *hdr;
97953
97954- table = nf_ct_frag6_sysctl_table;
97955 if (!net_eq(net, &init_net)) {
97956- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
97957+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
97958 GFP_KERNEL);
97959 if (table == NULL)
97960 goto err_alloc;
97961@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
97962 table[0].data = &net->nf_frag.frags.timeout;
97963 table[1].data = &net->nf_frag.frags.low_thresh;
97964 table[2].data = &net->nf_frag.frags.high_thresh;
97965- }
97966-
97967- hdr = register_net_sysctl(net, "net/netfilter", table);
97968+ hdr = register_net_sysctl(net, "net/netfilter", table);
97969+ } else
97970+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
97971 if (hdr == NULL)
97972 goto err_reg;
97973
97974@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
97975 return 0;
97976
97977 err_reg:
97978- if (!net_eq(net, &init_net))
97979- kfree(table);
97980+ kfree(table);
97981 err_alloc:
97982 return -ENOMEM;
97983 }
97984diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
97985index 827f795..7e28e82 100644
97986--- a/net/ipv6/output_core.c
97987+++ b/net/ipv6/output_core.c
97988@@ -9,8 +9,8 @@
97989
97990 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
97991 {
97992- static atomic_t ipv6_fragmentation_id;
97993- int old, new;
97994+ static atomic_unchecked_t ipv6_fragmentation_id;
97995+ int id;
97996
97997 #if IS_ENABLED(CONFIG_IPV6)
97998 if (rt && !(rt->dst.flags & DST_NOPEER)) {
97999@@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
98000 }
98001 }
98002 #endif
98003- do {
98004- old = atomic_read(&ipv6_fragmentation_id);
98005- new = old + 1;
98006- if (!new)
98007- new = 1;
98008- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
98009- fhdr->identification = htonl(new);
98010+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
98011+ if (!id)
98012+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
98013+ fhdr->identification = htonl(id);
98014 }
98015 EXPORT_SYMBOL(ipv6_select_ident);
98016
98017diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
98018index a83243c..a1ca589 100644
98019--- a/net/ipv6/ping.c
98020+++ b/net/ipv6/ping.c
98021@@ -246,6 +246,22 @@ static struct pernet_operations ping_v6_net_ops = {
98022 };
98023 #endif
98024
98025+static struct pingv6_ops real_pingv6_ops = {
98026+ .ipv6_recv_error = ipv6_recv_error,
98027+ .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
98028+ .icmpv6_err_convert = icmpv6_err_convert,
98029+ .ipv6_icmp_error = ipv6_icmp_error,
98030+ .ipv6_chk_addr = ipv6_chk_addr,
98031+};
98032+
98033+static struct pingv6_ops dummy_pingv6_ops = {
98034+ .ipv6_recv_error = dummy_ipv6_recv_error,
98035+ .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
98036+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
98037+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
98038+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
98039+};
98040+
98041 int __init pingv6_init(void)
98042 {
98043 #ifdef CONFIG_PROC_FS
98044@@ -253,11 +269,7 @@ int __init pingv6_init(void)
98045 if (ret)
98046 return ret;
98047 #endif
98048- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
98049- pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
98050- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
98051- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
98052- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
98053+ pingv6_ops = &real_pingv6_ops;
98054 return inet6_register_protosw(&pingv6_protosw);
98055 }
98056
98057@@ -266,11 +278,7 @@ int __init pingv6_init(void)
98058 */
98059 void pingv6_exit(void)
98060 {
98061- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
98062- pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
98063- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
98064- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
98065- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
98066+ pingv6_ops = &dummy_pingv6_ops;
98067 #ifdef CONFIG_PROC_FS
98068 unregister_pernet_subsys(&ping_v6_net_ops);
98069 #endif
98070diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
98071index b6bb87e..06cc9ed 100644
98072--- a/net/ipv6/raw.c
98073+++ b/net/ipv6/raw.c
98074@@ -384,7 +384,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
98075 {
98076 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
98077 skb_checksum_complete(skb)) {
98078- atomic_inc(&sk->sk_drops);
98079+ atomic_inc_unchecked(&sk->sk_drops);
98080 kfree_skb(skb);
98081 return NET_RX_DROP;
98082 }
98083@@ -412,7 +412,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
98084 struct raw6_sock *rp = raw6_sk(sk);
98085
98086 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
98087- atomic_inc(&sk->sk_drops);
98088+ atomic_inc_unchecked(&sk->sk_drops);
98089 kfree_skb(skb);
98090 return NET_RX_DROP;
98091 }
98092@@ -436,7 +436,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
98093
98094 if (inet->hdrincl) {
98095 if (skb_checksum_complete(skb)) {
98096- atomic_inc(&sk->sk_drops);
98097+ atomic_inc_unchecked(&sk->sk_drops);
98098 kfree_skb(skb);
98099 return NET_RX_DROP;
98100 }
98101@@ -465,6 +465,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
98102 if (flags & MSG_OOB)
98103 return -EOPNOTSUPP;
98104
98105+ if (addr_len)
98106+ *addr_len=sizeof(*sin6);
98107+
98108 if (flags & MSG_ERRQUEUE)
98109 return ipv6_recv_error(sk, msg, len, addr_len);
98110
98111@@ -503,7 +506,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
98112 sin6->sin6_flowinfo = 0;
98113 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
98114 IP6CB(skb)->iif);
98115- *addr_len = sizeof(*sin6);
98116 }
98117
98118 sock_recv_ts_and_drops(msg, sk, skb);
98119@@ -606,7 +608,7 @@ out:
98120 return err;
98121 }
98122
98123-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
98124+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
98125 struct flowi6 *fl6, struct dst_entry **dstp,
98126 unsigned int flags)
98127 {
98128@@ -918,12 +920,15 @@ do_confirm:
98129 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
98130 char __user *optval, int optlen)
98131 {
98132+ struct icmp6_filter filter;
98133+
98134 switch (optname) {
98135 case ICMPV6_FILTER:
98136 if (optlen > sizeof(struct icmp6_filter))
98137 optlen = sizeof(struct icmp6_filter);
98138- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
98139+ if (copy_from_user(&filter, optval, optlen))
98140 return -EFAULT;
98141+ raw6_sk(sk)->filter = filter;
98142 return 0;
98143 default:
98144 return -ENOPROTOOPT;
98145@@ -936,6 +941,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
98146 char __user *optval, int __user *optlen)
98147 {
98148 int len;
98149+ struct icmp6_filter filter;
98150
98151 switch (optname) {
98152 case ICMPV6_FILTER:
98153@@ -947,7 +953,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
98154 len = sizeof(struct icmp6_filter);
98155 if (put_user(len, optlen))
98156 return -EFAULT;
98157- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
98158+ filter = raw6_sk(sk)->filter;
98159+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
98160 return -EFAULT;
98161 return 0;
98162 default:
98163diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
98164index cc85a9b..526a133 100644
98165--- a/net/ipv6/reassembly.c
98166+++ b/net/ipv6/reassembly.c
98167@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
98168
98169 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
98170 {
98171- struct ctl_table *table;
98172+ ctl_table_no_const *table = NULL;
98173 struct ctl_table_header *hdr;
98174
98175- table = ip6_frags_ns_ctl_table;
98176 if (!net_eq(net, &init_net)) {
98177- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
98178+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
98179 if (table == NULL)
98180 goto err_alloc;
98181
98182@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
98183 /* Don't export sysctls to unprivileged users */
98184 if (net->user_ns != &init_user_ns)
98185 table[0].procname = NULL;
98186- }
98187+ hdr = register_net_sysctl(net, "net/ipv6", table);
98188+ } else
98189+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
98190
98191- hdr = register_net_sysctl(net, "net/ipv6", table);
98192 if (hdr == NULL)
98193 goto err_reg;
98194
98195@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
98196 return 0;
98197
98198 err_reg:
98199- if (!net_eq(net, &init_net))
98200- kfree(table);
98201+ kfree(table);
98202 err_alloc:
98203 return -ENOMEM;
98204 }
98205diff --git a/net/ipv6/route.c b/net/ipv6/route.c
98206index 4b4944c..4580b91 100644
98207--- a/net/ipv6/route.c
98208+++ b/net/ipv6/route.c
98209@@ -2954,7 +2954,7 @@ struct ctl_table ipv6_route_table_template[] = {
98210
98211 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
98212 {
98213- struct ctl_table *table;
98214+ ctl_table_no_const *table;
98215
98216 table = kmemdup(ipv6_route_table_template,
98217 sizeof(ipv6_route_table_template),
98218diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
98219index d3005b3..b36df4a 100644
98220--- a/net/ipv6/sit.c
98221+++ b/net/ipv6/sit.c
98222@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
98223 static void ipip6_dev_free(struct net_device *dev);
98224 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
98225 __be32 *v4dst);
98226-static struct rtnl_link_ops sit_link_ops __read_mostly;
98227+static struct rtnl_link_ops sit_link_ops;
98228
98229 static int sit_net_id __read_mostly;
98230 struct sit_net {
98231@@ -1664,7 +1664,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
98232 unregister_netdevice_queue(dev, head);
98233 }
98234
98235-static struct rtnl_link_ops sit_link_ops __read_mostly = {
98236+static struct rtnl_link_ops sit_link_ops = {
98237 .kind = "sit",
98238 .maxtype = IFLA_IPTUN_MAX,
98239 .policy = ipip6_policy,
98240diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
98241index 107b2f1..72741a9 100644
98242--- a/net/ipv6/sysctl_net_ipv6.c
98243+++ b/net/ipv6/sysctl_net_ipv6.c
98244@@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
98245
98246 static int __net_init ipv6_sysctl_net_init(struct net *net)
98247 {
98248- struct ctl_table *ipv6_table;
98249+ ctl_table_no_const *ipv6_table;
98250 struct ctl_table *ipv6_route_table;
98251 struct ctl_table *ipv6_icmp_table;
98252 int err;
98253diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
98254index f67033b..6f974fc 100644
98255--- a/net/ipv6/tcp_ipv6.c
98256+++ b/net/ipv6/tcp_ipv6.c
98257@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
98258 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
98259 }
98260
98261+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98262+extern int grsec_enable_blackhole;
98263+#endif
98264+
98265 static void tcp_v6_hash(struct sock *sk)
98266 {
98267 if (sk->sk_state != TCP_CLOSE) {
98268@@ -1397,6 +1401,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
98269 return 0;
98270
98271 reset:
98272+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98273+ if (!grsec_enable_blackhole)
98274+#endif
98275 tcp_v6_send_reset(sk, skb);
98276 discard:
98277 if (opt_skb)
98278@@ -1479,12 +1486,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
98279 TCP_SKB_CB(skb)->sacked = 0;
98280
98281 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
98282- if (!sk)
98283+ if (!sk) {
98284+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98285+ ret = 1;
98286+#endif
98287 goto no_tcp_socket;
98288+ }
98289
98290 process:
98291- if (sk->sk_state == TCP_TIME_WAIT)
98292+ if (sk->sk_state == TCP_TIME_WAIT) {
98293+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98294+ ret = 2;
98295+#endif
98296 goto do_time_wait;
98297+ }
98298
98299 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
98300 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
98301@@ -1536,6 +1551,10 @@ csum_error:
98302 bad_packet:
98303 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
98304 } else {
98305+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98306+ if (!grsec_enable_blackhole || (ret == 1 &&
98307+ (skb->dev->flags & IFF_LOOPBACK)))
98308+#endif
98309 tcp_v6_send_reset(NULL, skb);
98310 }
98311
98312diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
98313index 089c741..cfee117 100644
98314--- a/net/ipv6/udp.c
98315+++ b/net/ipv6/udp.c
98316@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
98317 udp_ipv6_hash_secret + net_hash_mix(net));
98318 }
98319
98320+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98321+extern int grsec_enable_blackhole;
98322+#endif
98323+
98324 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
98325 {
98326 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
98327@@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
98328 int is_udp4;
98329 bool slow;
98330
98331+ if (addr_len)
98332+ *addr_len = sizeof(struct sockaddr_in6);
98333+
98334 if (flags & MSG_ERRQUEUE)
98335 return ipv6_recv_error(sk, msg, len, addr_len);
98336
98337@@ -435,7 +442,7 @@ try_again:
98338 if (unlikely(err)) {
98339 trace_kfree_skb(skb, udpv6_recvmsg);
98340 if (!peeked) {
98341- atomic_inc(&sk->sk_drops);
98342+ atomic_inc_unchecked(&sk->sk_drops);
98343 if (is_udp4)
98344 UDP_INC_STATS_USER(sock_net(sk),
98345 UDP_MIB_INERRORS,
98346@@ -477,7 +484,7 @@ try_again:
98347 ipv6_iface_scope_id(&sin6->sin6_addr,
98348 IP6CB(skb)->iif);
98349 }
98350- *addr_len = sizeof(*sin6);
98351+
98352 }
98353 if (is_udp4) {
98354 if (inet->cmsg_flags)
98355@@ -685,7 +692,7 @@ csum_error:
98356 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
98357 drop:
98358 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
98359- atomic_inc(&sk->sk_drops);
98360+ atomic_inc_unchecked(&sk->sk_drops);
98361 kfree_skb(skb);
98362 return -1;
98363 }
98364@@ -742,7 +749,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
98365 if (likely(skb1 == NULL))
98366 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
98367 if (!skb1) {
98368- atomic_inc(&sk->sk_drops);
98369+ atomic_inc_unchecked(&sk->sk_drops);
98370 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
98371 IS_UDPLITE(sk));
98372 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98373@@ -881,6 +888,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
98374 goto csum_error;
98375
98376 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
98377+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98378+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
98379+#endif
98380 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
98381
98382 kfree_skb(skb);
98383diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
98384index 5f8e128..865d38e 100644
98385--- a/net/ipv6/xfrm6_policy.c
98386+++ b/net/ipv6/xfrm6_policy.c
98387@@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
98388 }
98389 }
98390
98391-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
98392+static int xfrm6_garbage_collect(struct dst_ops *ops)
98393 {
98394 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
98395
98396- xfrm6_policy_afinfo.garbage_collect(net);
98397+ xfrm_garbage_collect_deferred(net);
98398 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
98399 }
98400
98401@@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
98402
98403 static int __net_init xfrm6_net_init(struct net *net)
98404 {
98405- struct ctl_table *table;
98406+ ctl_table_no_const *table = NULL;
98407 struct ctl_table_header *hdr;
98408
98409- table = xfrm6_policy_table;
98410 if (!net_eq(net, &init_net)) {
98411- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
98412+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
98413 if (!table)
98414 goto err_alloc;
98415
98416 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
98417- }
98418+ hdr = register_net_sysctl(net, "net/ipv6", table);
98419+ } else
98420+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
98421
98422- hdr = register_net_sysctl(net, "net/ipv6", table);
98423 if (!hdr)
98424 goto err_reg;
98425
98426@@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
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 }
98436diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
98437index 41ac7938..75e3bb1 100644
98438--- a/net/irda/ircomm/ircomm_tty.c
98439+++ b/net/irda/ircomm/ircomm_tty.c
98440@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
98441 add_wait_queue(&port->open_wait, &wait);
98442
98443 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
98444- __FILE__, __LINE__, tty->driver->name, port->count);
98445+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
98446
98447 spin_lock_irqsave(&port->lock, flags);
98448 if (!tty_hung_up_p(filp))
98449- port->count--;
98450+ atomic_dec(&port->count);
98451 port->blocked_open++;
98452 spin_unlock_irqrestore(&port->lock, flags);
98453
98454@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
98455 }
98456
98457 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
98458- __FILE__, __LINE__, tty->driver->name, port->count);
98459+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
98460
98461 schedule();
98462 }
98463@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
98464
98465 spin_lock_irqsave(&port->lock, flags);
98466 if (!tty_hung_up_p(filp))
98467- port->count++;
98468+ atomic_inc(&port->count);
98469 port->blocked_open--;
98470 spin_unlock_irqrestore(&port->lock, flags);
98471
98472 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
98473- __FILE__, __LINE__, tty->driver->name, port->count);
98474+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
98475
98476 if (!retval)
98477 port->flags |= ASYNC_NORMAL_ACTIVE;
98478@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
98479
98480 /* ++ is not atomic, so this should be protected - Jean II */
98481 spin_lock_irqsave(&self->port.lock, flags);
98482- self->port.count++;
98483+ atomic_inc(&self->port.count);
98484 spin_unlock_irqrestore(&self->port.lock, flags);
98485 tty_port_tty_set(&self->port, tty);
98486
98487 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
98488- self->line, self->port.count);
98489+ self->line, atomic_read(&self->port.count));
98490
98491 /* Not really used by us, but lets do it anyway */
98492 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
98493@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
98494 tty_kref_put(port->tty);
98495 }
98496 port->tty = NULL;
98497- port->count = 0;
98498+ atomic_set(&port->count, 0);
98499 spin_unlock_irqrestore(&port->lock, flags);
98500
98501 wake_up_interruptible(&port->open_wait);
98502@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
98503 seq_putc(m, '\n');
98504
98505 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
98506- seq_printf(m, "Open count: %d\n", self->port.count);
98507+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
98508 seq_printf(m, "Max data size: %d\n", self->max_data_size);
98509 seq_printf(m, "Max header size: %d\n", self->max_header_size);
98510
98511diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
98512index c4b7218..3e83259 100644
98513--- a/net/iucv/af_iucv.c
98514+++ b/net/iucv/af_iucv.c
98515@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
98516
98517 write_lock_bh(&iucv_sk_list.lock);
98518
98519- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
98520+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
98521 while (__iucv_get_sock_by_name(name)) {
98522 sprintf(name, "%08x",
98523- atomic_inc_return(&iucv_sk_list.autobind_name));
98524+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
98525 }
98526
98527 write_unlock_bh(&iucv_sk_list.lock);
98528diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
98529index cd5b8ec..f205e6b 100644
98530--- a/net/iucv/iucv.c
98531+++ b/net/iucv/iucv.c
98532@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
98533 return NOTIFY_OK;
98534 }
98535
98536-static struct notifier_block __refdata iucv_cpu_notifier = {
98537+static struct notifier_block iucv_cpu_notifier = {
98538 .notifier_call = iucv_cpu_notify,
98539 };
98540
98541diff --git a/net/key/af_key.c b/net/key/af_key.c
98542index 545f047..9757a9d 100644
98543--- a/net/key/af_key.c
98544+++ b/net/key/af_key.c
98545@@ -3041,10 +3041,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
98546 static u32 get_acqseq(void)
98547 {
98548 u32 res;
98549- static atomic_t acqseq;
98550+ static atomic_unchecked_t acqseq;
98551
98552 do {
98553- res = atomic_inc_return(&acqseq);
98554+ res = atomic_inc_return_unchecked(&acqseq);
98555 } while (!res);
98556 return res;
98557 }
98558diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
98559index da1a1ce..571db8d 100644
98560--- a/net/l2tp/l2tp_ip.c
98561+++ b/net/l2tp/l2tp_ip.c
98562@@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
98563 if (flags & MSG_OOB)
98564 goto out;
98565
98566+ if (addr_len)
98567+ *addr_len = sizeof(*sin);
98568+
98569 skb = skb_recv_datagram(sk, flags, noblock, &err);
98570 if (!skb)
98571 goto out;
98572@@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
98573 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98574 sin->sin_port = 0;
98575 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
98576- *addr_len = sizeof(*sin);
98577 }
98578 if (inet->cmsg_flags)
98579 ip_cmsg_recv(msg, skb);
98580diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
98581index 364ce0c..3ebb5a4 100644
98582--- a/net/mac80211/cfg.c
98583+++ b/net/mac80211/cfg.c
98584@@ -826,7 +826,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
98585 ret = ieee80211_vif_use_channel(sdata, chandef,
98586 IEEE80211_CHANCTX_EXCLUSIVE);
98587 }
98588- } else if (local->open_count == local->monitors) {
98589+ } else if (local_read(&local->open_count) == local->monitors) {
98590 local->_oper_chandef = *chandef;
98591 ieee80211_hw_config(local, 0);
98592 }
98593@@ -3308,7 +3308,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
98594 else
98595 local->probe_req_reg--;
98596
98597- if (!local->open_count)
98598+ if (!local_read(&local->open_count))
98599 break;
98600
98601 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
98602@@ -3771,8 +3771,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
98603 if (chanctx_conf) {
98604 *chandef = chanctx_conf->def;
98605 ret = 0;
98606- } else if (local->open_count > 0 &&
98607- local->open_count == local->monitors &&
98608+ } else if (local_read(&local->open_count) > 0 &&
98609+ local_read(&local->open_count) == local->monitors &&
98610 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
98611 if (local->use_chanctx)
98612 *chandef = local->monitor_chandef;
98613diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
98614index 4aea4e7..9e698d1 100644
98615--- a/net/mac80211/ieee80211_i.h
98616+++ b/net/mac80211/ieee80211_i.h
98617@@ -28,6 +28,7 @@
98618 #include <net/ieee80211_radiotap.h>
98619 #include <net/cfg80211.h>
98620 #include <net/mac80211.h>
98621+#include <asm/local.h>
98622 #include "key.h"
98623 #include "sta_info.h"
98624 #include "debug.h"
98625@@ -961,7 +962,7 @@ struct ieee80211_local {
98626 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
98627 spinlock_t queue_stop_reason_lock;
98628
98629- int open_count;
98630+ local_t open_count;
98631 int monitors, cooked_mntrs;
98632 /* number of interfaces with corresponding FIF_ flags */
98633 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
98634diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
98635index a075791..1d0027f 100644
98636--- a/net/mac80211/iface.c
98637+++ b/net/mac80211/iface.c
98638@@ -519,7 +519,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98639 break;
98640 }
98641
98642- if (local->open_count == 0) {
98643+ if (local_read(&local->open_count) == 0) {
98644 res = drv_start(local);
98645 if (res)
98646 goto err_del_bss;
98647@@ -566,7 +566,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98648 res = drv_add_interface(local, sdata);
98649 if (res)
98650 goto err_stop;
98651- } else if (local->monitors == 0 && local->open_count == 0) {
98652+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
98653 res = ieee80211_add_virtual_monitor(local);
98654 if (res)
98655 goto err_stop;
98656@@ -675,7 +675,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98657 atomic_inc(&local->iff_promiscs);
98658
98659 if (coming_up)
98660- local->open_count++;
98661+ local_inc(&local->open_count);
98662
98663 if (hw_reconf_flags)
98664 ieee80211_hw_config(local, hw_reconf_flags);
98665@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98666 err_del_interface:
98667 drv_remove_interface(local, sdata);
98668 err_stop:
98669- if (!local->open_count)
98670+ if (!local_read(&local->open_count))
98671 drv_stop(local);
98672 err_del_bss:
98673 sdata->bss = NULL;
98674@@ -856,7 +856,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98675 }
98676
98677 if (going_down)
98678- local->open_count--;
98679+ local_dec(&local->open_count);
98680
98681 switch (sdata->vif.type) {
98682 case NL80211_IFTYPE_AP_VLAN:
98683@@ -923,7 +923,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98684 }
98685 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
98686
98687- if (local->open_count == 0)
98688+ if (local_read(&local->open_count) == 0)
98689 ieee80211_clear_tx_pending(local);
98690
98691 /*
98692@@ -963,7 +963,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98693
98694 ieee80211_recalc_ps(local, -1);
98695
98696- if (local->open_count == 0) {
98697+ if (local_read(&local->open_count) == 0) {
98698 ieee80211_stop_device(local);
98699
98700 /* no reconfiguring after stop! */
98701@@ -974,7 +974,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98702 ieee80211_configure_filter(local);
98703 ieee80211_hw_config(local, hw_reconf_flags);
98704
98705- if (local->monitors == local->open_count)
98706+ if (local->monitors == local_read(&local->open_count))
98707 ieee80211_add_virtual_monitor(local);
98708 }
98709
98710diff --git a/net/mac80211/main.c b/net/mac80211/main.c
98711index 7d1c3ac..b62dd29 100644
98712--- a/net/mac80211/main.c
98713+++ b/net/mac80211/main.c
98714@@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
98715 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
98716 IEEE80211_CONF_CHANGE_POWER);
98717
98718- if (changed && local->open_count) {
98719+ if (changed && local_read(&local->open_count)) {
98720 ret = drv_config(local, changed);
98721 /*
98722 * Goal:
98723diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
98724index 3401262..d5cd68d 100644
98725--- a/net/mac80211/pm.c
98726+++ b/net/mac80211/pm.c
98727@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
98728 struct ieee80211_sub_if_data *sdata;
98729 struct sta_info *sta;
98730
98731- if (!local->open_count)
98732+ if (!local_read(&local->open_count))
98733 goto suspend;
98734
98735 ieee80211_scan_cancel(local);
98736@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
98737 cancel_work_sync(&local->dynamic_ps_enable_work);
98738 del_timer_sync(&local->dynamic_ps_timer);
98739
98740- local->wowlan = wowlan && local->open_count;
98741+ local->wowlan = wowlan && local_read(&local->open_count);
98742 if (local->wowlan) {
98743 int err = drv_suspend(local, wowlan);
98744 if (err < 0) {
98745@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
98746 WARN_ON(!list_empty(&local->chanctx_list));
98747
98748 /* stop hardware - this must stop RX */
98749- if (local->open_count)
98750+ if (local_read(&local->open_count))
98751 ieee80211_stop_device(local);
98752
98753 suspend:
98754diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
98755index 22b223f..ab70070 100644
98756--- a/net/mac80211/rate.c
98757+++ b/net/mac80211/rate.c
98758@@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
98759
98760 ASSERT_RTNL();
98761
98762- if (local->open_count)
98763+ if (local_read(&local->open_count))
98764 return -EBUSY;
98765
98766 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
98767diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
98768index 6ff1346..936ca9a 100644
98769--- a/net/mac80211/rc80211_pid_debugfs.c
98770+++ b/net/mac80211/rc80211_pid_debugfs.c
98771@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
98772
98773 spin_unlock_irqrestore(&events->lock, status);
98774
98775- if (copy_to_user(buf, pb, p))
98776+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
98777 return -EFAULT;
98778
98779 return p;
98780diff --git a/net/mac80211/util.c b/net/mac80211/util.c
98781index 9f9b9bd..d6fcf59 100644
98782--- a/net/mac80211/util.c
98783+++ b/net/mac80211/util.c
98784@@ -1474,7 +1474,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
98785 }
98786 #endif
98787 /* everything else happens only if HW was up & running */
98788- if (!local->open_count)
98789+ if (!local_read(&local->open_count))
98790 goto wake_up;
98791
98792 /*
98793@@ -1699,7 +1699,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
98794 local->in_reconfig = false;
98795 barrier();
98796
98797- if (local->monitors == local->open_count && local->monitors > 0)
98798+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
98799 ieee80211_add_virtual_monitor(local);
98800
98801 /*
98802diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
98803index c3398cd..98ad3b4 100644
98804--- a/net/netfilter/Kconfig
98805+++ b/net/netfilter/Kconfig
98806@@ -1002,6 +1002,16 @@ config NETFILTER_XT_MATCH_ESP
98807
98808 To compile it as a module, choose M here. If unsure, say N.
98809
98810+config NETFILTER_XT_MATCH_GRADM
98811+ tristate '"gradm" match support'
98812+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
98813+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
98814+ ---help---
98815+ The gradm match allows to match on grsecurity RBAC being enabled.
98816+ It is useful when iptables rules are applied early on bootup to
98817+ prevent connections to the machine (except from a trusted host)
98818+ while the RBAC system is disabled.
98819+
98820 config NETFILTER_XT_MATCH_HASHLIMIT
98821 tristate '"hashlimit" match support'
98822 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
98823diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
98824index 394483b..ed51f2d 100644
98825--- a/net/netfilter/Makefile
98826+++ b/net/netfilter/Makefile
98827@@ -130,6 +130,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
98828 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
98829 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
98830 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
98831+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
98832 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
98833 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
98834 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
98835diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
98836index bac7e01..1d7a31a 100644
98837--- a/net/netfilter/ipset/ip_set_core.c
98838+++ b/net/netfilter/ipset/ip_set_core.c
98839@@ -1950,7 +1950,7 @@ done:
98840 return ret;
98841 }
98842
98843-static struct nf_sockopt_ops so_set __read_mostly = {
98844+static struct nf_sockopt_ops so_set = {
98845 .pf = PF_INET,
98846 .get_optmin = SO_IP_SET,
98847 .get_optmax = SO_IP_SET + 1,
98848diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
98849index 4c8e5c0..5a79b4d 100644
98850--- a/net/netfilter/ipvs/ip_vs_conn.c
98851+++ b/net/netfilter/ipvs/ip_vs_conn.c
98852@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
98853 /* Increase the refcnt counter of the dest */
98854 ip_vs_dest_hold(dest);
98855
98856- conn_flags = atomic_read(&dest->conn_flags);
98857+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
98858 if (cp->protocol != IPPROTO_UDP)
98859 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
98860 flags = cp->flags;
98861@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
98862
98863 cp->control = NULL;
98864 atomic_set(&cp->n_control, 0);
98865- atomic_set(&cp->in_pkts, 0);
98866+ atomic_set_unchecked(&cp->in_pkts, 0);
98867
98868 cp->packet_xmit = NULL;
98869 cp->app = NULL;
98870@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
98871
98872 /* Don't drop the entry if its number of incoming packets is not
98873 located in [0, 8] */
98874- i = atomic_read(&cp->in_pkts);
98875+ i = atomic_read_unchecked(&cp->in_pkts);
98876 if (i > 8 || i < 0) return 0;
98877
98878 if (!todrop_rate[i]) return 0;
98879diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
98880index 4f26ee4..6a9d7c3 100644
98881--- a/net/netfilter/ipvs/ip_vs_core.c
98882+++ b/net/netfilter/ipvs/ip_vs_core.c
98883@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
98884 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
98885 /* do not touch skb anymore */
98886
98887- atomic_inc(&cp->in_pkts);
98888+ atomic_inc_unchecked(&cp->in_pkts);
98889 ip_vs_conn_put(cp);
98890 return ret;
98891 }
98892@@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
98893 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
98894 pkts = sysctl_sync_threshold(ipvs);
98895 else
98896- pkts = atomic_add_return(1, &cp->in_pkts);
98897+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
98898
98899 if (ipvs->sync_state & IP_VS_STATE_MASTER)
98900 ip_vs_sync_conn(net, cp, pkts);
98901diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
98902index 35be035..dad174b 100644
98903--- a/net/netfilter/ipvs/ip_vs_ctl.c
98904+++ b/net/netfilter/ipvs/ip_vs_ctl.c
98905@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
98906 */
98907 ip_vs_rs_hash(ipvs, dest);
98908 }
98909- atomic_set(&dest->conn_flags, conn_flags);
98910+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
98911
98912 /* bind the service */
98913 old_svc = rcu_dereference_protected(dest->svc, 1);
98914@@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
98915 * align with netns init in ip_vs_control_net_init()
98916 */
98917
98918-static struct ctl_table vs_vars[] = {
98919+static ctl_table_no_const vs_vars[] __read_only = {
98920 {
98921 .procname = "amemthresh",
98922 .maxlen = sizeof(int),
98923@@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
98924 " %-7s %-6d %-10d %-10d\n",
98925 &dest->addr.in6,
98926 ntohs(dest->port),
98927- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
98928+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
98929 atomic_read(&dest->weight),
98930 atomic_read(&dest->activeconns),
98931 atomic_read(&dest->inactconns));
98932@@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
98933 "%-7s %-6d %-10d %-10d\n",
98934 ntohl(dest->addr.ip),
98935 ntohs(dest->port),
98936- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
98937+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
98938 atomic_read(&dest->weight),
98939 atomic_read(&dest->activeconns),
98940 atomic_read(&dest->inactconns));
98941@@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
98942
98943 entry.addr = dest->addr.ip;
98944 entry.port = dest->port;
98945- entry.conn_flags = atomic_read(&dest->conn_flags);
98946+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
98947 entry.weight = atomic_read(&dest->weight);
98948 entry.u_threshold = dest->u_threshold;
98949 entry.l_threshold = dest->l_threshold;
98950@@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
98951 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
98952 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
98953 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
98954- (atomic_read(&dest->conn_flags) &
98955+ (atomic_read_unchecked(&dest->conn_flags) &
98956 IP_VS_CONN_F_FWD_MASK)) ||
98957 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
98958 atomic_read(&dest->weight)) ||
98959@@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
98960 {
98961 int idx;
98962 struct netns_ipvs *ipvs = net_ipvs(net);
98963- struct ctl_table *tbl;
98964+ ctl_table_no_const *tbl;
98965
98966 atomic_set(&ipvs->dropentry, 0);
98967 spin_lock_init(&ipvs->dropentry_lock);
98968diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
98969index ca056a3..9cf01ef 100644
98970--- a/net/netfilter/ipvs/ip_vs_lblc.c
98971+++ b/net/netfilter/ipvs/ip_vs_lblc.c
98972@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
98973 * IPVS LBLC sysctl table
98974 */
98975 #ifdef CONFIG_SYSCTL
98976-static struct ctl_table vs_vars_table[] = {
98977+static ctl_table_no_const vs_vars_table[] __read_only = {
98978 {
98979 .procname = "lblc_expiration",
98980 .data = NULL,
98981diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
98982index 3f21a2f..a112e85 100644
98983--- a/net/netfilter/ipvs/ip_vs_lblcr.c
98984+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
98985@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
98986 * IPVS LBLCR sysctl table
98987 */
98988
98989-static struct ctl_table vs_vars_table[] = {
98990+static ctl_table_no_const vs_vars_table[] __read_only = {
98991 {
98992 .procname = "lblcr_expiration",
98993 .data = NULL,
98994diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
98995index f63c238..1b87f8a 100644
98996--- a/net/netfilter/ipvs/ip_vs_sync.c
98997+++ b/net/netfilter/ipvs/ip_vs_sync.c
98998@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
98999 cp = cp->control;
99000 if (cp) {
99001 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
99002- pkts = atomic_add_return(1, &cp->in_pkts);
99003+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
99004 else
99005 pkts = sysctl_sync_threshold(ipvs);
99006 ip_vs_sync_conn(net, cp->control, pkts);
99007@@ -771,7 +771,7 @@ control:
99008 if (!cp)
99009 return;
99010 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
99011- pkts = atomic_add_return(1, &cp->in_pkts);
99012+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
99013 else
99014 pkts = sysctl_sync_threshold(ipvs);
99015 goto sloop;
99016@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
99017
99018 if (opt)
99019 memcpy(&cp->in_seq, opt, sizeof(*opt));
99020- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
99021+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
99022 cp->state = state;
99023 cp->old_state = cp->state;
99024 /*
99025diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
99026index c47444e..b0961c6 100644
99027--- a/net/netfilter/ipvs/ip_vs_xmit.c
99028+++ b/net/netfilter/ipvs/ip_vs_xmit.c
99029@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
99030 else
99031 rc = NF_ACCEPT;
99032 /* do not touch skb anymore */
99033- atomic_inc(&cp->in_pkts);
99034+ atomic_inc_unchecked(&cp->in_pkts);
99035 goto out;
99036 }
99037
99038@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
99039 else
99040 rc = NF_ACCEPT;
99041 /* do not touch skb anymore */
99042- atomic_inc(&cp->in_pkts);
99043+ atomic_inc_unchecked(&cp->in_pkts);
99044 goto out;
99045 }
99046
99047diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
99048index a4b5e2a..13b1de3 100644
99049--- a/net/netfilter/nf_conntrack_acct.c
99050+++ b/net/netfilter/nf_conntrack_acct.c
99051@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
99052 #ifdef CONFIG_SYSCTL
99053 static int nf_conntrack_acct_init_sysctl(struct net *net)
99054 {
99055- struct ctl_table *table;
99056+ ctl_table_no_const *table;
99057
99058 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
99059 GFP_KERNEL);
99060diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
99061index 43549eb..0bbeace 100644
99062--- a/net/netfilter/nf_conntrack_core.c
99063+++ b/net/netfilter/nf_conntrack_core.c
99064@@ -1605,6 +1605,10 @@ void nf_conntrack_init_end(void)
99065 #define DYING_NULLS_VAL ((1<<30)+1)
99066 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
99067
99068+#ifdef CONFIG_GRKERNSEC_HIDESYM
99069+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
99070+#endif
99071+
99072 int nf_conntrack_init_net(struct net *net)
99073 {
99074 int ret;
99075@@ -1619,7 +1623,11 @@ int nf_conntrack_init_net(struct net *net)
99076 goto err_stat;
99077 }
99078
99079+#ifdef CONFIG_GRKERNSEC_HIDESYM
99080+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
99081+#else
99082 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
99083+#endif
99084 if (!net->ct.slabname) {
99085 ret = -ENOMEM;
99086 goto err_slabname;
99087diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
99088index 1df1761..ce8b88a 100644
99089--- a/net/netfilter/nf_conntrack_ecache.c
99090+++ b/net/netfilter/nf_conntrack_ecache.c
99091@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
99092 #ifdef CONFIG_SYSCTL
99093 static int nf_conntrack_event_init_sysctl(struct net *net)
99094 {
99095- struct ctl_table *table;
99096+ ctl_table_no_const *table;
99097
99098 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
99099 GFP_KERNEL);
99100diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
99101index 974a2a4..52cc6ff 100644
99102--- a/net/netfilter/nf_conntrack_helper.c
99103+++ b/net/netfilter/nf_conntrack_helper.c
99104@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
99105
99106 static int nf_conntrack_helper_init_sysctl(struct net *net)
99107 {
99108- struct ctl_table *table;
99109+ ctl_table_no_const *table;
99110
99111 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
99112 GFP_KERNEL);
99113diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
99114index ce30041..3861b5d 100644
99115--- a/net/netfilter/nf_conntrack_proto.c
99116+++ b/net/netfilter/nf_conntrack_proto.c
99117@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
99118
99119 static void
99120 nf_ct_unregister_sysctl(struct ctl_table_header **header,
99121- struct ctl_table **table,
99122+ ctl_table_no_const **table,
99123 unsigned int users)
99124 {
99125 if (users > 0)
99126diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
99127index a99b6c3..cb372f9 100644
99128--- a/net/netfilter/nf_conntrack_proto_dccp.c
99129+++ b/net/netfilter/nf_conntrack_proto_dccp.c
99130@@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
99131 const char *msg;
99132 u_int8_t state;
99133
99134- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
99135+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
99136 BUG_ON(dh == NULL);
99137
99138 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
99139@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
99140 out_invalid:
99141 if (LOG_INVALID(net, IPPROTO_DCCP))
99142 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
99143- NULL, msg);
99144+ NULL, "%s", msg);
99145 return false;
99146 }
99147
99148@@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
99149 u_int8_t type, old_state, new_state;
99150 enum ct_dccp_roles role;
99151
99152- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
99153+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
99154 BUG_ON(dh == NULL);
99155 type = dh->dccph_type;
99156
99157@@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
99158 unsigned int cscov;
99159 const char *msg;
99160
99161- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
99162+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
99163 if (dh == NULL) {
99164 msg = "nf_ct_dccp: short packet ";
99165 goto out_invalid;
99166@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
99167
99168 out_invalid:
99169 if (LOG_INVALID(net, IPPROTO_DCCP))
99170- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
99171+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
99172 return -NF_ACCEPT;
99173 }
99174
99175diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
99176index f641751..d3c5b51 100644
99177--- a/net/netfilter/nf_conntrack_standalone.c
99178+++ b/net/netfilter/nf_conntrack_standalone.c
99179@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
99180
99181 static int nf_conntrack_standalone_init_sysctl(struct net *net)
99182 {
99183- struct ctl_table *table;
99184+ ctl_table_no_const *table;
99185
99186 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
99187 GFP_KERNEL);
99188diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
99189index 7a394df..bd91a8a 100644
99190--- a/net/netfilter/nf_conntrack_timestamp.c
99191+++ b/net/netfilter/nf_conntrack_timestamp.c
99192@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
99193 #ifdef CONFIG_SYSCTL
99194 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
99195 {
99196- struct ctl_table *table;
99197+ ctl_table_no_const *table;
99198
99199 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
99200 GFP_KERNEL);
99201diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
99202index 85296d4..8becdec 100644
99203--- a/net/netfilter/nf_log.c
99204+++ b/net/netfilter/nf_log.c
99205@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
99206
99207 #ifdef CONFIG_SYSCTL
99208 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
99209-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
99210+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
99211
99212 static int nf_log_proc_dostring(struct ctl_table *table, int write,
99213 void __user *buffer, size_t *lenp, loff_t *ppos)
99214@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
99215 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
99216 mutex_unlock(&nf_log_mutex);
99217 } else {
99218+ ctl_table_no_const nf_log_table = *table;
99219+
99220 mutex_lock(&nf_log_mutex);
99221 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
99222 lockdep_is_held(&nf_log_mutex));
99223 if (!logger)
99224- table->data = "NONE";
99225+ nf_log_table.data = "NONE";
99226 else
99227- table->data = logger->name;
99228- r = proc_dostring(table, write, buffer, lenp, ppos);
99229+ nf_log_table.data = logger->name;
99230+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
99231 mutex_unlock(&nf_log_mutex);
99232 }
99233
99234diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
99235index f042ae5..30ea486 100644
99236--- a/net/netfilter/nf_sockopt.c
99237+++ b/net/netfilter/nf_sockopt.c
99238@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
99239 }
99240 }
99241
99242- list_add(&reg->list, &nf_sockopts);
99243+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
99244 out:
99245 mutex_unlock(&nf_sockopt_mutex);
99246 return ret;
99247@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
99248 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
99249 {
99250 mutex_lock(&nf_sockopt_mutex);
99251- list_del(&reg->list);
99252+ pax_list_del((struct list_head *)&reg->list);
99253 mutex_unlock(&nf_sockopt_mutex);
99254 }
99255 EXPORT_SYMBOL(nf_unregister_sockopt);
99256diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
99257index a155d19..726b0f2 100644
99258--- a/net/netfilter/nfnetlink_log.c
99259+++ b/net/netfilter/nfnetlink_log.c
99260@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
99261 struct nfnl_log_net {
99262 spinlock_t instances_lock;
99263 struct hlist_head instance_table[INSTANCE_BUCKETS];
99264- atomic_t global_seq;
99265+ atomic_unchecked_t global_seq;
99266 };
99267
99268 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
99269@@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
99270 /* global sequence number */
99271 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
99272 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
99273- htonl(atomic_inc_return(&log->global_seq))))
99274+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
99275 goto nla_put_failure;
99276
99277 if (data_len) {
99278diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
99279index da0c1f4..f79737a 100644
99280--- a/net/netfilter/nft_compat.c
99281+++ b/net/netfilter/nft_compat.c
99282@@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
99283 /* We want to reuse existing compat_to_user */
99284 old_fs = get_fs();
99285 set_fs(KERNEL_DS);
99286- t->compat_to_user(out, in);
99287+ t->compat_to_user((void __force_user *)out, in);
99288 set_fs(old_fs);
99289 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
99290 kfree(out);
99291@@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
99292 /* We want to reuse existing compat_to_user */
99293 old_fs = get_fs();
99294 set_fs(KERNEL_DS);
99295- m->compat_to_user(out, in);
99296+ m->compat_to_user((void __force_user *)out, in);
99297 set_fs(old_fs);
99298 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
99299 kfree(out);
99300diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
99301new file mode 100644
99302index 0000000..c566332
99303--- /dev/null
99304+++ b/net/netfilter/xt_gradm.c
99305@@ -0,0 +1,51 @@
99306+/*
99307+ * gradm match for netfilter
99308